Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // 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") // ErrNotExist indicates certain item does not exist in Blockchain database ErrNotExist = errors.New("not exist in DB") // ErrOutOfBound indicates an out of bound error ErrOutOfBound = errors.New("out of bound") // ErrUnexpectedType indicates an invalid casting ErrUnexpectedType = errors.New("unexpected type") )
Functions ¶
This section is empty.
Types ¶
type CachedBatch ¶
type CachedBatch interface { KVStoreBatch Snapshot // 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 ¶
func NewCachedBatch() CachedBatch
NewCachedBatch returns a new cached batch buffer
type KVStoreBatch ¶
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) // Delete deletes a record by (namespace, key) Delete(string, []byte, string) // Size returns the size of batch Size() int // Entry returns the entry at the index Entry(int) (*WriteInfo, error) // SerializeQueue serialize the writes in queue SerializeQueue(WriteInfoSerialize, WriteInfoFilter) []byte // Clear clears entries staged in batch Clear() // Translate clones the batch Translate(WriteInfoTranslate) KVStoreBatch // CheckFillPercent CheckFillPercent(string) (float64, bool) // AddFillPercent AddFillPercent(string, float64) }
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 WriteBatch() to persist to underlying DB KVStore.WriteBatch(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 ¶
type KVStoreCache interface { // Read retrieves a record Read(*kvCacheKey) ([]byte, error) // Write puts a record into cache Write(*kvCacheKey, []byte) // WriteIfNotExist puts a record into cache only if it doesn't exist, otherwise return ErrAlreadyExist WriteIfNotExist(*kvCacheKey, []byte) error // Evict deletes a record from cache Evict(*kvCacheKey) // Clear clear the cache Clear() // Append appends caches Append(...KVStoreCache) error }
KVStoreCache is a local cache of batched <k, v> for fast query
type Snapshot ¶
type Snapshot interface { // Snapshot takes a snapshot of current cached batch Snapshot() int // RevertSnapshot sets the cached batch to the state at the given snapshot RevertSnapshot(int) error // ResetSnapshots() clears all snapshots ResetSnapshots() }
Snapshot defines an interface which supports snapshot related functions
type WriteInfo ¶
type WriteInfo struct {
// contains filtered or unexported fields
}
WriteInfo is the struct to store Put/Delete operation info
func NewWriteInfo ¶
func NewWriteInfo( writeType WriteType, namespace string, key, value []byte, errorMessage string, ) *WriteInfo
NewWriteInfo creates a new write info
func (*WriteInfo) SerializeWithoutWriteType ¶
SerializeWithoutWriteType serializes the write info without write type
type WriteInfoFilter ¶
WriteInfoFilter filters a write
type WriteInfoSerialize ¶
WriteInfoSerialize serializes a write to bytes
type WriteInfoTranslate ¶
WriteInfoTranslate translates a write info