util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OpSet op set
	OpSet int32 = 0
	// OpDelete op delete
	OpDelete int32 = 1
)
View Source
var (
	DefaultTimeoutWheel = putil.DefaultTimeoutWheel
)

Functions

func CpuUsages

func CpuUsages() ([]float64, error)

CpuUsages returns cpu usages

func DiskStats

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

DiskStats returns the disk usage stats

func GZIP

func GZIP(fs vfs.FS, path string) error

GZIP compress a path to a gzip file

func GetTestDir

func GetTestDir() string

GetTestDir returns the data directory to use in tests.

func IORates

func IORates(path string) (map[string]disk.IOCountersStat, error)

IORates io rates

func IsDarwin

func IsDarwin() bool

IsDarwin returns whether running on Darwin.

func MemStats

func MemStats() (*mem.VirtualMemoryStat, error)

MemStats returns the mem usage stats

func RAMDiskDirExist

func RAMDiskDirExist(dir string) bool

RAMDiskDirExist returns whether the specified directory is a mounted RAM disk,

func UnGZIP

func UnGZIP(fs vfs.FS, file string, dest string) error

UnGZIP ungip file

Types

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) PrefixScan

func (kv *KVTree) PrefixScan(prefix []byte, handler func(key, value []byte) (bool, error)) error

PrefixScan Scan scans all keys startswith pre

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 Session

type Session struct {
	ID   interface{}
	Addr string
	// contains filtered or unexported fields
}

Session session

func NewSession

func NewSession(conn goetty.IOSession, releaseFunc func(interface{})) *Session

NewSession create a client session

func (*Session) Close

func (s *Session) Close()

Close close the client session

func (*Session) OnResp

func (s *Session) OnResp(resp interface{})

OnResp receive a response

type ShardItem

type ShardItem struct {
	Shard bhmetapb.Shard
}

ShardItem is the Shard btree item

func (*ShardItem) Contains

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

Contains returns the item contains the key

func (*ShardItem) Less

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

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

type ShardTree

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

ShardTree is the btree for Shard

func NewShardTree

func NewShardTree() *ShardTree

NewShardTree returns a default Shard btree

func (*ShardTree) Ascend

func (t *ShardTree) Ascend(fn func(Shard *bhmetapb.Shard) bool)

Ascend asc iterator the tree until fn returns false

func (*ShardTree) AscendRange

func (t *ShardTree) AscendRange(start, end []byte, fn func(Shard *bhmetapb.Shard) bool)

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

func (*ShardTree) NextShard

func (t *ShardTree) NextShard(start []byte) *bhmetapb.Shard

NextShard return the next bigger key range Shard

func (*ShardTree) Remove

func (t *ShardTree) Remove(Shard bhmetapb.Shard) bool

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

func (*ShardTree) Search

func (t *ShardTree) Search(key []byte) bhmetapb.Shard

Search returns a Shard that contains the key.

func (*ShardTree) Update

func (t *ShardTree) Update(shard bhmetapb.Shard)

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

type WriteBatch

type WriteBatch struct {
	Ops    []int32
	Keys   [][]byte
	Values [][]byte
	TTLs   []int32
}

WriteBatch write batch

func NewWriteBatch

func NewWriteBatch() *WriteBatch

NewWriteBatch returns a write batch

func (*WriteBatch) Delete

func (wb *WriteBatch) Delete(key []byte) error

Delete remove the key

func (*WriteBatch) Reset

func (wb *WriteBatch) Reset()

Reset reset

func (*WriteBatch) Set

func (wb *WriteBatch) Set(key []byte, value []byte) error

Set set key, value

func (*WriteBatch) SetWithTTL

func (wb *WriteBatch) SetWithTTL(key []byte, value []byte, ttl int32) error

SetWithTTL set key, value with TTL in seconds

Directories

Path Synopsis
hrl module

Jump to

Keyboard shortcuts

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