store

package module
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 64 Imported by: 1

Documentation

Index

Constants

View Source
const (
	//StoreBlockDBDir blockdb folder name
	StoreBlockDBDir = "store_block"
	//StoreStateDBDir statedb folder name
	StoreStateDBDir = "store_state"
	//StoreHistoryDBDir historydb folder name
	StoreHistoryDBDir = "store_history"
	//StoreResultDBDir resultdb folder name
	StoreResultDBDir   = "store_result"
	StoreEventLogDBDir = "store_event_log"
	StoreLocalDBDir    = "localdb"
	StoreTxExistDbDir  = "store_txexist"

	DBName_BlockDB   = "blockdb"
	DBName_StateDB   = "statedb"
	DBName_HistoryDB = "historydb"
	DBName_ResultDB  = "resultdb"
	DBName_EventDB   = "eventdb"
	DBName_LocalDB   = "localdb"
	DBName_TxExistDB = "txexistdb"
)

nolint

Variables

View Source
var (

	// ErrHistoryDBIsDisable when disable is true, get history key return error
	ErrHistoryDBIsDisable = errors.New("history db is disable")
)

Functions

func NewAsyncBlockStoreImpl

func NewAsyncBlockStoreImpl(blockStoreImpl protocol.BlockchainStore, logger protocol.Logger) protocol.BlockchainStore

NewAsyncBlockStoreImpl add next time

@Description:
@param blockStoreImpl
@param logger
@return protocol.BlockchainStore

func WrapBlockDB2TxExistDB added in v2.2.0

func WrapBlockDB2TxExistDB(db blockdb.BlockDB, log protocol.Logger) txexistdb.TxExistDB

WrapBlockDB2TxExistDB 创建空db @Description: @param db @param log @return txexistdb.TxExistDB

Types

type AsyncBlockStoreImpl

type AsyncBlockStoreImpl struct {
	protocol.BlockchainStore
	// contains filtered or unexported fields
}

AsyncBlockStoreImpl Asynchronous storage of block data.

@Description:

func (*AsyncBlockStoreImpl) GetBlock

func (async *AsyncBlockStoreImpl) GetBlock(height uint64) (*commonPb.Block, error)

GetBlock returns a block given its block height, or returns nil if none exists.

@Description:
@receiver async
@param height
@return *commonPb.Block
@return error

func (*AsyncBlockStoreImpl) PutBlock

func (async *AsyncBlockStoreImpl) PutBlock(block *commonPb.Block, txRWSets []*commonPb.TxRWSet) error

PutBlock Asynchronous storage of block data.

@Description:
@receiver async
@param block
@param txRWSets
@return error

The block data will be cached and stored by idle working GO routines later. Note: Concurrent calls are not allowed

type BlockStoreImpl

type BlockStoreImpl struct {

	//记录慢日志的阈值,默认0表示不记录
	SlowLogThreshold int64
	// contains filtered or unexported fields
}

BlockStoreImpl provides an implementation of `protocol.BlockchainStore`. @Description:

func NewBlockStoreImpl

func NewBlockStoreImpl(chainId string,
	storeConfig *conf.StorageConfig,
	blockDB blockdb.BlockDB,
	stateDB statedb.StateDB,
	historyDB historydb.HistoryDB,
	contractEventDB contracteventdb.ContractEventDB,
	resultDB resultdb.ResultDB,
	txExistDB txexistdb.TxExistDB,
	commonDB protocol.DBHandle,
	logger protocol.Logger,
	bfdb binlog.BinLogger,
	walLog *wal.Log,
	bigFilterDB bigfilterdb.BigFilterDB,
	rwCache rolling_window_cache.RollingWindowCache) (*BlockStoreImpl, error)

NewBlockStoreImpl constructs new `BlockStoreImpl` @Description: @param chainId @param storeConfig @param blockDB @param stateDB @param historyDB @param contractEventDB @param resultDB @param txExistDB @param commonDB @param logger @param bfdb @param walLog @param bigFilterDB @param rwCache @return *BlockStoreImpl @return error

func (*BlockStoreImpl) ArchiveBlock

func (bs *BlockStoreImpl) ArchiveBlock(archiveHeight uint64) error

ArchiveBlock the block after backup @Description: @receiver bs @param archiveHeight @return error

