kv

package
v0.0.0-...-6c7ef32 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 16 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 DecodeKey

func DecodeKey(k []byte) []byte

DecodeKey removes the prefixed keyPrefix.

func DecodeValue

func DecodeValue(data []byte) ([]interface{}, error)

DecodeValue decodes values after it is fetched from the KV store.

func EncodeKey

func EncodeKey(k []byte) []byte

EncodeKey appends the k behind keyPrefix.

func EncodeValue

func EncodeValue(values ...interface{}) ([]byte, error)

EncodeValue encodes values before it is stored to the KV store.

func IsErrNotFound

func IsErrNotFound(err error) bool

IsErrNotFound checks if err is a kind of NotFound error.

func IsRetryableError

func IsRetryableError(err error) bool

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 FnKeyCmp

type FnKeyCmp func(key []byte) bool

FnKeyCmp is the function for iterator the keys

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

func NewKVIndex(indexPrefix, indexName string, unique bool) Index

NewKVIndex builds a new kvIndex object.

type IndexIter

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

IndexIter is for KV store index iterator.

func (*IndexIter) Close

func (c *IndexIter) Close()

Close does the clean up works when KV store index iterator is closed.

func (*IndexIter) Next

func (c *IndexIter) Next() (k []interface{}, h int64, err error)

Next returns current key and moves iterator to the next step.

type IndexIterator

type IndexIterator interface {
	Next() (k []interface{}, h int64, err error)
	Close()
}

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.

func NextUntil

func NextUntil(it Iterator, fn FnKeyCmp) (Iterator, error)

NextUntil applies FnKeyCmp to each entry of the iterator until meets some condition. It will stop when fn returns true, or iterator is invalid or occur error

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.

func (*UnionIter) Key

func (iter *UnionIter) Key() string

Key implements the Iterator Key interface.

func (*UnionIter) Next

func (iter *UnionIter) Next(f FnKeyCmp) (Iterator, 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

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.

func (*UnionStore) Set

func (us *UnionStore) Set(key []byte, value []byte) error

Set implements the Store Set interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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