db

package
v0.5.0-rc10-hotfix1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: Apache-2.0 Imports: 10 Imported by: 16

Documentation

Index

Constants

View Source
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

View Source
var (
	// ErrNotExist indicates certain item does not exist in Blockchain database
	ErrNotExist = errors.New("not exist in DB")
	// 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")
	// ErrIO indicates the generic error of DB I/O operation
	ErrIO = errors.New("DB I/O operation error")
)

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)
	// 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
	// Digest of the cached batch
	Digest() hash.Hash256
	// contains filtered or unexported methods
}

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.

func NewMemKVStore

func NewMemKVStore() KVStore

NewMemKVStore instantiates an in-memory KV store

func NewOnDiskDB added in v0.4.4

func NewOnDiskDB(cfg config.DB) KVStore

NewOnDiskDB instantiates an on-disk 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()
	// CloneBatch clones the batch
	CloneBatch() KVStoreBatch
	// contains filtered or unexported methods
}

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)

func NewBatch added in v0.4.0

func NewBatch() KVStoreBatch

NewBatch returns a batch

type KVStoreCache added in v0.4.4

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 added in v0.4.4

func NewKVCache() KVStoreCache

NewKVCache returns a KVCache

type KVStoreForTrie added in v0.4.4

type KVStoreForTrie struct {
	// contains filtered or unexported fields
}

KVStoreForTrie defines a kvstore with fixed bucket and cache layer for trie. It may be used in other cases as well

func NewKVStoreForTrie added in v0.4.4

func NewKVStoreForTrie(bucket string, dao KVStore, options ...Option) (*KVStoreForTrie, error)

NewKVStoreForTrie creates a new KVStoreForTrie

func (*KVStoreForTrie) Delete added in v0.4.4

func (s *KVStoreForTrie) Delete(key []byte) error

Delete deletes key

func (*KVStoreForTrie) Flush added in v0.4.4

func (s *KVStoreForTrie) Flush() error

Flush flushs the data in cache layer to db

func (*KVStoreForTrie) Get added in v0.4.4

func (s *KVStoreForTrie) Get(key []byte) ([]byte, error)

Get gets value of key

func (*KVStoreForTrie) Put added in v0.4.4

func (s *KVStoreForTrie) Put(key []byte, value []byte) error

Put puts value for key

func (*KVStoreForTrie) Start added in v0.4.4

func (s *KVStoreForTrie) Start(ctx context.Context) error

Start starts the kv store

func (*KVStoreForTrie) Stop added in v0.4.4

func (s *KVStoreForTrie) Stop(ctx context.Context) error

Stop stops the kv store

type Option added in v0.4.4

type Option func(*KVStoreForTrie) error

Option defines an interface to initialize the kv store

func CachedBatchOption added in v0.4.4

func CachedBatchOption(cb CachedBatch) Option

CachedBatchOption defines a way to set the cache layer for db

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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