func (*BlockStoreImpl) BeginDbTransaction

func (bs *BlockStoreImpl) BeginDbTransaction(txName string) (protocol.SqlDBTransaction, error)

BeginDbTransaction 启用一个事务

@Description:
@receiver bs
@param txName
@return protocol.SqlDBTransaction
@return error

func (*BlockStoreImpl) BlockExists

func (bs *BlockStoreImpl) BlockExists(blockHash []byte) (bool, error)

BlockExists returns true if the black hash exist, or returns false if none exists. @Description: @receiver bs @param blockHash @return bool @return error

func (*BlockStoreImpl) Close

func (bs *BlockStoreImpl) Close() error

Close is used to close database @Description: @receiver bs @return error

func (*BlockStoreImpl) CommitDbTransaction

func (bs *BlockStoreImpl) CommitDbTransaction(txName string) error

CommitDbTransaction 提交一个事务

@Description:
@receiver bs
@param txName
@return error

func (*BlockStoreImpl) CommonPutBlock added in v2.2.0

func (bs *BlockStoreImpl) CommonPutBlock(block *commonPb.Block, txRWSets []*commonPb.TxRWSet) error

CommonPutBlock add next time @Description: 普通写模式,占用资源少,写入慢 1.写wal 2.写kvdb cache 或者 sql 3.写kvdb 或者什么都不做 4.删除过期的wal @receiver bs @param block @param txRWSets @return error

func (*BlockStoreImpl) CreateDatabase

func (bs *BlockStoreImpl) CreateDatabase(contractName string) error

CreateDatabase add next time

@Description:
@receiver bs
@param contractName
@return error

func (*BlockStoreImpl) DropDatabase

func (bs *BlockStoreImpl) DropDatabase(contractName string) error

DropDatabase 删除一个合约对应的数据库

@Description:
@receiver bs
@param contractName
@return error

func (*BlockStoreImpl) ExecDdlSql

func (bs *BlockStoreImpl) ExecDdlSql(contractName, sql, version string) error

ExecDdlSql execute DDL SQL in a contract

@Description:
@receiver bs
@param contractName
@param sql
@param version
@return error

func (*BlockStoreImpl) GetAccountTxHistory

func (bs *BlockStoreImpl) GetAccountTxHistory(accountId []byte) (protocol.TxHistoryIterator, error)

GetAccountTxHistory add next time @Description: @receiver bs @param accountId @return protocol.TxHistoryIterator @return error

func (*BlockStoreImpl) GetArchiveStatus added in v2.3.4

func (bs *BlockStoreImpl) GetArchiveStatus() (*storePb.ArchiveStatus, error)

GetArchiveStatus return archive status @Description: @receiver bs @return *tbf.ArchiveStatus @return error

func (*BlockStoreImpl) GetArchivedPivot

func (bs *BlockStoreImpl) GetArchivedPivot() uint64

GetArchivedPivot return archived pivot @Description: @receiver bs @return uint64

func (*BlockStoreImpl) GetBlock

func (bs *BlockStoreImpl) GetBlock(height uint64) (*commonPb.Block, error)

GetBlock returns a block given it's block height, or returns nil if none exists. @Description: @receiver bs @param height @return *commonPb.Block @return error

func (*BlockStoreImpl) GetBlockByHash

func (bs *BlockStoreImpl) GetBlockByHash(blockHash []byte) (*commonPb.Block, error)

GetBlockByHash returns a block given it's hash, or returns nil if none exists. @Description: @receiver bs @param blockHash @return *commonPb.Block @return error

func (*BlockStoreImpl) GetBlockByTx

func (bs *BlockStoreImpl) GetBlockByTx(txId string) (*commonPb.Block, error)

GetBlockByTx returns a block which contains a tx. @Description: @receiver bs @param txId @return *commonPb.Block @return error

func (*BlockStoreImpl) GetBlockHeaderByHeight

func (bs *BlockStoreImpl) GetBlockHeaderByHeight(height uint64) (*commonPb.BlockHeader, error)

GetBlockHeaderByHeight returns a block header by given it's height, or returns nil if none exists. @Description: @receiver bs @param height @return *commonPb.BlockHeader @return error

func (*BlockStoreImpl) GetBlockWithRWSets

