util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTimeoutWheel = putil.DefaultTimeoutWheel
)

Functions

func CpuUsages

func CpuUsages() ([]float64, error)

CpuUsages returns cpu usages

func DescribeReplica added in v0.2.0

func DescribeReplica(shardID uint64, peerID uint64) string

DescribeReplica returns a string representation of a replica ID used in logging.

func DiskStats

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

DiskStats returns the disk usage stats

func FirstError added in v0.2.0

func FirstError(err1 error, err2 error) error

FirstError returns the first error.

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 ShardItem

type ShardItem struct {
	Shard meta.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 *meta.Shard) bool)

Ascend asc iterator the tree until fn returns false

func (*ShardTree) AscendRange

func (t *ShardTree) AscendRange(start, end []byte, fn func(Shard *meta.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) *meta.Shard

NextShard return the next bigger key range Shard

func (*ShardTree) Remove

func (t *ShardTree) Remove(shard meta.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) meta.Shard

Search returns a Shard that contains the key.

func (*ShardTree) Update

func (t *ShardTree) Update(shards ...meta.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 interface {
	// Set set kv-value to the batch
	Set([]byte, []byte)
	// Delete add delete key to the batch
	Delete([]byte)
	// DeleteRange deletes the keys specified in the range
	DeleteRange([]byte, []byte)
	// Reset reset the batch
	Reset()
	// Close close the batch
	Close()
}

WriteBatch write batch

Directories

Path Synopsis
hrl module

Jump to

Keyboard shortcuts

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