state

package
v0.0.0-...-667e438 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() *stateConfig

func NewStateConfig

func NewStateConfig(vp *viper.Viper) (*stateConfig, error)

Types

type CompositeRangeScanIterator

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

CompositeRangeScanIterator - an implementation of interface 'statemgmt.RangeScanIterator' This provides a wrapper on top of more than one underlying iterators

func (*CompositeRangeScanIterator) Close

func (citr *CompositeRangeScanIterator) Close()

Close - see interface 'statemgmt.StateDeltaIterator' for details

func (*CompositeRangeScanIterator) GetKeyValue

func (citr *CompositeRangeScanIterator) GetKeyValue() (string, []byte)

GetKeyValue - see interface 'statemgmt.StateDeltaIterator' for details

func (*CompositeRangeScanIterator) Next

func (citr *CompositeRangeScanIterator) Next() bool

type State

type State struct {
	//this three fields MUST be immutable in the life-time of a ledger
	//(even the db has been switched)
	*db.OpenchainDB
	// contains filtered or unexported fields
}

State structure for maintaining world state. This encapsulates a particular implementation for managing the state persistence This is not thread safe

func CreateState

func CreateState(db *db.OpenchainDB, config *stateConfig) *State

CreateState constructs a new State, but not initialize it

func NewState

func NewState(db *db.OpenchainDB, config *stateConfig) *State

NewState constructs a new State. This Initializes encapsulated state implementation

func (*State) AddChangesForPersistence

func (state *State) AddChangesForPersistence(blockNumber uint64, writeBatch *db.DBWriteBatch)

AddChangesForPersistence adds key-value pairs to writeBatch

func (*State) ApplyStateDelta

func (state *State) ApplyStateDelta(delta *statemgmt.StateDelta)

ApplyStateDelta applies already prepared stateDelta to the existing state. This is an in memory change only. state.CommitStateDelta must be used to commit the state to the DB. This method is to be used in state transfer.

func (*State) ApplyTxExec

func (state *State) ApplyTxExec(exec *TxExecStates)

func (*State) ClearInMemoryChanges

func (state *State) ClearInMemoryChanges(changesPersisted bool)

ClearInMemoryChanges remove from memory all the changes to state

func (*State) CommitStateDelta

func (state *State) CommitStateDelta() error

CommitStateDelta commits the changes from state.ApplyStateDelta to the DB.

func (*State) CopyState

func (state *State) CopyState(sourceChaincodeID string, destChaincodeID string) error

CopyState copies all the key-values from sourceChaincodeID to destChaincodeID

func (*State) Delete

func (state *State) Delete(chaincodeID string, key string) error

Delete tracks the deletion of state for chaincodeID and key. Does not immediately writes to DB

func (*State) DeleteState

func (state *State) DeleteState() error

DeleteState deletes ALL state keys/values from the DB. This is generally only used during state synchronization when creating a new state from a snapshot.

func (*State) FetchStateDeltaFromDB

func (state *State) FetchStateDeltaFromDB(blockNumber uint64) (*statemgmt.StateDelta, error)

FetchStateDeltaFromDB fetches the StateDelta corrsponding to given blockNumber

func (*State) Get

func (state *State) Get(chaincodeID string, key string, sn *db.DBSnapshot, _ int) ([]byte, error)

Get returns state for chaincodeID and key. If committed is false, this first looks in memory and if missing, pulls from db. If committed is true, this pulls from the db only.

func (*State) GetHash

func (state *State) GetHash() ([]byte, error)

GetHash computes new state hash if the stateDelta is to be applied. Recomputes only if stateDelta has changed after most recent call to this function

func (*State) GetImpl

func (state *State) GetImpl() statemgmt.HashableState

func (*State) GetMaxStateDeltaSize

func (state *State) GetMaxStateDeltaSize() uint64

func (*State) GetRangeScanIterator

func (state *State) GetRangeScanIterator(chaincodeID string, startKey string, endKey string, committed bool) (statemgmt.RangeScanIterator, error)

GetRangeScanIterator returns an iterator to get all the keys (and values) between startKey and endKey (assuming lexical order of the keys) for a chaincodeID.

func (*State) GetSnapshot

func (state *State) GetSnapshot(blockNumber uint64, dbSnapshot *db.DBSnapshot) (*StateSnapshot, error)

GetSnapshot returns a snapshot of the global state for the current block. stateSnapshot.Release() must be called once you are done.

func (*State) GetSnapshotManager

func (state *State) GetSnapshotManager() statemgmt.SnapshotState

func (*State) GetStateDelta

func (state *State) GetStateDelta() *statemgmt.StateDelta

func (*State) GetTransient

func (state *State) GetTransient(chaincodeID string, key string) ([]byte, error)

func (*State) GetTxStateDeltaHash

