Documentation ¶
Index ¶
- Constants
- Variables
- func MVCCEncode(key []byte, version int64) (dst []byte)
- func MVCCKeyCompare(a, b []byte) int
- func SplitMVCCKey(mvccKey []byte) (key, version []byte, ok bool)
- type Batch
- type Database
- func (db *Database) ApplyChangeset(version int64, cs *proto.NamedChangeSet) error
- func (db *Database) Close() error
- func (db *Database) Get(storeKey string, targetVersion int64, key []byte) ([]byte, error)
- func (db *Database) GetLatestVersion() (int64, error)
- func (db *Database) Has(storeKey string, version int64, key []byte) (bool, error)
- func (db *Database) Import(version int64, ch <-chan sstypes.ImportEntry) error
- func (db *Database) Iterator(storeKey string, version int64, start, end []byte) (types.Iterator, error)
- func (db *Database) Prune(version int64) error
- func (db *Database) ReverseIterator(storeKey string, version int64, start, end []byte) (types.Iterator, error)
- func (db *Database) SetLatestVersion(version int64) error
Constants ¶
const ( VersionSize = 8 StorePrefixTpl = "s/k:%s/" // s/k:<storeKey> )
Variables ¶
var MVCCComparer = &pebble.Comparer{ Name: "ss_pebbledb_comparator", Compare: MVCCKeyCompare, AbbreviatedKey: func(k []byte) uint64 { key, _, ok := SplitMVCCKey(k) if !ok { return 0 } return pebble.DefaultComparer.AbbreviatedKey(key) }, Equal: func(a, b []byte) bool { return MVCCKeyCompare(a, b) == 0 }, Separator: func(dst, a, b []byte) []byte { aKey, _, ok := SplitMVCCKey(a) if !ok { return append(dst, a...) } bKey, _, ok := SplitMVCCKey(b) if !ok { return append(dst, a...) } if bytes.Equal(aKey, bKey) { return append(dst, a...) } n := len(dst) dst = pebble.DefaultComparer.Separator(dst, aKey, bKey) buf := dst[n:] if bytes.Equal(aKey, buf) { return append(dst[:n], a...) } return append(dst, 0) }, ImmediateSuccessor: func(dst, a []byte) []byte { return append(append(dst, a...), 0) }, Successor: func(dst, a []byte) []byte { aKey, _, ok := SplitMVCCKey(a) if !ok { return append(dst, a...) } n := len(dst) dst = pebble.DefaultComparer.Successor(dst, aKey) buf := dst[n:] if bytes.Equal(aKey, buf) { return append(dst[:n], a...) } return append(dst, 0) }, FormatKey: func(k []byte) fmt.Formatter { return mvccKeyFormatter{key: k} }, Split: func(k []byte) int { key, _, ok := SplitMVCCKey(k) if !ok { return len(k) } return len(key) + 1 }, }
MVCCComparer returns a PebbleDB Comparer with encoding and decoding routines for MVCC control, used to compare and store versioned keys.
Note: This Comparer implementation is largely based on PebbleDB's internal MVCC example, which can be found here: https://github.com/cockroachdb/pebble/blob/master/cmd/pebble/mvcc.go
Functions ¶
func MVCCEncode ¶
<key>\x00[<version>]<#version-bytes>
func SplitMVCCKey ¶
SplitMVCCKey accepts an MVCC key and returns the "user" key, the MVCC version, and a boolean indicating if the provided key is an MVCC key.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func (*Database) ApplyChangeset ¶
func (db *Database) ApplyChangeset(version int64, cs *proto.NamedChangeSet) error
func (*Database) GetLatestVersion ¶
func (*Database) Import ¶
func (db *Database) Import(version int64, ch <-chan sstypes.ImportEntry) error
func (*Database) Prune ¶
Prune for the PebbleDB SS backend is currently not supported. It seems the only reliable way to prune is to iterate over the desired domain and either manually tombstone or delete. Either way, the operation would be timely.