db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

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
	// PutIfNotExists indicate the type of write operation to be PutIfNotExists
	PutIfNotExists int32 = 2
)

Variables

View Source
var (
	// ErrInvalidDB indicates invalid operation attempted to Blockchain database
	ErrInvalidDB = errors.New("invalid DB operation")
	// ErrNotExist indicates certain item does not exist in Blockchain database
	ErrNotExist = errors.New("not exist in DB")
	// ErrAlreadyExist indicates certain item already exists in Blockchain database
	ErrAlreadyExist = errors.New("already exist in DB")
)

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

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
	// Put puts a record only if (namespace, key) doesn't exist, otherwise return ErrAlreadyExist
	PutIfNotExists(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

func NewBoltDB(path string, cfg *config.DB) KVStore

NewBoltDB instantiates a boltdb based KV store

func NewMemKVStore

func NewMemKVStore() KVStore

NewMemKVStore instantiates an in-memory 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{})
	// PutIfNotExists puts a record only if (namespace, key) doesn't exist, otherwise return ErrAlreadyExist
	PutIfNotExists(string, []byte, []byte, string, ...interface{}) error
	// 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()
}

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.PutIfNotExists(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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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