Documentation ¶
Index ¶
- Variables
- func DecodeKey(k []byte) []byte
- func DecodeValue(data []byte) ([]interface{}, error)
- func EncodeKey(k []byte) []byte
- func EncodeValue(values ...interface{}) ([]byte, error)
- func IsErrNotFound(err error) bool
- func IsRetryableError(err error) bool
- func RunInNewTxn(store Storage, retryable bool, f func(txn Transaction) error) error
- type ConditionValue
- type DecodeFn
- type Driver
- type EncodeFn
- type FnKeyCmp
- type Index
- type IndexIter
- type IndexIterator
- type Iterator
- type SetCondition
- type Snapshot
- type Storage
- type Transaction
- type UnionIter
- type UnionStore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is used when close an already closed txn. ErrClosed = errors.New("Error: Transaction already closed") // ErrNotExist is used when try to get an entry with an unexist key from KV store. ErrNotExist = errors.New("Error: key not exist") // ErrConditionNotMatch is used when condition is not met. ErrConditionNotMatch = errors.New("Error: Condition not match") // ErrLockConflict is used when try to lock an already locked key. ErrLockConflict = errors.New("Error: Lock conflict") )
Functions ¶
func DecodeValue ¶
DecodeValue decodes values after it is fetched from the KV store.
func EncodeValue ¶
EncodeValue encodes values before it is stored to the KV store.
func IsErrNotFound ¶
IsErrNotFound checks if err is a kind of NotFound error.
func IsRetryableError ¶
IsRetryableError check if the err is not a fatal error and the under going operation is worth to retried.
func RunInNewTxn ¶
func RunInNewTxn(store Storage, retryable bool, f func(txn Transaction) error) error
RunInNewTxn will run the f in a new transaction evnironment.
Types ¶
type ConditionValue ¶
type ConditionValue struct { OriginValue []byte Condition SetCondition }
ConditionValue is a data structure used to store current stored data and data verification condition.
func MakeCondition ¶
func MakeCondition(originValue []byte) *ConditionValue
MakeCondition builds a new ConditionValue.
type DecodeFn ¶
type DecodeFn func(raw interface{}) (interface{}, error)
DecodeFn is a function that decode data after fetch from store.
type Driver ¶
type Driver interface { // Open returns a new Storage. // The schema is the string for storage specific format. Open(schema string) (Storage, error) }
Driver is the interface that must be implemented by a kv storage.
type EncodeFn ¶
type EncodeFn func(raw interface{}) (interface{}, error)
EncodeFn is a function that encode data before put into store
type Index ¶
type Index interface { Create(txn Transaction, indexedValues []interface{}, h int64) error // supports insert into statement Delete(txn Transaction, indexedValues []interface{}, h int64) error // supports delete from statement Drop(txn Transaction) error // supports drop table, drop index statements Seek(txn Transaction, indexedValues []interface{}) (iter IndexIterator, hit bool, err error) // supports where clause SeekFirst(txn Transaction) (iter IndexIterator, err error) // supports aggregate min / ascending order by }
Index is the interface for index data on KV store.
func NewKVIndex ¶
NewKVIndex builds a new kvIndex object.
type IndexIter ¶
type IndexIter struct {
// contains filtered or unexported fields
}
IndexIter is for KV store index iterator.
type IndexIterator ¶
IndexIterator is the interface for iterator of index data on KV store.
type Iterator ¶
type Iterator interface { Next(FnKeyCmp) (Iterator, error) Value() []byte Key() string Valid() bool Close() }
Iterator is the interface for a interator on KV store.
type SetCondition ¶
type SetCondition int
SetCondition is the type for condition consts.
const ( // ConditionIfNotExist means the condition is not exist. ConditionIfNotExist SetCondition = iota + 1 // ConditionIfEqual means the condition is equals. ConditionIfEqual // ConditionForceSet means the condition is force set. ConditionForceSet )
type Snapshot ¶
type Snapshot interface { // Get gets the value for key k from snapshot. Get(k []byte) ([]byte, error) // NewIterator gets a new iterator on the snapshot. NewIterator(param interface{}) Iterator // Release releases the snapshot to store. Release() }
Snapshot defines the interface for the snapshot fetched from KV store.
type Storage ¶
type Storage interface { // Begin transaction Begin() (Transaction, error) // Close store Close() error // Storage's unique ID UUID() string }
Storage defines the interface for storage. Isolation should be at least SI(SNAPSHOT ISOLATION)
type Transaction ¶
type Transaction interface { // Get gets the value for key k from KV store. Get(k []byte) ([]byte, error) // Set sets the value for key k as v into KV store. Set(k []byte, v []byte) error // Seek searches for the entry with key k in KV store. Seek(k []byte, fnKeyCmp func(key []byte) bool) (Iterator, error) // Inc increases the value for key k in KV store by step. Inc(k []byte, step int64) (int64, error) // Deletes removes the entry for key k from KV store. Delete(k []byte) error // Commit commites the transaction operations to KV store. Commit() error // Rollback undoes the transaction operations to KV store. Rollback() error // String implements Stringer.String() interface. String() string // LockKeys tries to lock the entries with the keys in KV store. LockKeys(keys ...[]byte) error }
Transaction defines the interface for operations inside a Transaction. This is not thread safe.
type UnionIter ¶
type UnionIter struct {
// contains filtered or unexported fields
}
UnionIter is the iterator on an UnionStore.
func (*UnionIter) Close ¶
func (iter *UnionIter) Close()
Close implements the Iterator Close interface.
type UnionStore ¶
type UnionStore struct { Dirty *memdb.DB // updates are buffered in memory Snapshot Snapshot // for read }
UnionStore is a implement of Store which contains a buffer for update.
func NewUnionStore ¶
func NewUnionStore(snapshot Snapshot) (UnionStore, error)
NewUnionStore builds a new UnionStore.
func (*UnionStore) Close ¶
func (us *UnionStore) Close() error
Close implements the Store Close interface.
func (*UnionStore) Delete ¶
func (us *UnionStore) Delete(k []byte) error
Delete implements the Store Delete interface.
func (*UnionStore) Get ¶
func (us *UnionStore) Get(key []byte) (value []byte, err error)
Get implements the Store Get interface.
func (*UnionStore) Seek ¶
func (us *UnionStore) Seek(key []byte, txn Transaction) (Iterator, error)
Seek implements the Snapshot Seek interface.