Documentation ¶
Index ¶
- Constants
- Variables
- func Backup(odb *OpenchainDB) (tag string, err error)
- func DefaultOption() baseOpt
- func DropDB(path string) error
- func GetBackupPath(tag string) []string
- func GetCurrentDBPath() []string
- func InitDBPath(path string)
- func ListPersistorKeys() []string
- func NewPersistor(index PersistorKey) *persistor
- func Start()
- func Stop()
- func StopDB(odb *OpenchainDB)
- type DBIterator
- type DBSnapshot
- func (*DBSnapshot) Close(*DBSnapshot)
- func (e *DBSnapshot) GetFromBlockchainCFSnapshot(key []byte) ([]byte, error)
- func (e *DBSnapshot) GetFromIndexCFSnapshot(key []byte) ([]byte, error)
- func (e *DBSnapshot) GetFromStateCFSnapshot(key []byte) ([]byte, error)
- func (e *DBSnapshot) GetFromStateDeltaCFSnapshot(key []byte) ([]byte, error)
- func (e *DBSnapshot) GetSnapshot() *gorocksdb.Snapshot
- func (e *DBSnapshot) GetStateCFSnapshotIterator() *gorocksdb.Iterator
- func (e *DBSnapshot) Release()
- type DBWriteBatch
- type GlobalDataDB
- func (txdb *GlobalDataDB) AddGlobalState(parentStateHash []byte, statehash []byte) error
- func (h *GlobalDataDB) BatchCommit(writeBatch *gorocksdb.WriteBatch) error
- func (h *GlobalDataDB) DeleteKey(cfName string, key []byte) error
- func (h *GlobalDataDB) GetCFByName(cfName string) *gorocksdb.ColumnFamilyHandle
- func (openchainDB *GlobalDataDB) GetDBVersion() int
- func (txdb *GlobalDataDB) GetGlobalState(statehash []byte) *protos.GlobalState
- func (openchainDB *GlobalDataDB) GetIterator(cfName string) *gorocksdb.Iterator
- func (txdb *GlobalDataDB) GetTransaction(txid string) (*protos.Transaction, error)
- func (txdb *GlobalDataDB) GetTransactions(txids []string) []*protos.Transaction
- func (h *GlobalDataDB) GetValue(cfName string, key []byte) ([]byte, error)
- func (openchainDB *GlobalDataDB) ListCheckpoints() (ret [][]byte)
- func (openchainDB *GlobalDataDB) ListCheckpointsByTag(tag string) (ret [][]byte)
- func (h *GlobalDataDB) NewWriteBatch() *gorocksdb.WriteBatch
- func (txdb *GlobalDataDB) PutGenesisGlobalState(statehash []byte) error
- func (txdb *GlobalDataDB) PutTransactions(txs []*protos.Transaction) error
- func (h *GlobalDataDB) PutValue(cfName string, key []byte, value []byte) error
- type OpenchainDB
- func (oc *OpenchainDB) CheckpointCurrent(statehash []byte) error
- func (openchainDB *OpenchainDB) CleanManagedSnapshot()
- func (openchainDB *OpenchainDB) DeleteAll() error
- func (openchainDB *OpenchainDB) DeleteKey(cfname string, key []byte) error
- func (openchainDB *OpenchainDB) DeleteState() error
- func (openchainDB *OpenchainDB) GetDBPath() string
- func (openchainDB *OpenchainDB) GetDBTag() string
- func (openchainDB *OpenchainDB) GetDBVersion() int
- func (orgdb *OpenchainDB) GetFromBlockchainCF(key []byte) ([]byte, error)
- func (openchainDB *OpenchainDB) GetIterator(cfName string) *DBIterator
- func (openchainDB *OpenchainDB) GetManagedSnapshot(name string) *DBSnapshot
- func (openchainDB *OpenchainDB) GetSnapshot() *DBSnapshot
- func (openchainDB *OpenchainDB) GetValue(cfname string, key []byte) ([]byte, error)
- func (openchainDB *OpenchainDB) ManageSnapshot(name string) *DBSnapshot
- func (openchainDB *OpenchainDB) NewWriteBatch() *DBWriteBatch
- func (openchainDB *OpenchainDB) PutValue(cfname string, key []byte, value []byte) error
- func (oc *OpenchainDB) StateSwitch(statehash []byte) error
- func (openchainDB *OpenchainDB) UnManageSnapshot(name string)
- func (openchainDB *OpenchainDB) UpdateDBVersion(v int) error
- type PersistorKey
- type StateDuplicatedError
- type TestDBWrapper
- func (testDB *TestDBWrapper) CleanCF(t testing.TB, cfName string)
- func (testDB *TestDBWrapper) CleanDB(t testing.TB)
- func (testDB *TestDBWrapper) CloseDB(t testing.TB)
- func (testDB *TestDBWrapper) CreateFreshDBGinkgo()
- func (testDB *TestDBWrapper) GetDB() *OpenchainDB
- func (testDB *TestDBWrapper) GetDBStats() string
- func (testDB *TestDBWrapper) GetEstimatedNumKeys(t testing.TB) map[string]string
- func (testDB *TestDBWrapper) GetFromDB(t testing.TB, key []byte) []byte
- func (testDB *TestDBWrapper) GetFromStateCF(t testing.TB, key []byte) []byte
- func (testDB *TestDBWrapper) GetFromStateDeltaCF(t testing.TB, key []byte) []byte
- func (testDB *TestDBWrapper) NewWriteBatch() *DBWriteBatch
- func (testDB *TestDBWrapper) OpenDB(t testing.TB)
- func (testDB *TestDBWrapper) PutGenesisGlobalState(state []byte) error
- func (testDB *TestDBWrapper) WriteToDB(t testing.TB, writeBatch *DBWriteBatch)
Constants ¶
const BlockchainCF = "blockchainCF"
cf in db
const ConsensusCF = "consensusCF"
const DBVersion = 1
const GlobalCF = "globalCF"
const IndexesCF = "indexesCF"
const PersistCF = "persistCF"
const RawLegacyPBFTPrefix = "consensus.chkpt."
some per-def prefix
const StateCF = "stateCF"
const StateDeltaCF = "stateDeltaCF"
const TxCF = "txCF"
cf in txdb
Variables ¶
var CurrentDBPathKey = []byte("blockCount")
Functions ¶
func Backup ¶
func Backup(odb *OpenchainDB) (tag string, err error)
func DefaultOption ¶
func DefaultOption() baseOpt
func GetBackupPath ¶
generate paths for backuping, only understanded by this package
func GetCurrentDBPath ¶
func GetCurrentDBPath() []string
func InitDBPath ¶
func InitDBPath(path string)
func ListPersistorKeys ¶
func ListPersistorKeys() []string
func NewPersistor ¶
func NewPersistor(index PersistorKey) *persistor
func Start ¶
func Start()
Start the db, init the openchainDB instance and open the db. Note this method has no guarantee correct behavior concurrent invocation.
func Stop ¶
func Stop()
Stop the db. Note this method has no guarantee correct behavior concurrent invocation.
func StopDB ¶
func StopDB(odb *OpenchainDB)
NOTICE: stop the db do not ensure a completely "clean" of all resource, memory leak is highly possible and we should avoid to use it frequently
Types ¶
type DBIterator ¶
func (*DBIterator) Close ¶
func (e *DBIterator) Close()
type DBSnapshot ¶
type DBSnapshot struct {
// contains filtered or unexported fields
}
func (*DBSnapshot) Close ¶
func (*DBSnapshot) Close(*DBSnapshot)
protect the close function declared in ocDB to avoiding a wrong calling
func (*DBSnapshot) GetFromBlockchainCFSnapshot ¶
func (e *DBSnapshot) GetFromBlockchainCFSnapshot(key []byte) ([]byte, error)
GetFromBlockchainCFSnapshot get value for given key from column family in a DB snapshot - blockchainCF
func (*DBSnapshot) GetFromIndexCFSnapshot ¶
func (e *DBSnapshot) GetFromIndexCFSnapshot(key []byte) ([]byte, error)
func (*DBSnapshot) GetFromStateCFSnapshot ¶
func (e *DBSnapshot) GetFromStateCFSnapshot(key []byte) ([]byte, error)
func (*DBSnapshot) GetFromStateDeltaCFSnapshot ¶
func (e *DBSnapshot) GetFromStateDeltaCFSnapshot(key []byte) ([]byte, error)
func (*DBSnapshot) GetSnapshot ¶
func (e *DBSnapshot) GetSnapshot() *gorocksdb.Snapshot
func (*DBSnapshot) GetStateCFSnapshotIterator ¶
func (e *DBSnapshot) GetStateCFSnapshotIterator() *gorocksdb.Iterator
GetStateCFSnapshotIterator get iterator for column family - stateCF. This iterator is based on a snapshot and should be used for long running scans, such as reading the entire state. Remember to call iterator.Close() when you are done.
func (*DBSnapshot) Release ¶
func (e *DBSnapshot) Release()
type DBWriteBatch ¶
type DBWriteBatch struct { *gorocksdb.WriteBatch // contains filtered or unexported fields }
func (*DBWriteBatch) BatchCommit ¶
func (e *DBWriteBatch) BatchCommit() error
func (*DBWriteBatch) Destroy ¶
func (e *DBWriteBatch) Destroy()
func (*DBWriteBatch) GetCFs ¶
func (e *DBWriteBatch) GetCFs() *openchainCFs
type GlobalDataDB ¶
type GlobalDataDB struct {
// contains filtered or unexported fields
}
func GetGlobalDBHandle ¶
func GetGlobalDBHandle() *GlobalDataDB
func (*GlobalDataDB) AddGlobalState ¶
func (txdb *GlobalDataDB) AddGlobalState(parentStateHash []byte, statehash []byte) error
func (*GlobalDataDB) BatchCommit ¶
func (h *GlobalDataDB) BatchCommit(writeBatch *gorocksdb.WriteBatch) error
func (*GlobalDataDB) GetCFByName ¶
func (h *GlobalDataDB) GetCFByName(cfName string) *gorocksdb.ColumnFamilyHandle
func (*GlobalDataDB) GetDBVersion ¶
func (openchainDB *GlobalDataDB) GetDBVersion() int
func (*GlobalDataDB) GetGlobalState ¶
func (txdb *GlobalDataDB) GetGlobalState(statehash []byte) *protos.GlobalState
func (*GlobalDataDB) GetIterator ¶
func (openchainDB *GlobalDataDB) GetIterator(cfName string) *gorocksdb.Iterator
func (*GlobalDataDB) GetTransaction ¶
func (txdb *GlobalDataDB) GetTransaction(txid string) (*protos.Transaction, error)
func (*GlobalDataDB) GetTransactions ¶
func (txdb *GlobalDataDB) GetTransactions(txids []string) []*protos.Transaction
func (*GlobalDataDB) ListCheckpoints ¶
func (openchainDB *GlobalDataDB) ListCheckpoints() (ret [][]byte)
list the default db's checkpoints
func (*GlobalDataDB) ListCheckpointsByTag ¶
func (openchainDB *GlobalDataDB) ListCheckpointsByTag(tag string) (ret [][]byte)
func (*GlobalDataDB) NewWriteBatch ¶
func (h *GlobalDataDB) NewWriteBatch() *gorocksdb.WriteBatch
func (*GlobalDataDB) PutGenesisGlobalState ¶
func (txdb *GlobalDataDB) PutGenesisGlobalState(statehash []byte) error
func (*GlobalDataDB) PutTransactions ¶
func (txdb *GlobalDataDB) PutTransactions(txs []*protos.Transaction) error
type OpenchainDB ¶
type OpenchainDB struct { //lock to access db field sync.RWMutex // contains filtered or unexported fields }
a wrapper for global ocDB
func GetDBHandle ¶
func GetDBHandle() *OpenchainDB
func (*OpenchainDB) CheckpointCurrent ¶
func (oc *OpenchainDB) CheckpointCurrent(statehash []byte) error
func (*OpenchainDB) CleanManagedSnapshot ¶
func (openchainDB *OpenchainDB) CleanManagedSnapshot()
func (*OpenchainDB) DeleteAll ¶
func (openchainDB *OpenchainDB) DeleteAll() error
func (*OpenchainDB) DeleteKey ¶
func (openchainDB *OpenchainDB) DeleteKey(cfname string, key []byte) error
func (*OpenchainDB) DeleteState ¶
func (openchainDB *OpenchainDB) DeleteState() error
DeleteState delets ALL state keys/values from the DB. This is generally only used during state synchronization when creating a new state from a snapshot.
func (*OpenchainDB) GetDBPath ¶
func (openchainDB *OpenchainDB) GetDBPath() string
func (*OpenchainDB) GetDBTag ¶
func (openchainDB *OpenchainDB) GetDBTag() string
func (*OpenchainDB) GetDBVersion ¶
func (openchainDB *OpenchainDB) GetDBVersion() int
func (*OpenchainDB) GetFromBlockchainCF ¶
func (orgdb *OpenchainDB) GetFromBlockchainCF(key []byte) ([]byte, error)
func (*OpenchainDB) GetIterator ¶
func (openchainDB *OpenchainDB) GetIterator(cfName string) *DBIterator
func (*OpenchainDB) GetManagedSnapshot ¶
func (openchainDB *OpenchainDB) GetManagedSnapshot(name string) *DBSnapshot
func (*OpenchainDB) GetSnapshot ¶
func (openchainDB *OpenchainDB) GetSnapshot() *DBSnapshot
GetSnapshot create a point-in-time view of the DB.
func (*OpenchainDB) GetValue ¶
func (openchainDB *OpenchainDB) GetValue(cfname string, key []byte) ([]byte, error)
override methods with rwlock
func (*OpenchainDB) ManageSnapshot ¶
func (openchainDB *OpenchainDB) ManageSnapshot(name string) *DBSnapshot
manage a new snapshot for current db, if name is duplicated, the old one is returned and should be released. notice the managed snapshot CANNOT call Release anymore
func (*OpenchainDB) NewWriteBatch ¶
func (openchainDB *OpenchainDB) NewWriteBatch() *DBWriteBatch
func (*OpenchainDB) PutValue ¶
func (openchainDB *OpenchainDB) PutValue(cfname string, key []byte, value []byte) error
func (*OpenchainDB) StateSwitch ¶
func (oc *OpenchainDB) StateSwitch(statehash []byte) error
func (*OpenchainDB) UnManageSnapshot ¶
func (openchainDB *OpenchainDB) UnManageSnapshot(name string)
unmanage the snapshot
func (*OpenchainDB) UpdateDBVersion ¶
func (openchainDB *OpenchainDB) UpdateDBVersion(v int) error
type PersistorKey ¶
type PersistorKey int
func GetPersistKey ¶
func GetPersistKey(k string) PersistorKey
func PersistKeyRegister ¶
func PersistKeyRegister(k string) PersistorKey
type StateDuplicatedError ¶
type StateDuplicatedError struct {
// contains filtered or unexported fields
}
type TestDBWrapper ¶
type TestDBWrapper struct {
// contains filtered or unexported fields
}
TestDBWrapper wraps the db. Can be used by other modules for testing
func NewTestDBWrapper ¶
func NewTestDBWrapper() *TestDBWrapper
NewTestDBWrapper constructs a new TestDBWrapper
func (*TestDBWrapper) CleanCF ¶
func (testDB *TestDBWrapper) CleanCF(t testing.TB, cfName string)
clean a cf, this is just for test purpose and do not care about concurrency situtaion
func (*TestDBWrapper) CleanDB ¶
func (testDB *TestDBWrapper) CleanDB(t testing.TB)
CleanDB This method closes existing db, remove the db dir. Can be called before starting a test so that data from other tests does not interfere
func (*TestDBWrapper) CloseDB ¶
func (testDB *TestDBWrapper) CloseDB(t testing.TB)
CloseDB closes the db
func (*TestDBWrapper) CreateFreshDBGinkgo ¶
func (testDB *TestDBWrapper) CreateFreshDBGinkgo()
CreateFreshDBGinkgo creates a fresh database for ginkgo testing
func (*TestDBWrapper) GetDB ¶
func (testDB *TestDBWrapper) GetDB() *OpenchainDB
func (*TestDBWrapper) GetDBStats ¶
func (testDB *TestDBWrapper) GetDBStats() string
GetDBStats returns statistics for the database
func (*TestDBWrapper) GetEstimatedNumKeys ¶
func (testDB *TestDBWrapper) GetEstimatedNumKeys(t testing.TB) map[string]string
GetEstimatedNumKeys returns estimated number of key-values in db. This is not accurate in all the cases
func (*TestDBWrapper) GetFromDB ¶
func (testDB *TestDBWrapper) GetFromDB(t testing.TB, key []byte) []byte
GetFromDB gets the value for the given key from default column-family
func (*TestDBWrapper) GetFromStateCF ¶
func (testDB *TestDBWrapper) GetFromStateCF(t testing.TB, key []byte) []byte
GetFromStateCF tests can use this method for getting value from StateCF column-family
func (*TestDBWrapper) GetFromStateDeltaCF ¶
func (testDB *TestDBWrapper) GetFromStateDeltaCF(t testing.TB, key []byte) []byte
GetFromStateDeltaCF tests can use this method for getting value from StateDeltaCF column-family
func (*TestDBWrapper) NewWriteBatch ¶
func (testDB *TestDBWrapper) NewWriteBatch() *DBWriteBatch
func (*TestDBWrapper) OpenDB ¶
func (testDB *TestDBWrapper) OpenDB(t testing.TB)
OpenDB opens the db
func (*TestDBWrapper) PutGenesisGlobalState ¶
func (testDB *TestDBWrapper) PutGenesisGlobalState(state []byte) error
func (*TestDBWrapper) WriteToDB ¶
func (testDB *TestDBWrapper) WriteToDB(t testing.TB, writeBatch *DBWriteBatch)
WriteToDB tests can use this method for persisting a given batch to db