unionstore

package
v2.0.0-...-d47a232 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTombstone

func IsTombstone(val []byte) bool

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 Iterator

type Iterator interface {
	Valid() bool
	Key() []byte
	Value() []byte
	Next() error
	Close()
}

Iterator is the interface for a iterator on KV store.

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) Get

func (us *KVUnionStore) Get(ctx context.Context, k []byte) ([]byte, error)

Get implements the Retriever interface.

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

func (db *MemDB) Cleanup(h int)

Cleanup cleanup the resources referenced by the StagingHandle. If the changes are not published by `Release`, they will be discarded.

func (*MemDB) Delete

func (db *MemDB) Delete(key []byte) error

Delete removes the entry for key k from kv store.

func (*MemDB) DeleteWithFlags

func (db *MemDB) DeleteWithFlags(key []byte, ops ...kv.FlagsOp) error

DeleteWithFlags delete key with the given KeyFlags

func (*MemDB) Dirty

func (db *MemDB) Dirty() bool

Dirty returns whether the root staging buffer is updated.

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

func (db *MemDB) Get(key []byte) ([]byte, error)

Get gets the value for key k from kv store. If corresponding kv pair does not exist, it returns nil and ErrNotExist.

func (*MemDB) GetFlags

func (db *MemDB) GetFlags(key []byte) (kv.KeyFlags, error)

GetFlags returns the latest flags associated with key.

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

func (db *MemDB) InspectStage(handle int, f func([]byte, kv.KeyFlags, []byte))

InspectStage used to inspect the value updates in the given stage.

func (*MemDB) Iter

func (db *MemDB) Iter(k []byte, upperBound []byte) (Iterator, error)

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

func (db *MemDB) IterReverse(k []byte) (Iterator, error)

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) Len

func (db *MemDB) Len() int

Len returns the number of entries in the DB.

func (*MemDB) Mem

func (db *MemDB) Mem() uint64

Mem returns the current memory footprint

func (*MemDB) Release

func (db *MemDB) Release(h int)

Release publish all modifications in the latest staging buffer to upper level.

func (*MemDB) RemoveFromBuffer

func (db *MemDB) RemoveFromBuffer(key []byte)

RemoveFromBuffer removes a record from the mem buffer. It should be only used for test.

func (*MemDB) Reset

func (db *MemDB) Reset()

Reset resets the MemBuffer to initial states.

func (*MemDB) RevertToCheckpoint

func (db *MemDB) RevertToCheckpoint(cp *MemDBCheckpoint)

RevertToCheckpoint reverts the MemDB to the checkpoint.

func (*MemDB) SelectValueHistory

func (db *MemDB) SelectValueHistory(key []byte, predicate func(value []byte) bool) ([]byte, error)

SelectValueHistory select the latest value which makes `predicate` returns true from the modification history.

func (*MemDB) Set

func (db *MemDB) Set(key []byte, value []byte) error

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

func (db *MemDB) SetMemoryFootprintChangeHook(hook func(uint64))

SetMemoryFootprintChangeHook sets the hook function that is triggered when memdb grows.

func (*MemDB) SetWithFlags

func (db *MemDB) SetWithFlags(key []byte, value []byte, ops ...kv.FlagsOp) error

SetWithFlags put key-value into the last active staging buffer with the given KeyFlags.

func (*MemDB) Size

func (db *MemDB) Size() int

Size returns sum of keys and values length.

func (*MemDB) SnapshotGetter

func (db *MemDB) SnapshotGetter() Getter

SnapshotGetter returns a Getter for a snapshot of MemBuffer.

func (*MemDB) SnapshotIter

func (db *MemDB) SnapshotIter(start, end []byte) Iterator

SnapshotIter returns a Iterator for a snapshot of MemBuffer.

func (*MemDB) Staging

func (db *MemDB) Staging() int

Staging create a new staging buffer inside the MemBuffer. Subsequent writes will be temporarily stored in this new staging buffer. When you think all modifications looks good, you can call `Release` to public all of them to the upper level buffer.

func (*MemDB) UpdateFlags

func (db *MemDB) UpdateFlags(key []byte, ops ...kv.FlagsOp)

UpdateFlags update the flags associated with key.

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) Close

func (i *MemdbIterator) Close()

Close closes the current iterator.

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) Key

func (i *MemdbIterator) Key() []byte

Key returns current key.

func (*MemdbIterator) Next

func (i *MemdbIterator) Next() error

Next goes the next position.

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.

func (*MemdbIterator) Value

func (i *MemdbIterator) Value() []byte

Value returns the value.

type UnionIter

type UnionIter struct {
	// contains filtered or unexported fields
}

UnionIter is the iterator on an UnionStore.

func NewUnionIter

func NewUnionIter(dirtyIt Iterator, snapshotIt Iterator, reverse bool) (*UnionIter, error)

NewUnionIter returns a union iterator for BufferStore.

func (*UnionIter) Close

func (iter *UnionIter) Close()

Close implements the Iterator Close interface.

func (*UnionIter) Key

func (iter *UnionIter) Key() []byte

Key implements the Iterator Key interface.

func (*UnionIter) Next

func (iter *UnionIter) Next() error

Next implements the Iterator Next interface.

func (*UnionIter) Valid

func (iter *UnionIter) Valid() bool

Valid implements the Iterator Valid interface.

func (*UnionIter) Value

func (iter *UnionIter) Value() []byte

Value implements the Iterator Value interface. Multi columns

Jump to

Keyboard shortcuts

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