Documentation ¶
Index ¶
- Variables
- func BackoffErrReporter(site string) backoff.Notify
- func IsTombstone(val []byte) bool
- func Open(dirname string, options ...Option) (kv.Storage, error)
- type BatchBufferGetter
- type BufferBatchGetter
- type KVSnapshot
- func (s *KVSnapshot) BatchGet(_ context.Context, keys []kv.Key) (map[string][]byte, error)
- func (s *KVSnapshot) Get(_ context.Context, key kv.Key) ([]byte, error)
- func (s *KVSnapshot) Iter(lowerBound kv.Key, upperBound kv.Key) (kv.Iterator, error)
- func (s *KVSnapshot) IterReverse(lowerBound kv.Key, upperBound kv.Key) (kv.Iterator, error)
- func (s *KVSnapshot) StartVer() kv.Version
- type MemDB
- func (db *MemDB) Checkpoint() *MemDBCheckpoint
- func (db *MemDB) Cleanup(h int)
- func (db *MemDB) Delete(key kv.Key) error
- func (db *MemDB) DeleteWithFlags(key []byte, ops ...kv.FlagsOp) error
- func (db *MemDB) Dirty() bool
- func (db *MemDB) DiscardValues()
- func (db *MemDB) Get(_ context.Context, key kv.Key) ([]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(lowerBound, upperBound kv.Key) (kv.Iterator, error)
- func (db *MemDB) IterReverse(lowerBound, upperBound kv.Key) (kv.Iterator, error)
- func (db *MemDB) IterReverseWithFlags(k []byte) *MemDBIter
- func (db *MemDB) IterWithFlags(lowerBound []byte, upperBound []byte) *MemDBIter
- 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() kv.Getter
- func (db *MemDB) SnapshotIter(start, end []byte) kv.Iterator
- func (db *MemDB) Staging() int
- func (db *MemDB) UpdateFlags(key []byte, ops ...kv.FlagsOp)
- type MemDBCheckpoint
- type MemDBIter
- func (i *MemDBIter) Close()
- func (i *MemDBIter) Flags() kv.KeyFlags
- func (i *MemDBIter) Handle() MemKeyHandle
- func (i *MemDBIter) HasValue() bool
- func (i *MemDBIter) Key() kv.Key
- func (i *MemDBIter) Next() error
- func (i *MemDBIter) UpdateFlags(ops ...kv.FlagsOp)
- func (i *MemDBIter) Valid() bool
- func (i *MemDBIter) Value() []byte
- type MemKeyHandle
- type Option
- type SnapshotIter
- type Txn
- func (txn *Txn) BatchGet(ctx context.Context, keys []kv.Key) (map[string][]byte, error)
- func (txn *Txn) Commit(_ context.Context) error
- func (txn *Txn) Delete(k kv.Key) error
- func (txn *Txn) Get(ctx context.Context, k kv.Key) ([]byte, error)
- func (txn *Txn) Iter(lowerBound, upperBound kv.Key) (kv.Iterator, error)
- func (txn *Txn) IterReverse(lowerBound, upperBound kv.Key) (kv.Iterator, error)
- func (txn *Txn) Len() int
- func (txn *Txn) Reset()
- func (txn *Txn) Rollback() error
- func (txn *Txn) Set(k kv.Key, v []byte) error
- func (txn *Txn) Size() int
- func (txn *Txn) Snapshot() kv.Snapshot
- func (txn *Txn) StartVer() kv.Version
- func (txn *Txn) String() string
- type UnionIter
- type UnionStore
- func (us *UnionStore) Get(ctx context.Context, k kv.Key) ([]byte, error)
- func (us *UnionStore) HasPresumeKeyNotExists(k []byte) bool
- func (us *UnionStore) Iter(lowerBound, upperBound kv.Key) (kv.Iterator, error)
- func (us *UnionStore) IterReverse(lowerBound, upperBound kv.Key) (kv.Iterator, error)
- func (us *UnionStore) MemBuffer() *MemDB
- func (us *UnionStore) SetEntrySizeLimit(entryLimit, bufferLimit uint64)
- func (us *UnionStore) UnmarkPresumeKeyNotExists(k []byte)
Constants ¶
This section is empty.
Variables ¶
var ( // PrewriteMaxBackoff is max sleep time of the `pre-write` command. PrewriteMaxBackoff = atomic.NewUint64(40000) // CommitMaxBackoff is max sleep time of the 'commit' command CommitMaxBackoff = uint64(40000) )
var (
ManagedLockTTL uint64 = 20000 // 20s
)
Global variable set by config file.
Functions ¶
func BackoffErrReporter ¶
BackoffErrReporter reports backoff error events.
func IsTombstone ¶
IsTombstone returns whether the value is a tombstone.
Types ¶
type BatchBufferGetter ¶
BatchBufferGetter is the interface for BatchGet.
type BufferBatchGetter ¶
type BufferBatchGetter struct {
// contains filtered or unexported fields
}
BufferBatchGetter is the type for BatchGet with MemBuffer.
func NewBufferBatchGetter ¶
func NewBufferBatchGetter(buffer BatchBufferGetter, snapshot kv.BatchGetter) *BufferBatchGetter
NewBufferBatchGetter creates a new BufferBatchGetter.
type KVSnapshot ¶
type KVSnapshot struct {
// contains filtered or unexported fields
}
KVSnapshot represent the MVCC snapshot of the low-level key/value store. All values read from the KVSnapshot will be checked via mvcc.Version. And only the committed key/values can be retrieved or iterated.
func (*KVSnapshot) IterReverse ¶
IterReverse implements the Snapshot interface.
func (*KVSnapshot) StartVer ¶
func (s *KVSnapshot) StartVer() kv.Version
StartVer implements the Snapshot interface.
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 SnapshotIter will iterate from greater key to smaller key. If k is nil, the returned SnapshotIter will be positioned at the last key.
func (*MemDB) IterReverseWithFlags ¶
IterReverseWithFlags returns a reversed MemDBIter.
func (*MemDB) IterWithFlags ¶
IterWithFlags returns a MemDBIter.
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 MemDBIter ¶
type MemDBIter struct {
// contains filtered or unexported fields
}
MemDBIter is an Iterator with KeyFlags related functions.
func (*MemDBIter) Handle ¶
func (i *MemDBIter) Handle() MemKeyHandle
Handle returns MemKeyHandle with the current position.
func (*MemDBIter) UpdateFlags ¶
UpdateFlags updates and apply with flagsOp.
type MemKeyHandle ¶
type MemKeyHandle struct {
// contains filtered or unexported fields
}
MemKeyHandle represents a pointer for key in MemBuffer.
type SnapshotIter ¶
type SnapshotIter struct {
// contains filtered or unexported fields
}
SnapshotIter represents a iterator which provides a consistent view of key/value store.
func (*SnapshotIter) Close ¶
func (i *SnapshotIter) Close()
Close implements the Iterator interface.
func (*SnapshotIter) Key ¶
func (i *SnapshotIter) Key() kv.Key
Key implements the Iterator interface.
func (*SnapshotIter) Next ¶
func (i *SnapshotIter) Next() error
Next implements the Iterator interface.
func (*SnapshotIter) Valid ¶
func (i *SnapshotIter) Valid() bool
Valid implements the Iterator interface.
func (*SnapshotIter) Value ¶
func (i *SnapshotIter) Value() []byte
Value implements the Iterator interface.
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn represents a transaction implemented beyond the low-level key/value storage.
func (*Txn) BatchGet ¶
BatchGet implements the Transaction interface. It gets kv from the memory buffer of statement and transaction, and the kv storage. Do not use len(value) == 0 or value == nil to represent non-exist. If a key doesn't exist, there shouldn't be any corresponding entry in the result map.
func (*Txn) Delete ¶
Delete implements the Transaction interface. It removes the entry for key k from kv store.
func (*Txn) 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 (*Txn) IterReverse ¶
IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.
func (*Txn) Len ¶
Len implements the Transaction interface. It returns the number of entries in the DB.
func (*Txn) Reset ¶
func (txn *Txn) Reset()
Reset implements the Transaction interface. It resets the Transaction to initial states.
func (*Txn) Rollback ¶
Rollback implements the Transaction interface. It undoes the transaction operations to KV store.
func (*Txn) Set ¶
Set implements the Transaction interface. It sets the value for key k as v into kv store. v must NOT be nil or empty, otherwise it returns ErrCannotSetNilValue.
func (*Txn) Size ¶
Size implements the Transaction interface. It returns sum of keys and values length.
type UnionIter ¶
type UnionIter struct {
// contains filtered or unexported fields
}
UnionIter is the SnapshotIter on an UnionStore.
func NewUnionIter ¶
NewUnionIter returns a union SnapshotIter for BufferStore.
func (*UnionIter) Close ¶
func (iter *UnionIter) Close()
Close implements the Iterator Close interface.
type UnionStore ¶
type UnionStore struct {
// contains filtered or unexported fields
}
UnionStore is an in-memory Store which contains a buffer for write and a snapshot for read.
func NewUnionStore ¶
func NewUnionStore(snapshot kv.Snapshot) *UnionStore
NewUnionStore builds a new unionStore.
func (*UnionStore) HasPresumeKeyNotExists ¶
func (us *UnionStore) HasPresumeKeyNotExists(k []byte) bool
HasPresumeKeyNotExists gets the key exist error info for the lazy check.
func (*UnionStore) IterReverse ¶
IterReverse implements the Retriever interface.
func (*UnionStore) MemBuffer ¶
func (us *UnionStore) MemBuffer() *MemDB
MemBuffer return the MemBuffer binding to this unionStore.
func (*UnionStore) SetEntrySizeLimit ¶
func (us *UnionStore) SetEntrySizeLimit(entryLimit, bufferLimit uint64)
SetEntrySizeLimit sets the size limit for each entry and total buffer.
func (*UnionStore) UnmarkPresumeKeyNotExists ¶
func (us *UnionStore) UnmarkPresumeKeyNotExists(k []byte)
UnmarkPresumeKeyNotExists deletes the key exist error info for the lazy check.