iotex-core: Index | Files

package batch

import ""


Package Files

batch.go batch_impl.go kv_cache.go writeinfo.go


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")

type CachedBatch Uses

type CachedBatch interface {
    // 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 Uses

func NewCachedBatch() CachedBatch

NewCachedBatch returns a new cached batch buffer

type KVStoreBatch Uses

type KVStoreBatch interface {
    // Lock locks the batch
    // Unlock unlocks the batch
    // ClearAndUnlock clears the write queue and unlocks the batch
    // 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
    // Translate clones the batch
    Translate(WriteInfoTranslate) KVStoreBatch

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)

func NewBatch Uses

func NewBatch() KVStoreBatch

NewBatch returns a batch

type KVStoreCache Uses

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
    // Clear clear the cache
    // Clone clones the cache
    Clone() KVStoreCache

KVStoreCache is a local cache of batched <k, v> for fast query

func NewKVCache Uses

func NewKVCache() KVStoreCache

NewKVCache returns a KVCache

type WriteInfo Uses

type WriteInfo struct {
    // contains filtered or unexported fields

WriteInfo is the struct to store Put/Delete operation info

func NewWriteInfo Uses

func NewWriteInfo(
    writeType WriteType,
    namespace string,
    value []byte,
    errorFormat string,
    errorArgs interface{},
) *WriteInfo

NewWriteInfo creates a new write info

func (*WriteInfo) ErrorArgs Uses

func (wi *WriteInfo) ErrorArgs() interface{}

ErrorArgs returns the error args

func (*WriteInfo) ErrorFormat Uses

func (wi *WriteInfo) ErrorFormat() string

ErrorFormat returns the error format

func (*WriteInfo) Key Uses

func (wi *WriteInfo) Key() []byte

Key returns a copy of key

func (*WriteInfo) Namespace Uses

func (wi *WriteInfo) Namespace() string

Namespace returns the namespace of a write info

func (*WriteInfo) Serialize Uses

func (wi *WriteInfo) Serialize() []byte

Serialize serializes the write info

func (*WriteInfo) SerializeWithoutWriteType Uses

func (wi *WriteInfo) SerializeWithoutWriteType() []byte

SerializeWithoutWriteType serializes the write info without write type

func (*WriteInfo) Value Uses

func (wi *WriteInfo) Value() []byte

Value returns a copy of value

func (*WriteInfo) WriteType Uses

func (wi *WriteInfo) WriteType() WriteType

WriteType returns the type of a write info

type WriteInfoFilter Uses

type WriteInfoFilter func(wi *WriteInfo) bool

WriteInfoFilter filters a write

type WriteInfoSerialize Uses

type WriteInfoSerialize func(wi *WriteInfo) []byte

WriteInfoSerialize serializes a write to bytes

type WriteInfoTranslate Uses

type WriteInfoTranslate func(wi *WriteInfo) *WriteInfo

WriteInfoTranslate translates a write info

type WriteType Uses

type WriteType uint8

WriteType is the type of write

const (
    // Put indicate the type of write operation to be Put
    Put WriteType = iota
    // Delete indicate the type of write operation to be Delete

Package batch imports 4 packages (graph) and is imported by 6 packages. Updated 2020-04-02. Refresh now. Tools for package owners.