util

package
v0.0.0-...-8b1bff0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GitCommit = ""
	BuildTime = ""
	GoVersion = ""
	Version   = ""
)

set on build time

Functions

func DefaultTimeoutWheel

func DefaultTimeoutWheel() *goetty.TimeoutWheel

DefaultTimeoutWheel returns default timeout wheel

func DiskStats

func DiskStats(path string) (*disk.UsageStat, error)

DiskStats returns the disk usage stats

func GZIP

func GZIP(path string) error

GZIP compress a path to a gzip file

func InitMetric

func InitMetric(runner *task.Runner, cfg *MetricCfg)

InitMetric init the metric

func NoConvert

func NoConvert(key []byte, do func([]byte) metapb.Cell) metapb.Cell

NoConvert no converter

func ParseUrls

func ParseUrls(s string) ([]url.URL, error)

ParseUrls parse a string into multiple urls.

func PrintVersion

func PrintVersion() bool

PrintVersion print version info

func Uint64Convert

func Uint64Convert(key []byte, do func([]byte) metapb.Cell) metapb.Cell

Uint64Convert returns the hash crc64 result value, must use `ReleaseConvertBytes` to release

func UnGZIP

func UnGZIP(file string, dest string) error

UnGZIP ungip file

Types

type CellItem

type CellItem struct {
	// contains filtered or unexported fields
}

CellItem is the cell btree item

func (*CellItem) Contains

func (r *CellItem) Contains(key []byte) bool

Contains returns the item contains the key

func (*CellItem) Less

func (r *CellItem) Less(other btree.Item) bool

Less returns true if the cell start key is greater than the other. So we will sort the cell with start key reversely.

type CellTree

type CellTree struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

CellTree is the btree for cell

func NewCellTree

func NewCellTree() *CellTree

NewCellTree returns a default cell btree

func (*CellTree) Ascend

func (t *CellTree) Ascend(fn func(cell *metapb.Cell) bool)

Ascend asc iterator the tree until fn returns false

func (*CellTree) AscendRange

func (t *CellTree) AscendRange(start, end []byte, fn func(cell *metapb.Cell) bool)

AscendRange asc iterator the tree in the range [start, end) until fn returns false

func (*CellTree) NextCell

func (t *CellTree) NextCell(start []byte) *metapb.Cell

NextCell return the next bigger key range cell

func (*CellTree) Remove

func (t *CellTree) Remove(cell metapb.Cell) bool

Remove removes a cell if the cell is in the tree. It will do nothing if it cannot find the cell or the found cell is not the same with the cell.

func (*CellTree) Search

func (t *CellTree) Search(key []byte) metapb.Cell

Search returns a cell that contains the key.

func (*CellTree) Update

func (t *CellTree) Update(cell metapb.Cell)

Update updates the tree with the cell. It finds and deletes all the overlapped cells first, and then insert the cell.

type KVTree

type KVTree struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

KVTree kv btree

func NewKVTree

func NewKVTree() *KVTree

NewKVTree return a kv btree

func (*KVTree) Delete

func (kv *KVTree) Delete(key []byte) bool

Delete deletes a key, return false if not the key is not exists

func (*KVTree) Get

func (kv *KVTree) Get(key []byte) []byte

Get get value, return nil if not the key is not exists

func (*KVTree) Put

func (kv *KVTree) Put(key, value []byte)

Put puts a key, value to the tree

func (*KVTree) RangeDelete

func (kv *KVTree) RangeDelete(start, end []byte)

RangeDelete deletes key in [start, end)

func (*KVTree) Scan

func (kv *KVTree) Scan(start, end []byte, handler func(key, value []byte) (bool, error)) error

Scan scans in [start, end]

func (*KVTree) Seek

func (kv *KVTree) Seek(key []byte) ([]byte, []byte)

Seek returns the next key and value which key >= spec key

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter limiter implemention by token

func NewLimiter

func NewLimiter(max uint64) *Limiter

NewLimiter return a limiter with max

func (*Limiter) Release

func (l *Limiter) Release()

Release release token

func (*Limiter) Wait

func (l *Limiter) Wait(ctx context.Context) error

Wait wait until get the token

type MetricCfg

type MetricCfg struct {
	Job          string
	Instance     string
	Address      string
	DurationSync time.Duration
}

MetricCfg is the metric configuration.

func NewMetricCfg

func NewMetricCfg(job, instance, address string, durationSync time.Duration) *MetricCfg

NewMetricCfg returns metric cfg

type OffsetQueue

type OffsetQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

OffsetQueue is a queue for sync.

func NewOffsetQueue

func NewOffsetQueue() *OffsetQueue

NewOffsetQueue returns a offset queue

func (*OffsetQueue) Add

func (q *OffsetQueue) Add(item interface{}) uint64

Add add a item to the queue

func (*OffsetQueue) Get

func (q *OffsetQueue) Get(offset uint64) ([]interface{}, uint64)

Get returns all the items after the offset, and remove all items before this offset

func (*OffsetQueue) GetMaxOffset

func (q *OffsetQueue) GetMaxOffset() uint64

GetMaxOffset returns the max offset in the queue

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL