iotex-core: github.com/iotexproject/iotex-core/db Index | Files | Directories

package db

import "github.com/iotexproject/iotex-core/db"

Index

Package Files

batch.go db.go db_bolt.go kv_cache.go kvstore4trie.go

Constants

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

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

type CachedBatch Uses

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 Uses

func NewCachedBatch() CachedBatch

NewCachedBatch returns a new cached batch buffer

type KVStore Uses

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 NewBoltDB Uses

func NewBoltDB(cfg config.DB) KVStore

NewBoltDB instantiates an BoltDB with implements KVStore

func NewMemKVStore Uses

func NewMemKVStore() KVStore

NewMemKVStore instantiates an in-memory KV store

type KVStoreBatch Uses

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 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
    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 Uses

func NewKVCache() KVStoreCache

NewKVCache returns a KVCache

type KVStoreForTrie Uses

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 Uses

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

NewKVStoreForTrie creates a new KVStoreForTrie

func (*KVStoreForTrie) Delete Uses

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

Delete deletes key

func (*KVStoreForTrie) Flush Uses

func (s *KVStoreForTrie) Flush() error

Flush flushs the data in cache layer to db

func (*KVStoreForTrie) Get Uses

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

Get gets value of key

func (*KVStoreForTrie) Put Uses

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

Put puts value for key

func (*KVStoreForTrie) Start Uses

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

Start starts the kv store

func (*KVStoreForTrie) Stop Uses

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

Stop stops the kv store

type Option Uses

type Option func(*KVStoreForTrie) error

Option defines an interface to initialize the kv store

func CachedBatchOption Uses

func CachedBatchOption(cb CachedBatch) Option

CachedBatchOption defines a way to set the cache layer for db

Directories

PathSynopsis
sql
trie
trie/triepb

Package db imports 9 packages (graph) and is imported by 9 packages. Updated 2019-08-11. Refresh now. Tools for package owners.