func (bs *BlockStoreImpl) GetBlockWithRWSets(height uint64) (*storePb.BlockWithRWSet, error)

GetBlockWithRWSets returns the block and all the rwsets corresponding to the block, or returns nil if zhe block does not exist @Description: @receiver bs @param height @return *storePb.BlockWithRWSet @return error

func (*BlockStoreImpl) GetContractByName

func (bs *BlockStoreImpl) GetContractByName(name string) (*commonPb.Contract, error)

GetContractByName 获得合约

@Description:
@receiver bs
@param name
@return *commonPb.Contract
@return error

func (*BlockStoreImpl) GetContractBytecode

func (bs *BlockStoreImpl) GetContractBytecode(name string) ([]byte, error)

GetContractBytecode add next time

@Description:
@receiver bs
@param name
@return []byte
@return error

func (*BlockStoreImpl) GetContractDbName

func (bs *BlockStoreImpl) GetContractDbName(contractName string) string

GetContractDbName 获得一个合约对应的状态数据库名

@Description:
@receiver bs
@param contractName
@return string

func (*BlockStoreImpl) GetContractTxHistory

func (bs *BlockStoreImpl) GetContractTxHistory(contractName string) (protocol.TxHistoryIterator, error)

GetContractTxHistory add next time @Description: @receiver bs @param contractName @return protocol.TxHistoryIterator @return error

func (*BlockStoreImpl) GetDBHandle

func (bs *BlockStoreImpl) GetDBHandle(dbName string) protocol.DBHandle

GetDBHandle returns the database handle for given dbName(chainId) @Description: @receiver bs @param dbName @return protocol.DBHandle

func (*BlockStoreImpl) GetDbTransaction

func (bs *BlockStoreImpl) GetDbTransaction(txName string) (protocol.SqlDBTransaction, error)

GetDbTransaction 根据事务名,获得一个已经启用的事务

@Description:
@receiver bs
@param txName
@return protocol.SqlDBTransaction
@return error

func (*BlockStoreImpl) GetHeightByHash

func (bs *BlockStoreImpl) GetHeightByHash(blockHash []byte) (uint64, error)

GetHeightByHash returns a block height given it's hash, or returns nil if none exists. @Description: @receiver bs @param blockHash @return uint64 @return error

func (*BlockStoreImpl) GetHistoryForKey

func (bs *BlockStoreImpl) GetHistoryForKey(contractName string, key []byte) (protocol.KeyHistoryIterator, error)

GetHistoryForKey add next time @Description: @receiver bs @param contractName @param key @return protocol.KeyHistoryIterator @return error

func (*BlockStoreImpl) GetLastBlock

func (bs *BlockStoreImpl) GetLastBlock() (*commonPb.Block, error)

GetLastBlock returns the last block. @Description: @receiver bs @return *commonPb.Block @return error

func (*BlockStoreImpl) GetLastChainConfig

func (bs *BlockStoreImpl) GetLastChainConfig() (*configPb.ChainConfig, error)

GetLastChainConfig returns the last chain config @Description: @receiver bs @return *configPb.ChainConfig @return error

func (*BlockStoreImpl) GetLastConfigBlock

func (bs *BlockStoreImpl) GetLastConfigBlock() (*commonPb.Block, error)

GetLastConfigBlock returns the last config block. @Description: @receiver bs @return *commonPb.Block @return error

func (*BlockStoreImpl) GetLastHeight added in v2.3.4

func (bs *BlockStoreImpl) GetLastHeight() (uint64, error)

GetLastHeight get last block height

@Description:
@receiver bs
@return uint64
@return error

func (*BlockStoreImpl) GetMemberExtraData

func (bs *BlockStoreImpl) GetMemberExtraData(member *accesscontrol.Member) (*accesscontrol.MemberExtraData, error)

GetMemberExtraData add next time

@Description:
@receiver bs
@param member
@return *accesscontrol.MemberExtraData
@return error

func (*BlockStoreImpl) GetTx

func (bs *BlockStoreImpl) GetTx(txId string) (*commonPb.Transaction, error)

GetTx retrieves a transaction by txid, or returns nil if none exists. @Description: @receiver bs @param txId @return *commonPb.Transaction @return error

func (*BlockStoreImpl) GetTxConfirmedTime

