Documentation ¶
Index ¶
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 ( // ErrInvalidDB indicates invalid operation attempted to Blockchain database ErrInvalidDB = errors.New("invalid DB operation") // ErrNotExist indicates certain item does not exist in Blockchain database ErrNotExist = errors.New("not exist in DB") // ErrAlreadyExist indicates certain item already exists in Blockchain database ErrAlreadyExist = errors.New("already exist in DB") )
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) }
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.
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() }
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)