statemgmt

package
v0.6.1-preview Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIteratorContains

func AssertIteratorContains(t *testing.T, itr RangeScanIterator, expected map[string][]byte)

AssertIteratorContains - tests wether the iterator (itr) contains expected results (provided in map)

func ConstructCompositeKey

func ConstructCompositeKey(chaincodeID string, key string) []byte

ConstructCompositeKey returns a []byte that uniquely represents a given chaincodeID and key. This assumes that chaincodeID does not contain a 0x00 byte, but the key may TODO:enforce this restriction on chaincodeID or use length prefixing here instead of delimiter

func Copy

func Copy(src []byte) []byte

Copy returns a copy of given bytes

func DecodeCompositeKey

func DecodeCompositeKey(compositeKey []byte) (string, string)

DecodeCompositeKey decodes the compositeKey constructed by ConstructCompositeKey method back to the original chaincodeID and key form

Types

type ChaincodeStateDelta

type ChaincodeStateDelta struct {
	ChaincodeID string
	UpdatedKVs  map[string]*UpdatedValue
}

ChaincodeStateDelta maintains state for a chaincode

type HashableState

type HashableState interface {

	// Initialize this gives a chance to initialize. For instance, state implementation can load some data from DB
	Initialize(configs map[string]interface{}) error

	// Get get the value from DB
	Get(chaincodeID string, key string) ([]byte, error)

	// PrepareWorkingSet passes a stateDelta that captures the changes that needs to be applied to the state
	PrepareWorkingSet(stateDelta *StateDelta) error

	// ComputeCryptoHash state implementation to compute crypto-hash of state
	// assuming the stateDelta (passed in PrepareWorkingSet method) is to be applied
	ComputeCryptoHash() ([]byte, error)

	// AddChangesForPersistence state implementation to add all the key-value pair that it needs
	// to persist for committing the  stateDelta (passed in PrepareWorkingSet method) to DB.
	// In addition to the information in the StateDelta, the implementation may also want to
	// persist intermediate results for faster crypto-hash computation
	AddChangesForPersistence(writeBatch *gorocksdb.WriteBatch) error

	// ClearWorkingSet state implementation may clear any data structures that it may have constructed
	// for computing cryptoHash and persisting the changes for the stateDelta (passed in PrepareWorkingSet method)
	ClearWorkingSet(changesPersisted bool)

	// GetStateSnapshotIterator state implementation to provide an iterator that is supposed to give
	// All the key-value of global state. A particular implementation may need to remove additional information
	// that the implementation keeps for faster crypto-hash computation. For instance, filter a few of the
	// key-values or remove some data from particular key-values.
	GetStateSnapshotIterator(snapshot *gorocksdb.Snapshot) (StateSnapshotIterator, error)

	// GetRangeScanIterator - state implementation to provide an iterator that is supposed to give
	// All the key-values for a given chaincodeID such that a return key should be lexically greater than or
	// equal to startKey and less than or equal to endKey. If the value for startKey parameter is an empty string
	// startKey is assumed to be the smallest key available in the db for the chaincodeID. Similarly, an empty string
	// for endKey parameter assumes the endKey to be the greatest key available in the db for the chaincodeID
	GetRangeScanIterator(chaincodeID string, startKey string, endKey string) (RangeScanIterator, error)

	// PerfHintKeyChanged state implementation may be provided with some hints before (e.g., during tx execution)
	// the StateDelta is prepared and passed in PrepareWorkingSet method.
	// A state implementation may use this hint for prefetching relevant data so as if this could improve
	// the performance of ComputeCryptoHash method (when gets called at a later time)
	PerfHintKeyChanged(chaincodeID string, key string)
}

HashableState - Interface that is be implemented by state management Different state management implementation can be effiecient for computing crypto-hash for state under different workload conditions.

type RangeScanIterator

type RangeScanIterator interface {

	// Next moves to next key-value. Returns true if next key-value exists
	Next() bool

	// GetKeyValue returns next key-value
	GetKeyValue() (string, []byte)

	// Close releases resources occupied by the iterator
	Close()
}

RangeScanIterator - is to be implemented by the return value of GetRangeScanIterator method in the implementation of HashableState interface

type StateDelta

type StateDelta struct {
	ChaincodeStateDeltas map[string]*ChaincodeStateDelta
	// RollBackwards allows one to contol whether this delta will roll the state
	// forwards or backwards.
	RollBackwards bool
}

StateDelta holds the changes to existing state. This struct is used for holding the uncommitted changes during execution of a tx-batch Also, to be used for transferring the state to another peer in chunks

