batch

package
v1.4.1-rc0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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() 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, ...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)

func NewBatch

func NewBatch() KVStoreBatch

NewBatch returns a batch

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

func NewKVCache

func NewKVCache() KVStoreCache

NewKVCache returns a KVCache

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

func (wi *WriteInfo) ErrorFormat() string

ErrorFormat returns the error format

func (*WriteInfo) Key

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

Key returns a copy of key

func (*WriteInfo) Namespace

func (wi *WriteInfo) Namespace() string

Namespace returns the namespace of a write info

func (*WriteInfo) Serialize

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

Serialize serializes the write info

func (*WriteInfo) SerializeWithoutWriteType

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

SerializeWithoutWriteType serializes the write info without write type

func (*WriteInfo) Value

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

Value returns a copy of value

func (*WriteInfo) WriteType

func (wi *WriteInfo) WriteType() WriteType

WriteType returns the type of a write info

type WriteInfoFilter

type WriteInfoFilter func(wi *WriteInfo) bool

WriteInfoFilter filters a write

type WriteInfoSerialize

type WriteInfoSerialize func(wi *WriteInfo) []byte

WriteInfoSerialize serializes a write to bytes

type WriteInfoTranslate

type WriteInfoTranslate func(wi *WriteInfo) *WriteInfo

WriteInfoTranslate translates a write info

type WriteType

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL