Documentation ¶
Index ¶
- Constants
- Variables
- func CopyBytes(b []byte) (copiedBytes []byte)
- func GetKey(key []byte, version int64) ([]byte, error)
- func GetKeyPerfix(key []byte) []byte
- func ToNum(bs []byte) int
- type Batch
- type DB
- type GoBadgerDB
- func (db *GoBadgerDB) BatchGet(keys [][]byte) (value [][]byte, err error)
- func (db *GoBadgerDB) Close()
- func (db *GoBadgerDB) DB() *badger.DB
- func (db *GoBadgerDB) Delete(key []byte) error
- func (db *GoBadgerDB) DeleteSync(key []byte) error
- func (db *GoBadgerDB) Get(key []byte) ([]byte, error)
- func (db *GoBadgerDB) Iterator(start, end []byte, reverse bool) Iterator
- func (db *GoBadgerDB) NewBatch(sync bool) Batch
- func (db *GoBadgerDB) Print()
- func (db *GoBadgerDB) Set(key []byte, value []byte) error
- func (db *GoBadgerDB) SetSync(key []byte, value []byte) error
- func (db *GoBadgerDB) Stats() map[string]string
- type GoBadgerDBBatch
- type GoLevelDB
- func (db *GoLevelDB) BatchGet(keys [][]byte) (value [][]byte, err error)
- func (db *GoLevelDB) Close()
- func (db *GoLevelDB) DB() *leveldb.DB
- func (db *GoLevelDB) Delete(key []byte) error
- func (db *GoLevelDB) DeleteSync(key []byte) error
- func (db *GoLevelDB) Get(key []byte) ([]byte, error)
- func (db *GoLevelDB) Iterator(start []byte, end []byte, reverse bool) Iterator
- func (db *GoLevelDB) NewBatch(sync bool) Batch
- func (db *GoLevelDB) Print()
- func (db *GoLevelDB) Set(key []byte, value []byte) error
- func (db *GoLevelDB) SetSync(key []byte, value []byte) error
- func (db *GoLevelDB) Stats() map[string]string
- type GoMemDB
- func (db *GoMemDB) BatchGet(keys [][]byte) (value [][]byte, err error)
- func (db *GoMemDB) Close()
- func (db *GoMemDB) DB() map[string][]byte
- func (db *GoMemDB) Delete(key []byte) error
- func (db *GoMemDB) DeleteSync(key []byte) error
- func (db *GoMemDB) Get(key []byte) ([]byte, error)
- func (db *GoMemDB) Iterator(start []byte, end []byte, reverse bool) Iterator
- func (db *GoMemDB) NewBatch(sync bool) Batch
- func (db *GoMemDB) Print()
- func (db *GoMemDB) Set(key []byte, value []byte) error
- func (db *GoMemDB) SetSync(key []byte, value []byte) error
- func (db *GoMemDB) Stats() map[string]string
- type GoSSDB
- func (db *GoSSDB) BatchGet(keys [][]byte) (values [][]byte, err error)
- func (db *GoSSDB) Close()
- func (db *GoSSDB) Delete(key []byte) error
- func (db *GoSSDB) DeleteSync(key []byte) error
- func (db *GoSSDB) Get(key []byte) ([]byte, error)
- func (db *GoSSDB) Iterator(itbeg []byte, itend []byte, reverse bool) Iterator
- func (db *GoSSDB) NewBatch(sync bool) Batch
- func (db *GoSSDB) Print()
- func (db *GoSSDB) Set(key []byte, value []byte) error
- func (db *GoSSDB) SetSync(key []byte, value []byte) error
- func (db *GoSSDB) Stats() map[string]string
- type Iterator
- type IteratorDB
- type IteratorSeeker
- type KV
- type KVDB
- type KVDBList
- type ListHelper
- func (db *ListHelper) IteratorCallback(start []byte, end []byte, count int32, direction int32, ...)
- func (db *ListHelper) IteratorScan(prefix []byte, key []byte, count int32, direction int32) (values [][]byte)
- func (db *ListHelper) IteratorScanFromFirst(prefix []byte, count int32) (values [][]byte)
- func (db *ListHelper) IteratorScanFromLast(prefix []byte, count int32) (values [][]byte)
- func (db *ListHelper) List(prefix, key []byte, count, direction int32) (values [][]byte)
- func (db *ListHelper) PrefixCount(prefix []byte) (count int64)
- func (db *ListHelper) PrefixScan(prefix []byte) (values [][]byte)
- type Lister
- type MVCC
- type MVCCHelper
- type MVCCIter
- type MVCCKV
- type PegasusBatch
- type PegasusDB
- func (db *PegasusDB) BatchGet(keys [][]byte) (values [][]byte, err error)
- func (db *PegasusDB) Close()
- func (db *PegasusDB) Delete(key []byte) error
- func (db *PegasusDB) DeleteSync(key []byte) error
- func (db *PegasusDB) Get(key []byte) ([]byte, error)
- func (db *PegasusDB) Iterator(begin []byte, end []byte, reverse bool) Iterator
- func (db *PegasusDB) NewBatch(sync bool) Batch
- func (db *PegasusDB) Print()
- func (db *PegasusDB) Set(key []byte, value []byte) error
- func (db *PegasusDB) SetSync(key []byte, value []byte) error
- func (db *PegasusDB) Stats() map[string]string
- type PegasusIt
- func (dbit *PegasusIt) Close()
- func (dbit *PegasusIt) Error() error
- func (dbit *PegasusIt) Key() []byte
- func (dbit *PegasusIt) Next() bool
- func (it *PegasusIt) Prefix() []byte
- func (dbit *PegasusIt) Rewind() bool
- func (dbit *PegasusIt) Seek(key []byte) bool
- func (dbit *PegasusIt) Valid() bool
- func (dbit *PegasusIt) Value() []byte
- func (dbit *PegasusIt) ValueCopy() []byte
- type RoundInt
- type SDBClient
- func (c *SDBClient) Close() error
- func (c *SDBClient) Del(key string) error
- func (c *SDBClient) Do(args ...interface{}) ([]string, error)
- func (c *SDBClient) Get(key string) (*Value, error)
- func (c *SDBClient) Keys(keyStart, keyEnd string, limit int64) ([]string, error)
- func (c *SDBClient) MultiDel(key ...string) (err error)
- func (c *SDBClient) MultiGet(key ...string) (vals []*Value, err error)
- func (c *SDBClient) MultiSet(kvs map[string][]byte) (err error)
- func (c *SDBClient) Rkeys(keyStart, keyEnd string, limit int64) ([]string, error)
- func (c *SDBClient) Set(key string, val []byte) (err error)
- type SDBPool
- type SimpleMVCC
- func (m *SimpleMVCC) AddMVCC(kvs []*types.KeyValue, hash []byte, prevHash []byte, version int64) ([]*types.KeyValue, error)
- func (m *SimpleMVCC) DelMVCC(hash []byte, version int64, strict bool) ([]*types.KeyValue, error)
- func (m *SimpleMVCC) DelVersionKV(hash []byte, version int64) ([]*types.KeyValue, error)
- func (m *SimpleMVCC) GetDelKV(key []byte, version int64) (*types.KeyValue, error)
- func (m *SimpleMVCC) GetDelKVList(version int64) ([]*types.KeyValue, error)
- func (m *SimpleMVCC) GetMaxVersion() (int64, error)
- func (m *SimpleMVCC) GetSaveKV(key []byte, value []byte, version int64) (*types.KeyValue, error)
- func (m *SimpleMVCC) GetV(key []byte, version int64) ([]byte, error)
- func (m *SimpleMVCC) GetVersion(hash []byte) (int64, error)
- func (m *SimpleMVCC) GetVersionHash(version int64) ([]byte, error)
- func (m *SimpleMVCC) SetV(key []byte, value []byte, version int64) error
- func (m *SimpleMVCC) SetVersionKV(hash []byte, version int64) ([]*types.KeyValue, error)
- type SsdbBench
- type SsdbNode
- type TransactionDB
- type Value
Constants ¶
const ( ENDN = '\n' ENDR = '\r' OK = "ok" NotFound = "not_found" ReadTimeOut = 3 WriteTimeOut = 3 ReadBufSize = 8 * 1024 IteratorPageSize = 10240 PooledSize = 3 )
const ( ListDESC = int32(0) ListASC = int32(1) ListSeek = int32(2) )
Variables ¶
var ErrNotFoundInDb = errors.New("ErrNotFoundInDb")
var (
FormatString = "%v\nthe trace error is\n%s"
)
var HashKeyLen = 24
Functions ¶
func GetKeyPerfix ¶
Types ¶
type DB ¶
type GoBadgerDB ¶
type GoBadgerDB struct { TransactionDB // contains filtered or unexported fields }
func NewGoBadgerDB ¶
func NewGoBadgerDB(name string, dir string, cache int) (*GoBadgerDB, error)
func (*GoBadgerDB) BatchGet ¶
func (db *GoBadgerDB) BatchGet(keys [][]byte) (value [][]byte, err error)
func (*GoBadgerDB) Close ¶
func (db *GoBadgerDB) Close()
func (*GoBadgerDB) DB ¶
func (db *GoBadgerDB) DB() *badger.DB
func (*GoBadgerDB) Delete ¶
func (db *GoBadgerDB) Delete(key []byte) error
func (*GoBadgerDB) DeleteSync ¶
func (db *GoBadgerDB) DeleteSync(key []byte) error
func (*GoBadgerDB) Iterator ¶
func (db *GoBadgerDB) Iterator(start, end []byte, reverse bool) Iterator
func (*GoBadgerDB) NewBatch ¶
func (db *GoBadgerDB) NewBatch(sync bool) Batch
func (*GoBadgerDB) Print ¶
func (db *GoBadgerDB) Print()
func (*GoBadgerDB) Stats ¶
func (db *GoBadgerDB) Stats() map[string]string
type GoBadgerDBBatch ¶
type GoBadgerDBBatch struct {
// contains filtered or unexported fields
}
func (*GoBadgerDBBatch) Delete ¶
func (mBatch *GoBadgerDBBatch) Delete(key []byte)
func (*GoBadgerDBBatch) Reset ¶
func (mBatch *GoBadgerDBBatch) Reset()
func (*GoBadgerDBBatch) Set ¶
func (mBatch *GoBadgerDBBatch) Set(key, value []byte)
func (*GoBadgerDBBatch) ValueSize ¶
func (mBatch *GoBadgerDBBatch) ValueSize() int
func (*GoBadgerDBBatch) Write ¶
func (mBatch *GoBadgerDBBatch) Write() error
type GoLevelDB ¶
type GoLevelDB struct { TransactionDB // contains filtered or unexported fields }
func (*GoLevelDB) DeleteSync ¶
type GoMemDB ¶
type GoMemDB struct { TransactionDB // contains filtered or unexported fields }
func (*GoMemDB) DeleteSync ¶
type GoSSDB ¶
type GoSSDB struct { TransactionDB // contains filtered or unexported fields }
func (*GoSSDB) DeleteSync ¶
type IteratorDB ¶
type IteratorSeeker ¶
type KVDBList ¶
type KVDBList struct { DB // contains filtered or unexported fields }
func (*KVDBList) PrefixCount ¶
type ListHelper ¶
type ListHelper struct {
// contains filtered or unexported fields
}
func NewListHelper ¶
func NewListHelper(db IteratorDB) *ListHelper
func (*ListHelper) IteratorCallback ¶
func (*ListHelper) IteratorScan ¶
func (*ListHelper) IteratorScanFromFirst ¶
func (db *ListHelper) IteratorScanFromFirst(prefix []byte, count int32) (values [][]byte)
func (*ListHelper) IteratorScanFromLast ¶
func (db *ListHelper) IteratorScanFromLast(prefix []byte, count int32) (values [][]byte)
func (*ListHelper) List ¶
func (db *ListHelper) List(prefix, key []byte, count, direction int32) (values [][]byte)
func (*ListHelper) PrefixCount ¶
func (db *ListHelper) PrefixCount(prefix []byte) (count int64)
func (*ListHelper) PrefixScan ¶
func (db *ListHelper) PrefixScan(prefix []byte) (values [][]byte)
type MVCC ¶
type MVCC interface { MVCCKV SetVersion(hash []byte, version int64) error DelVersion(hash []byte) error GetVersion(hash []byte) (int64, error) GetV(key []byte, version int64) ([]byte, error) SetV(key []byte, value []byte, version int64) error DelV(key []byte, version int64) error AddMVCC(kvs []*types.KeyValue, hash []byte, prevHash []byte, version int64) ([]*types.KeyValue, error) DelMVCC(hash []byte, version int64, strict bool) ([]*types.KeyValue, error) GetMaxVersion() (int64, error) GetVersionHash(version int64) ([]byte, error) //回收: 某个版本之前的所有数据 //1. 保证有一个最新版本 //2. 这个操作回遍历所有的key所以比较慢 Trash(version int64) error }
MVCC mvcc interface
type MVCCHelper ¶
type MVCCHelper struct { *SimpleMVCC // contains filtered or unexported fields }
MVCCHelper impl MVCC interface
func (*MVCCHelper) DelV ¶
func (m *MVCCHelper) DelV(key []byte, version int64) error
DelV del key with version
func (*MVCCHelper) DelVersion ¶
func (m *MVCCHelper) DelVersion(hash []byte) error
DelVersion del stateHash version map
func (*MVCCHelper) PrintAll ¶
func (m *MVCCHelper) PrintAll()
func (*MVCCHelper) SetVersion ¶
func (m *MVCCHelper) SetVersion(hash []byte, version int64) error
SetVersion set stateHash -> version map
type MVCCIter ¶
type MVCCIter struct {
*MVCCHelper
}
mvcc 迭代器版本 支持db 原生迭代器接口 为了支持快速迭代,我这里采用了复制数据的做法
func NewMVCCIter ¶
type MVCCKV ¶
type MVCCKV interface { GetSaveKV(key []byte, value []byte, version int64) (*types.KeyValue, error) GetDelKV(key []byte, version int64) (*types.KeyValue, error) SetVersionKV(hash []byte, version int64) ([]*types.KeyValue, error) DelVersionKV([]byte, int64) ([]*types.KeyValue, error) }
MVCCKV only return kv when change database
type PegasusBatch ¶
type PegasusBatch struct {
// contains filtered or unexported fields
}
func (*PegasusBatch) Delete ¶
func (db *PegasusBatch) Delete(key []byte)
func (*PegasusBatch) Reset ¶
func (db *PegasusBatch) Reset()
func (*PegasusBatch) Set ¶
func (db *PegasusBatch) Set(key, value []byte)
func (*PegasusBatch) ValueSize ¶
func (db *PegasusBatch) ValueSize() int
func (*PegasusBatch) Write ¶
func (db *PegasusBatch) Write() error
注意本方法的实现逻辑,因为ssdb没有提供删除和更新同时进行的批量操作; 所以这里先执行更新操作(删除的KEY在这里会将VALUE设置为空); 然后再执行删除操作; 这样即使中间执行出错,也不会导致删除结果未写入的情况(值已经被置空);
type PegasusDB ¶
type PegasusDB struct { TransactionDB // contains filtered or unexported fields }
func (*PegasusDB) DeleteSync ¶
type SDBClient ¶
type SDBClient struct {
// contains filtered or unexported fields
}
func (*SDBClient) Keys ¶
列出处于区间 (key_start, key_end] 的 key 列表.("", ""] 表示整个区间.
keyStart int 返回的起始 key(不包含), 空字符串表示 -inf. keyEnd int 返回的结束 key(包含), 空字符串表示 +inf. limit int 最多返回这么多个元素. 返回 返回包含 key 的数组. 返回 err,可能的错误,操作成功返回 nil
type SimpleMVCC ¶
type SimpleMVCC struct {
// contains filtered or unexported fields
}
func NewSimpleMVCC ¶
func NewSimpleMVCC(db KVDB) *SimpleMVCC
func (*SimpleMVCC) AddMVCC ¶
func (m *SimpleMVCC) AddMVCC(kvs []*types.KeyValue, hash []byte, prevHash []byte, version int64) ([]*types.KeyValue, error)
AddMVCC add keys in a version 添加MVCC的规则: 必须提供现有hash 和 prev 的hash, 而且这两个版本号相差1
func (*SimpleMVCC) DelMVCC ¶
DelMVCC 删除某个版本 我们目前规定删除的方法: 1 -> 1-2-3-4-5,6 version 必须连续的增长 2 -> del 也必须从尾部开始删除
func (*SimpleMVCC) DelVersionKV ¶
DelVersionKV only export del version key value
func (*SimpleMVCC) GetDelKVList ¶
func (m *SimpleMVCC) GetDelKVList(version int64) ([]*types.KeyValue, error)
func (*SimpleMVCC) GetMaxVersion ¶
func (m *SimpleMVCC) GetMaxVersion() (int64, error)
func (*SimpleMVCC) GetV ¶
func (m *SimpleMVCC) GetV(key []byte, version int64) ([]byte, error)
GetV get key with version
func (*SimpleMVCC) GetVersion ¶
func (m *SimpleMVCC) GetVersion(hash []byte) (int64, error)
GetVersion get stateHash and version map
func (*SimpleMVCC) GetVersionHash ¶
func (m *SimpleMVCC) GetVersionHash(version int64) ([]byte, error)
func (*SimpleMVCC) SetV ¶
func (m *SimpleMVCC) SetV(key []byte, value []byte, version int64) error
SetV set key and value with version
func (*SimpleMVCC) SetVersionKV ¶
SetVersionKV only export SetVersionKV key and value
type TransactionDB ¶
type TransactionDB struct {
// contains filtered or unexported fields
}
func (*TransactionDB) Begin ¶
func (db *TransactionDB) Begin()
func (*TransactionDB) Commit ¶
func (db *TransactionDB) Commit()
func (*TransactionDB) GetCache ¶
func (db *TransactionDB) GetCache() *lru.ARCCache
func (*TransactionDB) Rollback ¶
func (db *TransactionDB) Rollback()
func (*TransactionDB) SetCacheSize ¶
func (db *TransactionDB) SetCacheSize(size int)