func (bs *BlockStoreImpl) GetTxConfirmedTime(txId string) (int64, error)

GetTxConfirmedTime returns the confirmed time of a given tx @Description: @receiver bs @param txId @return int64 @return error

func (*BlockStoreImpl) GetTxHeight

func (bs *BlockStoreImpl) GetTxHeight(txId string) (uint64, error)

GetTxHeight retrieves a transaction height by txid, or returns nil if none exists. @Description: @receiver bs @param txId @return uint64 @return error

func (*BlockStoreImpl) GetTxInfoOnly added in v2.2.0

func (bs *BlockStoreImpl) GetTxInfoOnly(txId string) (*commonPb.TransactionInfo, error)

GetTxInfoOnly add next time @Description: @receiver d @param txId @return *commonPb.TransactionInfo @return error

func (*BlockStoreImpl) GetTxInfoWithRWSet added in v2.2.0

func (bs *BlockStoreImpl) GetTxInfoWithRWSet(txId string) (*commonPb.TransactionInfoWithRWSet, error)

GetTxInfoWithRWSet return tx and tx info and rw set @Description: @receiver bs @param txId @return *commonPb.TransactionInfoWithRWSet @return error

func (*BlockStoreImpl) GetTxRWSet

func (bs *BlockStoreImpl) GetTxRWSet(txId string) (*commonPb.TxRWSet, error)

GetTxRWSet returns an txRWSet for given txId, or returns nil if none exists. @Description: @receiver bs @param txId @return *commonPb.TxRWSet @return error

func (*BlockStoreImpl) GetTxRWSetsByHeight

func (bs *BlockStoreImpl) GetTxRWSetsByHeight(height uint64) ([]*commonPb.TxRWSet, error)

GetTxRWSetsByHeight returns all the rwsets corresponding to the block, or returns nil if zhe block does not exist @Description: @receiver bs @param height @return []*commonPb.TxRWSet @return error

func (*BlockStoreImpl) GetTxWithInfo added in v2.2.0

func (bs *BlockStoreImpl) GetTxWithInfo(txId string) (*commonPb.TransactionInfo, error)

GetTxWithInfo add next time @Description: @receiver d @param txId @return *commonPb.TransactionInfo @return error

func (*BlockStoreImpl) GetTxWithRWSet added in v2.2.0

func (bs *BlockStoreImpl) GetTxWithRWSet(txId string) (*commonPb.TransactionWithRWSet, error)

GetTxWithRWSet return tx and it's rw set @Description: @receiver bs @param txId @return *commonPb.TransactionWithRWSet @return error

func (*BlockStoreImpl) InitArchiveMgr

func (bs *BlockStoreImpl) InitArchiveMgr(chainId, bfdbPath string, fileStore binlog.BinLogger) error

InitArchiveMgr 初始化归档管理器

@Description:
@receiver bs
@param chainId
@return error

func (*BlockStoreImpl) InitGenesis

func (bs *BlockStoreImpl) InitGenesis(genesisBlock *storePb.BlockWithRWSet) error

InitGenesis 初始化创世区块到数据库,对应的数据库必须为空数据库,否则报错 @Description: @receiver bs @param genesisBlock @return error

func (*BlockStoreImpl) PutBlock

func (bs *BlockStoreImpl) PutBlock(block *commonPb.Block, txRWSets []*commonPb.TxRWSet) error

PutBlock commits the block and the corresponding rwsets in an atomic operation @Description: 如果是普通写入模式,先后写 kvCache,wal,kvdb 然后返回 如果是快速写模式,先写 kvCache,wal,chan 然后返回 ,chan中数据由单独的groutine负责完成 消费写到 db中 @receiver bs @param block @param txRWSets @return error

func (*BlockStoreImpl) QueryMulti

func (bs *BlockStoreImpl) QueryMulti(contractName, sql string, values ...interface{}) (protocol.SqlRows, error)

QueryMulti 不在事务中,直接查询状态数据库,返回多行结果

@Description:
@receiver bs
@param contractName
@param sql
@param values
@return protocol.SqlRows
@return error

func (*BlockStoreImpl) QuerySingle

func (bs *BlockStoreImpl) QuerySingle(contractName, sql string, values ...interface{}) (protocol.SqlRow, error)

