Documentation ¶
Index ¶
- func IsTombstone(val []byte) bool
- type Getter
- type Iterator
- type KVUnionStore
- func (us *KVUnionStore) Get(ctx context.Context, k []byte) ([]byte, error)
- func (us *KVUnionStore) GetMemBuffer() *MemDB
- func (us *KVUnionStore) HasPresumeKeyNotExists(k []byte) bool
- func (us *KVUnionStore) Iter(k, upperBound []byte) (Iterator, error)
- func (us *KVUnionStore) IterReverse(k []byte) (Iterator, error)
- func (us *KVUnionStore) SetEntrySizeLimit(entryLimit, bufferLimit uint64)
- func (us *KVUnionStore) UnmarkPresumeKeyNotExists(k []byte)
- type MemDB
- func (db *MemDB) Checkpoint() *MemDBCheckpoint
- func (db *MemDB) Cleanup(h int)
- func (db *MemDB) Delete(key []byte) error
- func (db *MemDB) DeleteWithFlags(key []byte, ops ...kv.FlagsOp) error
- func (db *MemDB) Dirty() bool
- func (db *MemDB) DiscardValues()
- func (db *MemDB) Get(key []byte) ([]byte, error)
- func (db *MemDB) GetFlags(key []byte) (kv.KeyFlags, error)
- func (db *MemDB) GetKeyByHandle(handle MemKeyHandle) []byte
- func (db *MemDB) GetValueByHandle(handle MemKeyHandle) ([]byte, bool)
- func (db *MemDB) InspectStage(handle int, f func([]byte, kv.KeyFlags, []byte))
- func (db *MemDB) Iter(k []byte, upperBound []byte) (Iterator, error)
- func (db *MemDB) IterReverse(k []byte) (Iterator, error)
- func (db *MemDB) IterReverseWithFlags(k []byte) *MemdbIterator
- func (db *MemDB) IterWithFlags(k []byte, upperBound []byte) *MemdbIterator
- func (db *MemDB) Len() int
- func (db *MemDB) Mem() uint64
- func (db *MemDB) Release(h int)
- func (db *MemDB) RemoveFromBuffer(key []byte)
- func (db *MemDB) Reset()
- func (db *MemDB) RevertToCheckpoint(cp *MemDBCheckpoint)
- func (db *MemDB) SelectValueHistory(key []byte, predicate func(value []byte) bool) ([]byte, error)
- func (db *MemDB) Set(key []byte, value []byte) error
- func (db *MemDB) SetMemoryFootprintChangeHook(hook func(uint64))
- func (db *MemDB) SetWithFlags(key []byte, value []byte, ops ...kv.FlagsOp) error
- func (db *MemDB) Size() int
- func (db *MemDB) SnapshotGetter() Getter
- func (db *MemDB) SnapshotIter(start, end []byte) Iterator
- func (db *MemDB) Staging() int
- func (db *MemDB) UpdateFlags(key []byte, ops ...kv.FlagsOp)
- type MemDBCheckpoint
- type MemKeyHandle
- type MemdbIterator
- func (i *MemdbIterator) Close()
- func (i *MemdbIterator) Flags() kv.KeyFlags
- func (i *MemdbIterator) Handle() MemKeyHandle
- func (i *MemdbIterator) HasValue() bool
- func (i *MemdbIterator) Key() []byte
- func (i *MemdbIterator) Next() error
- func (i *MemdbIterator) UpdateFlags(ops ...kv.FlagsOp)
- func (i *MemdbIterator) Valid() bool
- func (i *MemdbIterator) Value() []byte
- type UnionIter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTombstone ¶
IsTombstone returns whether the value is a tombstone.
Types ¶
type Getter ¶
type Getter interface { // Get gets the value for key k from kv store. // If corresponding kv pair does not exist, it returns nil and ErrNotExist. Get(k []byte) ([]byte, error) }
Getter is the interface for the Get method.
type KVUnionStore ¶
type KVUnionStore struct {
// contains filtered or unexported fields
}
KVUnionStore is an in-memory Store which contains a buffer for write and a snapshot for read.
func NewUnionStore ¶
func NewUnionStore(snapshot uSnapshot) *KVUnionStore
NewUnionStore builds a new unionStore.
func (*KVUnionStore) GetMemBuffer ¶
func (us *KVUnionStore) GetMemBuffer() *MemDB
GetMemBuffer return the MemBuffer binding to this unionStore.
func (*KVUnionStore) HasPresumeKeyNotExists ¶
func (us *KVUnionStore) HasPresumeKeyNotExists(k []byte) bool
HasPresumeKeyNotExists gets the key exist error info for the lazy check.
func (*KVUnionStore) Iter ¶
func (us *KVUnionStore) Iter(k, upperBound []byte) (Iterator, error)
Iter implements the Retriever interface.
func (*KVUnionStore) IterReverse ¶
func (us *KVUnionStore) IterReverse(k []byte) (Iterator, error)
IterReverse implements the Retriever interface.
func (*KVUnionStore) SetEntrySizeLimit ¶
func (us *KVUnionStore) SetEntrySizeLimit(entryLimit, bufferLimit uint64)
SetEntrySizeLimit sets the size limit for each entry and total buffer.
func (*KVUnionStore) UnmarkPresumeKeyNotExists ¶
func (us *KVUnionStore) UnmarkPresumeKeyNotExists(k []byte)
UnmarkPresumeKeyNotExists deletes the key exist error info for the lazy check.
type MemDB ¶
type MemDB struct { // This RWMutex only used to ensure memdbSnapGetter.Get will not race with // concurrent memdb.Set, memdb.SetWithFlags, memdb.Delete and memdb.UpdateFlags. sync.RWMutex // contains filtered or unexported fields }
MemDB is rollbackable Red-Black Tree optimized for TiDB's transaction states buffer use scenario. You can think MemDB is a combination of two separate tree map, one for key => value and another for key => keyFlags.
The value map is rollbackable, that means you can use the `Staging`, `Release` and `Cleanup` API to safely modify KVs.
The flags map is not rollbackable. There are two types of flag, persistent and non-persistent. When discarding a newly added KV in `Cleanup`, the non-persistent flags will be cleared. If there are persistent flags associated with key, we will keep this key in node without value.
func (*MemDB) Checkpoint ¶
func (db *MemDB) Checkpoint() *MemDBCheckpoint
Checkpoint returns a checkpoint of MemDB.
func (*MemDB) Cleanup ¶
Cleanup cleanup the resources referenced by the StagingHandle. If the changes are not published by `Release`, they will be discarded.
func (*MemDB) DeleteWithFlags ¶
DeleteWithFlags delete key with the given KeyFlags
func (*MemDB) DiscardValues ¶
func (db *MemDB) DiscardValues()
DiscardValues releases the memory used by all values. NOTE: any operation need value will panic after this function.
func (*MemDB) Get ¶
Get gets the value for key k from kv store. If corresponding kv pair does not exist, it returns nil and ErrNotExist.
func (*MemDB) GetKeyByHandle ¶
func (db *MemDB) GetKeyByHandle(handle MemKeyHandle) []byte
GetKeyByHandle returns key by handle.
func (*MemDB) GetValueByHandle ¶
func (db *MemDB) GetValueByHandle(handle MemKeyHandle) ([]byte, bool)
GetValueByHandle returns value by handle.
func (*MemDB) InspectStage ¶
InspectStage used to inspect the value updates in the given stage.
func (*MemDB) Iter ¶
Iter creates an Iterator positioned on the first entry that k <= entry's key. If such entry is not found, it returns an invalid Iterator with no error. It yields only keys that < upperBound. If upperBound is nil, it means the upperBound is unbounded. The Iterator must be Closed after use.
func (*MemDB) IterReverse ¶
IterReverse creates a reversed Iterator positioned on the first entry which key is less than k. The returned iterator will iterate from greater key to smaller key. If k is nil, the returned iterator will be positioned at the last key. TODO: Add lower bound limit
func (*MemDB) IterReverseWithFlags ¶
func (db *MemDB) IterReverseWithFlags(k []byte) *MemdbIterator
IterReverseWithFlags returns a reversed MemdbIterator.
func (*MemDB) IterWithFlags ¶
func (db *MemDB) IterWithFlags(k []byte, upperBound []byte) *MemdbIterator
IterWithFlags returns a MemdbIterator.
func (*MemDB) Release ¶
Release publish all modifications in the latest staging buffer to upper level.
func (*MemDB) RemoveFromBuffer ¶
RemoveFromBuffer removes a record from the mem buffer. It should be only used for test.
func (*MemDB) RevertToCheckpoint ¶
func (db *MemDB) RevertToCheckpoint(cp *MemDBCheckpoint)
RevertToCheckpoint reverts the MemDB to the checkpoint.
func (*MemDB) SelectValueHistory ¶
SelectValueHistory select the latest value which makes `predicate` returns true from the modification history.
func (*MemDB) Set ¶
Set sets the value for key k as v into kv store. v must NOT be nil or empty, otherwise it returns ErrCannotSetNilValue.
func (*MemDB) SetMemoryFootprintChangeHook ¶
SetMemoryFootprintChangeHook sets the hook function that is triggered when memdb grows.
func (*MemDB) SetWithFlags ¶
SetWithFlags put key-value into the last active staging buffer with the given KeyFlags.
func (*MemDB) SnapshotGetter ¶
SnapshotGetter returns a Getter for a snapshot of MemBuffer.
func (*MemDB) SnapshotIter ¶
SnapshotIter returns a Iterator for a snapshot of MemBuffer.
type MemDBCheckpoint ¶
type MemDBCheckpoint struct {
// contains filtered or unexported fields
}
MemDBCheckpoint is the checkpoint of memory DB.
type MemKeyHandle ¶
type MemKeyHandle struct { // Opaque user data UserData uint16 // contains filtered or unexported fields }
MemKeyHandle represents a pointer for key in MemBuffer.
type MemdbIterator ¶
type MemdbIterator struct {
// contains filtered or unexported fields
}
MemdbIterator is an Iterator with KeyFlags related functions.
func (*MemdbIterator) Flags ¶
func (i *MemdbIterator) Flags() kv.KeyFlags
Flags returns flags belong to current iterator.
func (*MemdbIterator) Handle ¶
func (i *MemdbIterator) Handle() MemKeyHandle
Handle returns MemKeyHandle with the current position.
func (*MemdbIterator) HasValue ¶
func (i *MemdbIterator) HasValue() bool
HasValue returns false if it is flags only.
func (*MemdbIterator) UpdateFlags ¶
func (i *MemdbIterator) UpdateFlags(ops ...kv.FlagsOp)
UpdateFlags updates and apply with flagsOp.
func (*MemdbIterator) Valid ¶
func (i *MemdbIterator) Valid() bool
Valid returns true if the current iterator is valid.
type UnionIter ¶
type UnionIter struct {
// contains filtered or unexported fields
}
UnionIter is the iterator on an UnionStore.
func NewUnionIter ¶
NewUnionIter returns a union iterator for BufferStore.
func (*UnionIter) Close ¶
func (iter *UnionIter) Close()
Close implements the Iterator Close interface.