func (state *State) GetTxStateDeltaHash() map[string][]byte

the tx-related API which has been deprecated (use TxExecStates instead) GetTxStateDeltaHash return the hash of the StateDelta

func (*State) MergeStateDelta

func (state *State) MergeStateDelta(delta *statemgmt.StateDelta)

similar to ApplyStateDelta but it merge, instead of change the state

func (*State) Set

func (state *State) Set(chaincodeID string, key string, value []byte) error

Set sets state to given value for chaincodeID and key. Does not immediately writes to DB

func (*State) SetMultipleKeys

func (state *State) SetMultipleKeys(chaincodeID string, kvs map[string][]byte) error

SetMultipleKeys sets the values for the multiple keys.

func (*State) TxBegin

func (state *State) TxBegin(txID string)

TxBegin marks begin of a new tx. If a tx is already in progress, this call panics

func (*State) TxFinish

func (state *State) TxFinish(txID string, txSuccessful bool)

TxFinish marks the completion of on-going tx. If txID is not same as of the on-going tx, this call panics

type StateConfig

type StateConfig struct {
	V *stateConfig
}

func (StateConfig) ImplConfigs

func (cw StateConfig) ImplConfigs() map[string]interface{}

type StateSnapshot

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

StateSnapshot encapsulates StateSnapshotIterator given by actual state implementation and the db snapshot

func NewStateSnapshot

func NewStateSnapshot(blockNumber uint64, itr statemgmt.StateSnapshotIterator, dbSnapshot *db.DBSnapshot) *StateSnapshot

func (*StateSnapshot) GetBlockNumber

func (ss *StateSnapshot) GetBlockNumber() uint64

GetBlockNumber returns the blocknumber associated with this global state snapshot

func (*StateSnapshot) GetRawKeyValue

func (ss *StateSnapshot) GetRawKeyValue() ([]byte, []byte)

GetRawKeyValue returns the raw bytes for the key and value at the current iterator position

func (*StateSnapshot) Next

func (ss *StateSnapshot) Next() bool

Next moves the iterator to the next key/value pair in the state

func (*StateSnapshot) Release

func (ss *StateSnapshot) Release()

Release the snapshot. This MUST be called when you are done with this resouce.

type TxExecStates

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

supporting for the concurrent executation of tx the r/w in tx exec involve three sets: wset record all set/delete action rset trace all get action, so we can evaluate the whole cost to db for one tx, we also trace each key in the iteration op in tx. baseSets, which is an array, is also used for get operation

func NewExecStates

func NewExecStates(baseSets ...*statemgmt.StateDelta) *TxExecStates

func NewExecStatesFromState

func NewExecStatesFromState(s *State, morebaseSets ...*statemgmt.StateDelta) *TxExecStates

legacy API

func (*TxExecStates) BindSnapshot

func (s *TxExecStates) BindSnapshot(sn *db.DBSnapshot)

caller MUST response for releasing the snapshot

func (*TxExecStates) DeRef

func (s *TxExecStates) DeRef() *statemgmt.StateDelta

func (*TxExecStates) Delete

func (s *TxExecStates) Delete(chaincodeID string, key string)

func (*TxExecStates) Get

func (s *TxExecStates) Get(chaincodeID string, key string, underlying statemgmt.HashableState) (ret []byte, err error)

func (*TxExecStates) GetRangeScanIterator

func (s *TxExecStates) GetRangeScanIterator(chaincodeID string, startKey string, endKey string, underlying statemgmt.HashableState) (statemgmt.RangeScanIterator, error)

GetRangeScanIterator returns an iterator to get all the keys (and values) between startKey and endKey (assuming lexical order of the keys) for a chaincodeID.

func (*TxExecStates) IsEmpty

func (s *TxExecStates) IsEmpty() bool

overwrite statedelta's isempty

func (*TxExecStates) IsSnapshotRead

func (s *TxExecStates) IsSnapshotRead() bool

func (*TxExecStates) RepairWSet

func (s *TxExecStates) RepairWSet(underlying statemgmt.HashableState) error

TODO: cost of repairwset is not count yet

func (*TxExecStates) Set

func (s *TxExecStates) Set(chaincodeID string, key string, value []byte)

we overwrite the set/delete methods with the fashion in state module: previous value is only searched from in-memory variables we availiable (i.e: rset/baseSets) base on the purpose that the most common op is write-after-read we can also repair the wset's previous value later if needed

func (*TxExecStates) SetMultipleKeys

func (s *TxExecStates) SetMultipleKeys(chaincodeID string, kvs map[string][]byte)

SetMultipleKeys sets the values for the multiple keys.

func (*TxExecStates) TxExecResultHash

func (s *TxExecStates) TxExecResultHash() []byte

Jump to

Keyboard shortcuts

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