QuerySingle 不在事务中,直接查询状态数据库,返回一行结果

@Description:
@receiver bs
@param contractName
@param sql
@param values
@return protocol.SqlRow
@return error

func (*BlockStoreImpl) QuickPutBlock added in v2.2.0

func (bs *BlockStoreImpl) QuickPutBlock(block *commonPb.Block, txRWSets []*commonPb.TxRWSet) error

QuickPutBlock 模式,写入和读取性能更好,占用内存更多 @Description: 1.写wal 2.写kvdb cache 或者 sql 3.写channel

判断5种db,是 kv型,还是sql型,kv型 则 因为 kv 型 有对应Cache,可以直接同步更新Cache
如果是sql型,则 因为 sql 型 没有Cache,直接同步更新db
再写 data 到 writeBatchChan
同理,消费 writeBatchChan时,也要 判断,如果是 sql 型,则不需要 消费chan了,因为前面已经 同步更新过了
如果 是 kv 型,则 消费 chan ,然后 同步更新
依次判断 blockDB,stateDB,historyDB,resultDB,contractEventDB 对应是 sql型存储还是 kv型存储
如果是 kv型存储,则直接更新其对应的Cache,如果(是sql型)不是(kv型),则同步更新
根据配置,同步写入对应db或Cache,blockDB,stateDB,historyDB,resultDB,contractEventDB,如果写入失败,直接panic

@receiver bs @param block @param txRWSets @return error

func (*BlockStoreImpl) ReadObject

func (bs *BlockStoreImpl) ReadObject(contractName string, key []byte) ([]byte, error)

ReadObject returns the state value for given contract name and key, or returns nil if none exists. @Description: @receiver bs @param contractName @param key @return []byte @return error

func (*BlockStoreImpl) ReadObjects added in v2.3.0

func (bs *BlockStoreImpl) ReadObjects(contractName string, keys [][]byte) ([][]byte, error)

ReadObjects add next time @Description: @receiver bs @param contractName @param keys @return [][]byte @return error

func (*BlockStoreImpl) RestoreBlocks

func (bs *BlockStoreImpl) RestoreBlocks(serializedBlocks [][]byte) error

RestoreBlocks restore blocks from outside serialized block data @Description: @receiver bs @param serializedBlocks @return error

func (*BlockStoreImpl) RollbackDbTransaction

func (bs *BlockStoreImpl) RollbackDbTransaction(txName string) error

RollbackDbTransaction 回滚一个事务

@Description:
@receiver bs
@param txName
@return error

func (*BlockStoreImpl) SelectObject

func (bs *BlockStoreImpl) SelectObject(contractName string, startKey []byte, limit []byte) (
	protocol.StateIterator, error)

SelectObject returns an iterator that contains all the key-values between given key ranges. startKey is included in the results and limit is excluded. @Description: @receiver bs @param contractName @param startKey @param limit @return protocol.StateIterator @return error

func (*BlockStoreImpl) TxExists

func (bs *BlockStoreImpl) TxExists(txId string) (bool, error)

TxExists returns true if the tx exist, or returns false if none exists. @Description: @receiver bs @param txId @return bool @return error

func (*BlockStoreImpl) TxExistsInFullDB added in v2.2.1

func (bs *BlockStoreImpl) TxExistsInFullDB(txId string) (bool, uint64, error)

TxExistsInFullDB returns true and the latest committed block height in db if the tx exist, or returns false and math.MaxUint64 if none exists. @Description: @receiver bs @param txId @return bool @return uint64 @return error

func (*BlockStoreImpl) TxExistsInIncrementDB added in v2.2.1

func (bs *BlockStoreImpl) TxExistsInIncrementDB(txId string, startHeight uint64) (bool, error)

TxExistsInIncrementDB returns true if the tx exist from starHeight to the latest committed block, or returns false if none exists. @Description: @receiver bs @param txId @param startHeight @return bool @return error

func (*BlockStoreImpl) TxExistsInIncrementDBState added in v2.3.2

func (bs *BlockStoreImpl) TxExistsInIncrementDBState(txId string, startHeight uint64) (bool, bool, error)

TxExistsInIncrementDBState returns true if the tx exist from starHeight to the latest committed block, or returns false if none exists. @Description: @receiver bs @param txId @param startHeight @return bool @return bool ,true is inside the window, false is outside the window. @return error