func ConstructRandomStateDelta

func ConstructRandomStateDelta(
	t testing.TB,
	chaincodeIDPrefix string,
	numChaincodes int,
	maxKeySuffix int,
	numKeysToInsert int,
	kvSize int) *StateDelta

ConstructRandomStateDelta creates a random state delta for testing

func NewStateDelta

func NewStateDelta() *StateDelta

NewStateDelta constructs an empty StateDelta struct

func (*StateDelta) ApplyChanges

func (stateDelta *StateDelta) ApplyChanges(anotherStateDelta *StateDelta)

ApplyChanges merges another delta - if a key is present in both, the value of the existing key is overwritten

func (*StateDelta) ComputeCryptoHash

func (stateDelta *StateDelta) ComputeCryptoHash() []byte

ComputeCryptoHash computes crypto-hash for the data held returns nil if no data is present

func (*StateDelta) Delete

func (stateDelta *StateDelta) Delete(chaincodeID string, key string, previousValue []byte)

Delete deletes a key from the state

func (*StateDelta) Get

func (stateDelta *StateDelta) Get(chaincodeID string, key string) *UpdatedValue

Get get the state from delta if exists

func (*StateDelta) GetUpdatedChaincodeIds

func (stateDelta *StateDelta) GetUpdatedChaincodeIds(sorted bool) []string

GetUpdatedChaincodeIds return the chaincodeIDs that are prepsent in the delta If sorted is true, the method return chaincodeIDs in lexicographical sorted order

func (*StateDelta) GetUpdates

func (stateDelta *StateDelta) GetUpdates(chaincodeID string) map[string]*UpdatedValue

GetUpdates returns changes associated with given chaincodeId

func (*StateDelta) IsEmpty

func (stateDelta *StateDelta) IsEmpty() bool

IsEmpty checks whether StateDelta contains any data

func (*StateDelta) IsUpdatedValueSet

func (stateDelta *StateDelta) IsUpdatedValueSet(chaincodeID, key string) bool

IsUpdatedValueSet returns true if a update value is already set for the given chaincode ID and key.

func (*StateDelta) Marshal

func (stateDelta *StateDelta) Marshal() (b []byte)

Marshal serializes the StateDelta

func (*StateDelta) Set

func (stateDelta *StateDelta) Set(chaincodeID string, key string, value, previousValue []byte)

Set sets state value for a key

func (*StateDelta) Unmarshal

func (stateDelta *StateDelta) Unmarshal(bytes []byte) error

Unmarshal deserializes StateDelta

type StateDeltaIterator

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

StateDeltaIterator - An iterator implementation over state-delta

func NewStateDeltaRangeScanIterator

func NewStateDeltaRangeScanIterator(delta *StateDelta, chaincodeID string, startKey string, endKey string) *StateDeltaIterator

NewStateDeltaRangeScanIterator - return an iterator for performing a range scan over a state-delta object

func (*StateDeltaIterator) Close

func (itr *StateDeltaIterator) Close()

Close - see interface 'RangeScanIterator' for details

func (*StateDeltaIterator) ContainsKey

func (itr *StateDeltaIterator) ContainsKey(key string) bool

ContainsKey - checks wether the given key is present in the state-delta

func (*StateDeltaIterator) GetKeyValue

func (itr *StateDeltaIterator) GetKeyValue() (string, []byte)

GetKeyValue - see interface 'RangeScanIterator' for details

func (*StateDeltaIterator) Next

func (itr *StateDeltaIterator) Next() bool

Next - see interface 'RangeScanIterator' for details

type StateSnapshotIterator

type StateSnapshotIterator interface {

	// Next moves to next key-value. Returns true if next key-value exists
	Next() bool

	// GetRawKeyValue returns next key-value
	GetRawKeyValue() ([]byte, []byte)

	// Close releases resources occupied by the iterator
	Close()
}

StateSnapshotIterator An interface that is to be implemented by the return value of GetStateSnapshotIterator method in the implementation of HashableState interface

type UpdatedValue

type UpdatedValue struct {
	Value         []byte
	PreviousValue []byte
}

UpdatedValue holds the value for a key

func (*UpdatedValue) GetPreviousValue

func (updatedValue *UpdatedValue) GetPreviousValue() []byte

GetPreviousValue returns the previous value

func (*UpdatedValue) GetValue

func (updatedValue *UpdatedValue) GetValue() []byte

GetValue returns the value

func (*UpdatedValue) IsDeleted

func (updatedValue *UpdatedValue) IsDeleted() bool

IsDeleted checks whether the key was deleted

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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