storage

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: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LHeadDirection        uint8  = 0
	LTailDirection        uint8  = 1
	LItemMinIndex         uint64 = 1024
	LItemMaxIndex         uint64 = 1<<64 - 1024
	LItemInitIndex        uint64 = 1<<32 - 512
	LimitConcurrencyWrite        = 50000
)

Variables

View Source
var (
	ScoreMin int64 = math.MinInt64 + 2
	ScoreMax int64 = math.MaxInt64 - 1
)
View Source
var (
	// ErrKeySize key size is 0
	ErrKeySize = errors.New("invalid key size")
	// ErrValueSize value size is 0
	ErrValueSize = errors.New("invalid value size")
	// ErrEmptyKey key size is 0
	ErrEmptyKey = errors.New("invalid key size")
	//ErrListIndex index not in list range[head, tail]
	ErrListIndex = errors.New("invalid index of list")
	//ErrKeyOrFieldEmpty length of key or field is zero
	ErrKeyOrFieldEmpty = errors.New("invalid key or field")

	ErrInvalidMeta = errors.New("ERR invalid key meta")
)

Functions

func KVPrefixNext

func KVPrefixNext(key []byte) []byte

KVPrefixNext use Greedy algorithm, calculate next KVPrefix

func MarshalHashObj

func MarshalHashObj(obj *HashObj) []byte

func MarshalListObj

func MarshalListObj(obj *ListObj) []byte

MarshalListObj Serialize ListObj func

func MarshalSetObj

func MarshalSetObj(obj *SetObj) []byte

func MarshalZSetObj

func MarshalZSetObj(obj *ZSetObj) []byte

func RawKeyPrefix

func RawKeyPrefix(key []byte) []byte

Types

type BoltCfg

type BoltCfg struct {
	DataPath string
	FileMode os.FileMode
	Options  bolt.Options
}

type DataEngine

type DataEngine interface {
	RangeDeleteable
	// GetTargetSizeKey Find a key in the range [startKey, endKey) that sum size over target
	// if found returns the key
	GetTargetSizeKey(startKey []byte, endKey []byte, size uint64) (uint64, []byte, error)
	// CreateSnapshot create a snapshot file under the giving path
	CreateSnapshot(path string, start, end []byte) error
	// ApplySnapshot apply a snapshort file from giving path
	ApplySnapshot(path string) error

	// ScanIndexInfo scans the range and execute the handler fun. Returens a tuple (error count, first error)
	ScanIndexInfo(startKey []byte, endKey []byte, skipEmpty bool, handler func(key, idxInfo []byte) error) (int, error)
	SetIndexInfo(key, idxInfo []byte) error
	GetIndexInfo(key []byte) (idxInfo []byte, err error)
}

DataEngine is the storage of redis data

type Driver

type Driver interface {
	GetEngine() Engine
	GetDataEngine() DataEngine
	GetKVEngine() KVEngine
	GetHashEngine() HashEngine
	GetSetEngine() SetEngine
	GetZSetEngine() ZSetEngine
	GetListEngine() ListEngine
	NewWriteBatch() WriteBatch
	Write(wb WriteBatch, sync bool) error
}

Driver is def storage interface

func NewBoltDriver

func NewBoltDriver(cfg *BoltCfg) (Driver, error)

func NewMemoryDriver

func NewMemoryDriver() Driver

NewMemoryDriver returns Driver with memory implemention

func NewNemoDriver

func NewNemoDriver(cfg *NemoCfg) (Driver, error)

NewNemoDriver return a driver implemention by nemo

type Engine