func (*BlockStoreImpl) WriteBatchFromChanToDB added in v2.2.0

func (bs *BlockStoreImpl) WriteBatchFromChanToDB()

WriteBatchFromChanToDB 消费chan 中数据,同步写到db @Description: 从一个chan中,消费需要批量写入的序列化好的块 1.写kvdb 2.删除wal中,当前block前10个block 3.blockWithSerializedInfo 放回对象池 @receiver bs

func (*BlockStoreImpl) WriteKvDb added in v2.2.0

func (bs *BlockStoreImpl) WriteKvDb(blockWithSerializedInfo *serialization.BlockWithSerializedInfo,
	errsChan chan error) error

WriteKvDb commit block to kvdb @Description: 写 block,state,history,result,bigfilter 5种kvdb,不包含contractevent db, 合约db只有 sql型,没有kv型. @receiver bs @param blockWithSerializedInfo @param errsChan @return error

func (*BlockStoreImpl) WriteKvDbCacheSqlDb added in v2.2.0

func (bs *BlockStoreImpl) WriteKvDbCacheSqlDb(blockWithSerializedInfo *serialization.BlockWithSerializedInfo,
	errsChan chan error) error

WriteKvDbCacheSqlDb commit block to kvdb cache and sqldb @Description: 写block,state,history,result,bigfilter 5种kvdb cache或者对应的sqldb, 写1个 contractEventDB(sqldb), 1个 txExistDB(kvdb) txExistDB不支持sql型, 写1个 rollingWindowCache 一共8个groutine @receiver bs @param blockWithSerializedInfo @param errsChan @return error

type Factory

type Factory struct {
}

Factory is a factory function to create an instance of the block store which commits block into the ledger. @Description:

func NewFactory

func NewFactory() *Factory

NewFactory add next time @Description: @return *Factory

func (*Factory) NewStore

func (m *Factory) NewStore(chainId string, storeConfig *conf.StorageConfig,
	logger protocol.Logger, p11Handle *pkcs11.P11Handle) (protocol.BlockchainStore, error)

NewStore constructs new BlockStore @Description: @receiver m @param chainId @param storeConfig @param logger @param p11Handle @return protocol.BlockchainStore @return error

Directories

Path Synopsis
Package archive implement
Package archive implement
Package bigfilterdb implement
Package bigfilterdb implement
bigfilterkvdb
Package bigfilterkvdb implement @Description:
Package bigfilterkvdb implement @Description:
filter
Package filter implement
Package filter implement
Package binlog package
Package binlog package
Package blockdb implement
Package blockdb implement
blockfiledb
Package blockfiledb package
Package blockfiledb package
blockhelper
Package blockhelper package
Package blockhelper package
blockkvdb
Package blockkvdb package
Package blockkvdb package
blocksqldb
Package blocksqldb package
Package blocksqldb package
Package bloom package
Package bloom package
Package cache package
Package cache package
Package conf package
Package conf package
Package contracteventdb package
Package contracteventdb package
eventsqldb
Package eventsqldb package
Package eventsqldb package
Package dbprovider package
Package dbprovider package
Package historydb package
Package historydb package
historykvdb
Package historykvdb package
Package historykvdb package
historysqldb
Package historysqldb package
Package historysqldb package
Package resultdb package
Package resultdb package
resultfiledb
Package resultfiledb package
Package resultfiledb package
resulthelper
Package resulthelper package
Package resulthelper package
resultkvdb
Package resultkvdb package
Package resultkvdb package
resultsqldb
Package resultsqldb package
Package resultsqldb package
Package rolling_window_cache implement
Package rolling_window_cache implement
Package serialization package
Package serialization package
Package statedb package
Package statedb package
bloom
Package bloom package
Package bloom package
statekvdb
Package statekvdb package
Package statekvdb package
statesqldb
Package statesqldb package
Package statesqldb package
Package test package
Package test package
Package txexistdb package
Package txexistdb package
txexistkvdb
Package txexistkvdb package
Package txexistkvdb package
Package types implement @Description:
Package types implement @Description:
blockfile
Package blockfile package
Package blockfile package
Package utils package
Package utils package

Jump to

Keyboard shortcuts

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