Documentation ¶
Index ¶
- Constants
- Variables
- func IsErrNotFound(err error) bool
- func WalkMemBuffer(memBuf MemBuffer, f func(k key.Key, v []byte) error) error
- type BufferStore
- func (s *BufferStore) Get(k key.Key) ([]byte, error)
- func (s *BufferStore) Iter(k key.Key, upperBound key.Key) (Iterator, error)
- func (s *BufferStore) IterReverse(k key.Key) (Iterator, error)
- func (s *BufferStore) Reset()
- func (s *BufferStore) SaveTo(m Mutator) error
- func (s *BufferStore) SetCap(cap int)
- func (s *BufferStore) WalkBuffer(f func(k key.Key, v []byte) error) error
- type IsoLevel
- type Iterator
- type MemBuffer
- type Mutator
- type Option
- type Options
- type Retriever
- type RetrieverMutator
- type Snapshot
- type UnionIter
- type UnionStore
Constants ¶
const ( PriorityNormal = iota PriorityLow PriorityHigh )
Priority value for transaction priority.
Variables ¶
var ( // ErrNotExist is used when try to get an entry with an unexist key from KV store. ErrNotExist = errors.New("key not exist") // ErrCannotSetNilValue is the error when sets an empty value. ErrCannotSetNilValue = errors.New("can not set nil value") // ErrTxnTooLarge is the error when transaction is too large, lock time reached the maximum value. ErrTxnTooLarge = errors.New("transaction is too large") // ErrEntryTooLarge is the error when a key value entry is too large. ErrEntryTooLarge = errors.New("entry is too large") // ErrKeyExists returns when key is already exist. ErrKeyExists = errors.New("key already exist") // ErrInvalidTxn is the error that using a transaction after calling Commit or Rollback. ErrInvalidTxn = errors.New("invalid transaction") )
Functions ¶
func IsErrNotFound ¶
IsErrNotFound checks if err is a kind of NotFound error.
Types ¶
type BufferStore ¶
type BufferStore struct { MemBuffer // contains filtered or unexported fields }
BufferStore wraps a Retriever for read and a MemBuffer for buffered write. Common usage pattern:
bs := NewBufferStore(r) // use BufferStore to wrap a Retriever // ... // read/write on bs // ... bs.SaveTo(m) // save above operations to a Mutator
func NewBufferStore ¶
func NewBufferStore(r Retriever, conf *config.Txn) *BufferStore
NewBufferStore creates a BufferStore using r for read.
func (*BufferStore) Get ¶
func (s *BufferStore) Get(k key.Key) ([]byte, error)
Get implements the Retriever interface.
func (*BufferStore) IterReverse ¶
func (s *BufferStore) IterReverse(k key.Key) (Iterator, error)
IterReverse implements the Retriever interface.
func (*BufferStore) SaveTo ¶
func (s *BufferStore) SaveTo(m Mutator) error
SaveTo saves all buffered kv pairs into a Mutator.
func (*BufferStore) SetCap ¶
func (s *BufferStore) SetCap(cap int)
SetCap sets the MemBuffer capability.
func (*BufferStore) WalkBuffer ¶
WalkBuffer iterates all buffered kv pairs.
type MemBuffer ¶
type MemBuffer interface { RetrieverMutator // Size returns sum of keys and values length. Size() int // Len returns the number of entries in the DB. Len() int // Reset cleanup the MemBuffer Reset() // SetCap sets the MemBuffer capability, to reduce memory allocations. // Please call it before you use the MemBuffer, otherwise it will not works. SetCap(cap int) }
MemBuffer is an in-memory kv collection, can be used to buffer write operations.
type Mutator ¶
type Mutator interface { // Set sets the value for key k as v into kv store. // v must NOT be nil or empty, otherwise it returns ErrCannotSetNilValue. Set(k key.Key, v []byte) error // Delete removes the entry for key k from kv store. Delete(k key.Key) error }
Mutator is the interface wraps the basic Set and Delete methods.
type Option ¶
type Option int
Option is used for customizing kv store's behaviors during a transaction.
const ( // PresumeKeyNotExists indicates that when dealing with a Get operation but failing to read data from cache, // we presume that the key does not exist in Store. The actual existence will be checked before the // transaction's commit. // This option is an optimization for frequent checks during a transaction, e.g. batch inserts. PresumeKeyNotExists Option = iota + 1 // PresumeKeyNotExistsError is the option key for error. // When PresumeKeyNotExists is set and condition is not match, should throw the error. PresumeKeyNotExistsError // BinlogInfo contains the binlog data and client. BinlogInfo // SchemaChecker is used for checking schema-validity. SchemaChecker // IsolationLevel sets isolation level for current transaction. The default level is SI. IsolationLevel // Priority marks the priority of this transaction. Priority // NotFillCache makes this request do not touch the LRU cache of the underlying storage. NotFillCache // SyncLog decides whether the WAL(write-ahead log) of this request should be synchronized. SyncLog // KeyOnly retrieve only keys, it can be used in scan now. KeyOnly )
Transaction options
type Retriever ¶
type Retriever 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 key.Key) ([]byte, 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. Iter(k key.Key, upperBound key.Key) (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 IterReverse(k key.Key) (Iterator, error) }
Retriever is the interface wraps the basic Get and Seek methods.
type RetrieverMutator ¶
RetrieverMutator is the interface that groups Retriever and Mutator interfaces.
type Snapshot ¶
type Snapshot interface { Retriever // BatchGet gets a batch of values from snapshot. BatchGet(keys []key.Key) (map[string][]byte, error) // SetPriority snapshot set the priority SetPriority(priority int) }
Snapshot defines the interface for the snapshot fetched from KV store.
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.
type UnionStore ¶
type UnionStore interface { MemBuffer // Returns related condition pair LookupConditionPair(k key.Key) *conditionPair // WalkBuffer iterates all buffered kv pairs. WalkBuffer(f func(k key.Key, v []byte) error) error // SetOption sets an option with a value, when val is nil, uses the default // value of this option. SetOption(opt Option, val interface{}) // DelOption deletes an option. DelOption(opt Option) // GetOption gets an option. GetOption(opt Option) interface{} // GetMemBuffer return the MemBuffer binding to this UnionStore. GetMemBuffer() MemBuffer }
UnionStore is a store that wraps a snapshot for read and a BufferStore for buffered write. Also, it provides some transaction related utilities.
func NewUnionStore ¶
func NewUnionStore(conf *config.Txn, snapshot Snapshot) UnionStore
NewUnionStore builds a new UnionStore.