util

package
v0.0.0-...-a9a2a47 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// tenant length should be less than 250, 251-255 can be used by system
	LeaderKey  = 251
	GCPointKey = 252
)
View Source
const (
	TSTRING byte = iota
	TLISTMETA
	TLISTDATA
	THASHMETA
	THASHDATA
	TSETMETA
	TSETDATA
	TZSETMETA
	TZSETSCORE
	TZSETDATA
	TTTLMETA
	TTTLDATA
)
View Source
const (
	FNORMAL byte = iota
	FDELETED
)
View Source
const (
	ObjectData byte = iota
	ObjectTTL
)
View Source
const (
	MetaTypeKey byte = iota
	DataTypeKey
	ScoreTypeKey
)

Variables

View Source
var (
	ScoreMin int64 = math.MinInt64 + 2
	ScoreMax int64 = math.MaxInt64 - 1
)
View Source
var (
	GitCommit = ""
	BuildTime = ""
	GoVersion = ""
	Version   = ""
)

set on build time

View Source
var (
	EmptyListOrSet []interface{} = make([]interface{}, 0)
)
View Source
var (
	ErrParams = errors.New("params error")
)

number convert utils

Functions

func BytesToInt32

func BytesToInt32(n []byte) (int32, error)

func BytesToInt64

func BytesToInt64(n []byte) (int64, error)

func BytesToUint16

func BytesToUint16(n []byte) (uint16, error)

func BytesToUint32

func BytesToUint32(n []byte) (uint32, error)

func BytesToUint64

func BytesToUint64(n []byte) (uint64, error)

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 Int64ToBytes

func Int64ToBytes(n int64) ([]byte, error)

func Int64ToStrBytes

func Int64ToStrBytes(n int64) ([]byte, error)

func IsNumber

func IsNumber(s string) bool

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 RawDBPrefix

func RawDBPrefix(tenantId string, dbId uint8) []byte

func RawKeyPrefix

func RawKeyPrefix(tenantid string, dbid uint8, key []byte) []byte

tenantlen(2)|tenant|dbid(1)|typedata(1)|userkeylen(4)|userkey

func RawSysGCPointKey

func RawSysGCPointKey() []byte

func RawSysLeaderKey

func RawSysLeaderKey() []byte

func RawTenantPrefix

func RawTenantPrefix(tenantId string) []byte

func ReverseByteMetrics

func ReverseByteMetrics(a [][]byte)

func StrBytesToInt64

func StrBytesToInt64(n []byte) (int64, error)

func StrBytesToUint64

func StrBytesToUint64(n []byte) (uint64, error)

func StrToInt64

func StrToInt64(n string) (int64, error)

func StrToUint64

func StrToUint64(n string) (uint64, error)

func Uint16ToBytes

func Uint16ToBytes(n uint16) ([]byte, error)

func Uint16ToBytes1

func Uint16ToBytes1(dst []byte, n uint16) error

func Uint32ToBytes

func Uint32ToBytes(n uint32) ([]byte, error)

func Uint32ToBytes1

func Uint32ToBytes1(dst []byte, n uint32) error

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 Uint64ToBytes

func Uint64ToBytes(n uint64) ([]byte, error)

func Uint64ToBytes1

func Uint64ToBytes1(dst []byte, n uint64) error

func UnGZIP

func UnGZIP(file string, dest string) error

UnGZIP ungip file

func ZScoreDecoder

func ZScoreDecoder(rawkeyPrefixLen int, rawkey []byte) (int64, []byte, error)

func ZScoreOffset

func ZScoreOffset(score int64) uint64

func ZScoreRestore

func ZScoreRestore(rscore uint64) int64

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 CharType

type CharType int
const (
	CHAR_NUMBER CharType = iota
	CHAR_EXP
	CHAR_POINT
	CHAR_SIGN
	CHAR_SPACE
	CHAR_ILLEGAL
)

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

type State

type State int

judge whether a string can represent a legal number

const (
	STATE_INITIAL State = iota
	STATE_INT_SIGN
	STATE_INTEGER
	STATE_POINT
	STATE_POINT_WITHOUT_INT
	STATE_FRACTION
	STATE_EXP
	STATE_EXP_SIGN
	STATE_EXP_NUMBER
	STATE_END
)

type Trie

type Trie struct {
	Next [128]*Trie
	Had  bool
}

func NewTrie

func NewTrie() *Trie

func (*Trie) BuildTrie

func (this *Trie) BuildTrie(member []byte) bool

xiaoxiao : add dict Tree

Jump to

Keyboard shortcuts

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