store

package module
v0.0.0-...-8b03266 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 60 Imported by: 2

README

store

介绍

hercules 链存储基础模块

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

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

Variables

This section is empty.

Functions

func NewAsyncBlockStoreImpl

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

func WrapBlockDB2TxExistDB

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

创建空db

Types

type AsyncBlockStoreImpl

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

AsyncBlockStoreImpl Asynchronous storage of block data.

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.

func (*AsyncBlockStoreImpl) PutBlock

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

PutBlock Asynchronous storage of block data. 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 {
	ArchiveMgr *archive.ArchiveMgr
	// contains filtered or unexported fields
}

BlockStoreImpl provides an implementation of `protocol.BlockchainStore`.

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`

func (*BlockStoreImpl) ArchiveBlock

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

ArchiveBlock the block after backup

func (*BlockStoreImpl) BeginDbTransaction

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

BeginDbTransaction 启用一个事务

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.

func (*BlockStoreImpl) Close

func (bs *BlockStoreImpl) Close() error

Close is used to close database

func (*BlockStoreImpl) CommitDbTransaction

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

CommitDbTransaction 提交一个事务

func (*BlockStoreImpl) CommonPutBlock

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

普通写模式,占用资源少,写入慢 1.写wal 2.写kvdb cache 或者 sql 3.写kvdb 或者什么都不做 4.删除过期的wal

func (*BlockStoreImpl) CreateDatabase

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

func (*BlockStoreImpl) DropDatabase

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

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

func (*BlockStoreImpl) ExecDdlSql

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

ExecDdlSql execute DDL SQL in a contract

func (*BlockStoreImpl) GetAccountTxHistory

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

func (*BlockStoreImpl) GetArchivedPivot

func (bs *BlockStoreImpl) GetArchivedPivot() uint64

GetArchivedPivot return archived pivot

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.

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.

func (*BlockStoreImpl) GetBlockByTx

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

GetBlockByTx returns a block which contains a tx.

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.

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

func (*BlockStoreImpl) GetContractByName

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

获得合约

func (*BlockStoreImpl) GetContractBytecode

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

func (*BlockStoreImpl) GetContractDbName

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

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

func (*BlockStoreImpl) GetContractTxHistory

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

func (*BlockStoreImpl) GetDBHandle

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

GetDBHandle returns the database handle for given dbName(chainId)

func (*BlockStoreImpl) GetDbTransaction

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

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

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.

func (*BlockStoreImpl) GetHistoryForKey

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

func (*BlockStoreImpl) GetLastBlock

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

GetLastBlock returns the last block.

func (*BlockStoreImpl) GetLastChainConfig

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

GetLastChainConfig returns the last chain config

func (*BlockStoreImpl) GetLastConfigBlock

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

GetLastConfigBlock returns the last config block.

func (*BlockStoreImpl) GetMemberExtraData

func (bs *BlockStoreImpl) GetMemberExtraData(member *accesscontrol.Member) (*accesscontrol.MemberExtraData, 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.

func (*BlockStoreImpl) GetTxConfirmedTime

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

GetTxConfirmedTime returns the confirmed time of a given tx

func (*BlockStoreImpl) GetTxHeight

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

GetTxHeight retrieves a transaction height by txid, or returns nil if none exists.

func (*BlockStoreImpl) GetTxInfoOnly

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

func (*BlockStoreImpl) GetTxInfoWithRWSet

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

GetTxInfoWithRWSet return tx and tx info and rw set

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.

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

func (*BlockStoreImpl) GetTxWithInfo

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

func (*BlockStoreImpl) GetTxWithRWSet

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

GetTxWithRWSet return tx and it's rw set

func (*BlockStoreImpl) InitArchiveMgr

func (bs *BlockStoreImpl) InitArchiveMgr(chainId string) error

func (*BlockStoreImpl) InitGenesis

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

InitGenesis 初始化创世区块到数据库,对应的数据库必须为空数据库,否则报错

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 如果是普通写入模式,先后写 kvCache,wal,kvdb 然后返回 如果是快速写模式,先写 kvCache,wal,chan 然后返回 ,chan中数据由单独的groutine负责完成 消费写到 db中

func (*BlockStoreImpl) QueryMulti

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

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

func (*BlockStoreImpl) QuerySingle

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

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

func (*BlockStoreImpl) QuickPutBlock

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

QuickPutBlock 模式,写入和读取性能更好,占用内存更多 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

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.

func (*BlockStoreImpl) RestoreBlocks

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

RestoreBlocks restore blocks from outside serialized block data

func (*BlockStoreImpl) RollbackDbTransaction

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

RollbackDbTransaction 回滚一个事务

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.

func (*BlockStoreImpl) TxExists

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

TxExists returns true if the tx exist, or returns false if none exists.

func (*BlockStoreImpl) TxExistsInFullDB

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.

func (*BlockStoreImpl) TxExistsInIncrementDB

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.

func (*BlockStoreImpl) WriteBatchFromChanToDB

func (bs *BlockStoreImpl) WriteBatchFromChanToDB()

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

func (*BlockStoreImpl) WriteKvDb

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

commit block to kvdb 写 block,state,history,result,bigfilter 5种kvdb,不包含contractevent db, 合约db只有 sql型,没有kv型.

func (*BlockStoreImpl) WriteKvDbCacheSqlDb

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

commit block to kvdb cache and sqldb 写block,state,history,result,bigfilter 5种kvdb cache或者对应的sqldb, 写1个 contractEventDB(sqldb), 1个 txExistDB(kvdb) txExistDB不支持sql型, 写1个 rollingWindowCache 一共8个groutine

type Factory

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

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

func NewFactory

func NewFactory() *Factory

func (*Factory) NewBlockDB

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

创建blockdb

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

Jump to

Keyboard shortcuts

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