Documentation
¶
Index ¶
- Variables
- type CachedBatch
- type CachedBatchOption
- type KVStoreBatch
- type KVStoreCache
- type WriteInfo
- func (wi *WriteInfo) ErrorArgs() interface{}
- func (wi *WriteInfo) ErrorFormat() string
- func (wi *WriteInfo) Key() []byte
- func (wi *WriteInfo) Namespace() string
- func (wi *WriteInfo) Serialize() []byte
- func (wi *WriteInfo) SerializeWithoutWriteType() []byte
- func (wi *WriteInfo) Value() []byte
- func (wi *WriteInfo) WriteType() WriteType
- type WriteInfoFilter
- type WriteInfoSerialize
- type WriteInfoTranslate
- type WriteType
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") )
Functions ¶
This section is empty.
Types ¶
type CachedBatch ¶
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
}
CachedBatch derives from Batch interface A local cache is added to provide fast retrieval of pending Put/Delete entries
func NewCachedBatch ¶
func NewCachedBatch(opts ...CachedBatchOption) CachedBatch
NewCachedBatch returns a new cached batch buffer
type CachedBatchOption ¶ added in v1.7.0
type CachedBatchOption func(*cachedBatch)
CachedBatchOption is option for cached batch
func SafeRevertOption ¶ added in v1.7.0
func SafeRevertOption() CachedBatchOption
SafeRevertOption is safe revert option
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, ...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)
// 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(hash160 hash.Hash160) ([]byte, error)
// Write puts a record into cache
Write(hash.Hash160, []byte)
// WriteIfNotExist puts a record into cache only if it doesn't exist, otherwise return ErrAlreadyExist
WriteIfNotExist(hash.Hash160, []byte) error
// Evict deletes a record from cache
Evict(hash.Hash160)
// Clear clear the cache
Clear()
// Clone clones the cache
Clone() KVStoreCache
}
KVStoreCache is a local cache of batched <k, v> for fast query
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, errorFormat string, errorArgs interface{}, ) *WriteInfo
NewWriteInfo creates a new write info
func (*WriteInfo) ErrorArgs ¶
func (wi *WriteInfo) ErrorArgs() interface{}
ErrorArgs returns the error args
func (*WriteInfo) ErrorFormat ¶
ErrorFormat returns the error format
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