statedb

package
v1.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeValue

func DecodeValue(encodedValue []byte) ([]byte, *version.Height)

DecodeValue separates the version and value from a binary value

func EncodeValue

func EncodeValue(value []byte, version *version.Height) []byte

EncodeValue appends the value to the version, allows storage of version and value in binary form

Types

type CompositeKey

type CompositeKey struct {
	Namespace string
	Key       string
}

CompositeKey encloses Namespace and Key components

type QueryResult

type QueryResult interface{}

QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries

type ResultsIterator

type ResultsIterator interface {
	Next() (QueryResult, error)
	Close()
}

ResultsIterator hepls in iterates over query results

type UpdateBatch

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

UpdateBatch encloses the details of multiple `updates`

func NewUpdateBatch

func NewUpdateBatch() *UpdateBatch

NewUpdateBatch constructs an instance of a Batch

func (*UpdateBatch) Delete

func (batch *UpdateBatch) Delete(ns string, key string, version *version.Height)

Delete deletes a Key and associated value

func (*UpdateBatch) Exists

func (batch *UpdateBatch) Exists(ns string, key string) bool

Exists checks whether the given key exists in the batch

func (*UpdateBatch) Get

func (batch *UpdateBatch) Get(ns string, key string) *VersionedValue

Get returns the VersionedValue for the given namespace and key

func (*UpdateBatch) GetRangeScanIterator

func (batch *UpdateBatch) GetRangeScanIterator(ns string, startKey string, endKey string) ResultsIterator

GetRangeScanIterator returns an iterator that iterates over keys of a specific namespace in sorted order In other word this gives the same functionality over the contents in the `UpdateBatch` as `VersionedDB.GetStateRangeScanIterator()` method gives over the contents in the statedb This function can be used for querying the contents in the updateBatch before they are committed to the statedb. For instance, a validator implementation can used this to verify the validity of a range query of a transaction where the UpdateBatch represents the union of the modifications performed by the preceding valid transactions in the same block (Assuming Group commit approach where we commit all the updates caused by a block together).

func (*UpdateBatch) GetUpdatedNamespaces

func (batch *UpdateBatch) GetUpdatedNamespaces() []string

GetUpdatedNamespaces returns the names of the namespaces that are updated

func (*UpdateBatch) GetUpdates

func (batch *UpdateBatch) GetUpdates(ns string) map[string]*VersionedValue

GetUpdates returns all the updates for a namespace

func (*UpdateBatch) Put

func (batch *UpdateBatch) Put(ns string, key string, value []byte, version *version.Height)

Put adds a VersionedKV

type VersionedDB

type VersionedDB interface {
	// GetState gets the value for given namespace and key. For a chaincode, the namespace corresponds to the chaincodeId
	GetState(namespace string, key string) (*VersionedValue, error)
	// GetStateMultipleKeys gets the values for multiple keys in a single call
	GetStateMultipleKeys(namespace string, keys []string) ([]*VersionedValue, error)
	// GetStateRangeScanIterator returns an iterator that contains all the key-values between given key ranges.
	// startKey is inclusive
	// endKey is exclusive
	// The returned ResultsIterator contains results of type *VersionedKV
	GetStateRangeScanIterator(namespace string, startKey string, endKey string) (ResultsIterator, error)
	// ExecuteQuery executes the given query and returns an iterator that contains results of type *VersionedKV.
	ExecuteQuery(namespace, query string) (ResultsIterator, error)
	// ApplyUpdates applies the batch to the underlying db.
	// height is the height of the highest transaction in the Batch that
	// a state db implementation is expected to ues as a save point
	ApplyUpdates(batch *UpdateBatch, height *version.Height) error
	// GetLatestSavePoint returns the height of the highest transaction upto which
	// the state db is consistent
	GetLatestSavePoint() (*version.Height, error)
	// ValidateKey tests whether the key is supported by the db implementation.
	// For instance, leveldb supports any bytes for the key while the couchdb supports only valid utf-8 string
	ValidateKey(key string) error
	// Open opens the db
	Open() error
	// Close closes the db
	Close()
}

VersionedDB lists methods that a db is supposed to implement

type VersionedDBProvider

type VersionedDBProvider interface {
	// GetDBHandle returns a handle to a VersionedDB
	GetDBHandle(id string) (VersionedDB, error)
	// Close closes all the VersionedDB instances and releases any resources held by VersionedDBProvider
	Close()
}

VersionedDBProvider provides an instance of an versioned DB

type VersionedKV

type VersionedKV struct {
	CompositeKey
	VersionedValue
}

VersionedKV encloses key and corresponding VersionedValue

type VersionedValue

type VersionedValue struct {
	Value   []byte
	Version *version.Height
}

VersionedValue encloses value and corresponding version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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