Documentation ¶
Index ¶
- Constants
- Variables
- type CachedBatch
- type KVStore
- type KVStoreBatch
- type KVStoreCache
- type KVStoreForTrie
- func (s *KVStoreForTrie) Delete(key []byte) error
- func (s *KVStoreForTrie) Flush() error
- func (s *KVStoreForTrie) Get(key []byte) ([]byte, error)
- func (s *KVStoreForTrie) Put(key []byte, value []byte) error
- func (s *KVStoreForTrie) Start(ctx context.Context) error
- func (s *KVStoreForTrie) Stop(ctx context.Context) error
- type Option
Constants ¶
const ( // Put indicate the type of write operation to be Put Put int32 = iota // Delete indicate the type of write operation to be Delete Delete int32 = 1 )
Variables ¶
var ( // ErrNotExist indicates certain item does not exist in Blockchain database ErrNotExist = errors.New("not exist in DB") // ErrAlreadyDeleted indicates the key has been deleted ErrAlreadyDeleted = errors.New("already deleted from DB") // ErrAlreadyExist indicates certain item already exists in Blockchain database ErrAlreadyExist = errors.New("already exist in DB") // ErrIO indicates the generic error of DB I/O operation ErrIO = errors.New("DB I/O operation error") )
Functions ¶
This section is empty.
Types ¶
type CachedBatch ¶ added in v0.4.0
type CachedBatch interface { KVStoreBatch // Get gets a record by (namespace, key) Get(string, []byte) ([]byte, error) // Snapshot takes a snapshot of current cached batch Snapshot() int // Revert sets the cached batch to the state at the given snapshot Revert(int) error // Digest of the cached batch Digest() hash.Hash32B // contains filtered or unexported methods }
CachedBatch derives from Batch interface A local cache is added to provide fast retrieval of pending Put/Delete entries
func NewCachedBatch ¶ added in v0.4.0
func NewCachedBatch() CachedBatch
NewCachedBatch returns a new cached batch buffer
type KVStore ¶
type KVStore interface { lifecycle.StartStopper // Put insert or update a record identified by (namespace, key) Put(string, []byte, []byte) error // Get gets a record by (namespace, key) Get(string, []byte) ([]byte, error) // Delete deletes a record by (namespace, key) Delete(string, []byte) error // Commit commits a batch Commit(KVStoreBatch) error }
KVStore is the interface of KV store.
func NewOnDiskDB ¶ added in v0.4.4
NewOnDiskDB instantiates an on-disk KV store
type KVStoreBatch ¶ added in v0.3.0
type KVStoreBatch interface { // Lock locks the batch Lock() // Unlock unlocks the batch Unlock() // ClearAndUnlock clears the write queue and unlocks the batch ClearAndUnlock() // Put insert or update a record identified by (namespace, key) Put(string, []byte, []byte, string, ...interface{}) // Delete deletes a record by (namespace, key) Delete(string, []byte, string, ...interface{}) // Size returns the size of batch Size() int // Entry returns the entry at the index Entry(int) (*writeInfo, error) // Clear clears entries staged in batch Clear() // CloneBatch clones the batch CloneBatch() KVStoreBatch // contains filtered or unexported methods }
KVStoreBatch defines a batch buffer interface that stages Put/Delete entries in sequential order To use it, first start a new batch b := NewBatch() and keep batching Put/Delete operation into it b.Put(bucket, k, v) b.Delete(bucket, k, v) once it's done, call KVStore interface's Commit() to persist to underlying DB KVStore.Commit(b) if commit succeeds, the batch is cleared otherwise the batch is kept intact (so batch user can figure out what’s wrong and attempt re-commit later)
type KVStoreCache ¶ added in v0.4.4
type KVStoreCache interface { // Read retrieves a record Read(hash.CacheHash) ([]byte, error) // Write puts a record into cache Write(hash.CacheHash, []byte) // WriteIfNotExist puts a record into cache only if it doesn't exist, otherwise return ErrAlreadyExist WriteIfNotExist(hash.CacheHash, []byte) error // Evict deletes a record from cache Evict(hash.CacheHash) // Clear clear the cache Clear() // Clone clones the cache Clone() KVStoreCache }
KVStoreCache is a local cache of batched <k, v> for fast query
type KVStoreForTrie ¶ added in v0.4.4
type KVStoreForTrie struct {
// contains filtered or unexported fields
}
KVStoreForTrie defines a kvstore with fixed bucket and cache layer for trie. It may be used in other cases as well
func NewKVStoreForTrie ¶ added in v0.4.4
func NewKVStoreForTrie(bucket string, dao KVStore, options ...Option) (*KVStoreForTrie, error)
NewKVStoreForTrie creates a new KVStoreForTrie
func (*KVStoreForTrie) Delete ¶ added in v0.4.4
func (s *KVStoreForTrie) Delete(key []byte) error
Delete deletes key
func (*KVStoreForTrie) Flush ¶ added in v0.4.4
func (s *KVStoreForTrie) Flush() error
Flush flushs the data in cache layer to db
func (*KVStoreForTrie) Get ¶ added in v0.4.4
func (s *KVStoreForTrie) Get(key []byte) ([]byte, error)
Get gets value of key
func (*KVStoreForTrie) Put ¶ added in v0.4.4
func (s *KVStoreForTrie) Put(key []byte, value []byte) error
Put puts value for key
type Option ¶ added in v0.4.4
type Option func(*KVStoreForTrie) error
Option defines an interface to initialize the kv store
func CachedBatchOption ¶ added in v0.4.4
func CachedBatchOption(cb CachedBatch) Option
CachedBatchOption defines a way to set the cache layer for db