type Engine interface {
	Scanable
	Seekable
	RangeDeleteable

	Set(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Delete(key []byte) error
}

Engine is the storage of meta data

type HashEngine

type HashEngine interface {
	HSet(key, field, value []byte) (int64, error)
	HGet(key, field []byte) ([]byte, error)
	HDel(key []byte, fields ...[]byte) (int64, error)
	HExists(key, field []byte) (bool, error)
	HKeys(key []byte) ([][]byte, error)
	HVals(key []byte) ([][]byte, error)
	HGetAll(key []byte) ([]*raftcmdpb.FVPair, error)
	HScanGet(key, start []byte, count int) ([]*raftcmdpb.FVPair, error)
	HLen(key []byte) (int64, error)
	HMGet(key []byte, fields ...[]byte) ([][]byte, []error)
	HMSet(key []byte, fields, values [][]byte) error
	HSetNX(key, field, value []byte) (int64, error)
	HStrLen(key, field []byte) (int64, error)
	HIncrBy(key, field []byte, incrment int64) ([]byte, error)
}

HashEngine is the storage of Hash

type HashObj

type HashObj struct {
	Size uint64
}

func UnmarshalHashObj

func UnmarshalHashObj(raw []byte) (*HashObj, error)

type KVEngine

type KVEngine interface {
	RangeDeleteable

	Set(key, value []byte) error
	MSet(keys [][]byte, values [][]byte) error
	Get(key []byte) ([]byte, error)
	IncrBy(key []byte, incrment int64) (int64, error)
	DecrBy(key []byte, incrment int64) (int64, error)
	GetSet(key, value []byte) ([]byte, error)
	Append(key, value []byte) (int64, error)
	SetNX(key, value []byte) (int64, error)
	StrLen(key []byte) (int64, error)
	NewWriteBatch() WriteBatch
	Write(wb WriteBatch) error
}

KVEngine is the storage of KV

type ListEngine

type ListEngine interface {
	LIndex(key []byte, index int64) ([]byte, error)
	LInsert(key []byte, pos int, pivot []byte, value []byte) (int64, error)
	LLen(key []byte) (int64, error)
	LPop(key []byte) ([]byte, error)
	LPush(key []byte, values ...[]byte) (int64, error)
	LPushX(key []byte, value []byte) (int64, error)
	LRange(key []byte, begin int64, end int64) ([][]byte, error)
	LRem(key []byte, count int64, value []byte) (int64, error)
	LSet(key []byte, index int64, value []byte) error
	LTrim(key []byte, begin int64, end int64) error
	RPop(key []byte) ([]byte, error)
	RPush(key []byte, values ...[]byte) (int64, error)
	RPushX(key []byte, value []byte) (int64, error)
}

ListEngine is the storage of List

type ListObj

type ListObj struct {
	Head uint64
	Tail uint64
	Size uint64
}

func UnmarshalListObj

func UnmarshalListObj(raw []byte) (*ListObj, error)

UnmarshalListObj Deserialize ListObj func

type MemberPair

type MemberPair struct {
	Score  int64
	Member []byte
}

type NemoCfg

type NemoCfg struct {
	DataPath              string
	OptionPath            string
	LimitConcurrencyWrite uint64
}

NemoCfg nemo cfg

type RangeDeleteable

type RangeDeleteable interface {
	RangeDelete(start, end []byte) error
}

RangeDeleteable support range delete

type Scanable

type Scanable interface {
	// Scan scans the range and execute the handler fun.
	// returns false means end the scan.
	Scan(start, end []byte, handler func(key, value []byte) (bool, error), pooledKey bool) error
	// Free free the pooled bytes
	Free(pooled []byte)
}

Scanable support scan

type Seekable

type Seekable interface {
	Seek(key []byte) ([]byte, []byte, error)
}

Seekable support seek

type SetEngine

type SetEngine interface {
	SAdd(key []byte, members ...[]byte) (int64, error)
	SRem(key []byte, members ...[]byte) (int64, error)
	SCard(key []byte) (int64, error)
	SMembers(key []byte) ([][]byte, error)
	SIsMember(key []byte, member []byte) (int64, error)
	SPop(key []byte) ([]byte, error)
}

SetEngine is the storage of Set

type SetObj

type SetObj struct {
	Size uint64
}

func UnmarshalSetObj

func UnmarshalSetObj(raw []byte) (*SetObj, error)

type WriteBatch

type WriteBatch interface {
	Delete(key []byte) error
	Set(key []byte, value []byte) error
}

WriteBatch batch operation

type ZSetEngine

type ZSetEngine interface {
	ZAdd(key []byte, score float64, member []byte) (int64, error)
	ZCard(key []byte) (int64, error)
	ZCount(key []byte, min []byte, max []byte) (int64, error)
	ZIncrBy(key []byte, member []byte, by float64) ([]byte, error)
	ZLexCount(key []byte, min []byte, max []byte) (int64, error)
	ZRange(key []byte, start int64, stop int64) ([]*raftcmdpb.ScorePair, error)
	ZRangeByLex(key []byte, min []byte, max []byte) ([][]byte, error)
	ZRangeByScore(key []byte, min []byte, max []byte) ([]*raftcmdpb.ScorePair, error)
	ZRank(key []byte, member []byte) (int64, error)
	ZRem(key []byte, members ...[]byte) (int64, error)
	ZRemRangeByLex(key []byte, min []byte, max []byte) (int64, error)
	ZRemRangeByRank(key []byte, start int64, stop int64) (int64, error)
	ZRemRangeByScore(key []byte, min []byte, max []byte) (int64, error)
	ZScore(key []byte, member []byte) ([]byte, error)
}

ZSetEngine is the storage of ZSet

type ZSetObj

type ZSetObj struct {
	Size uint64
}

func UnmarshalZSetObj

func UnmarshalZSetObj(raw []byte) (*ZSetObj, error)

Jump to

Keyboard shortcuts

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