db

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: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BlockchainCF = "blockchainCF"

cf in db

View Source
const ConsensusCF = "consensusCF"
View Source
const DBVersion = 1
View Source
const GlobalCF = "globalCF"
View Source
const IndexesCF = "indexesCF"
View Source
const PersistCF = "persistCF"
View Source
const RawLegacyPBFTPrefix = "consensus.chkpt."

some per-def prefix

View Source
const StateCF = "stateCF"
View Source
const StateDeltaCF = "stateDeltaCF"
View Source
const TxCF = "txCF"

cf in txdb

Variables

View Source
var CurrentDBPathKey = []byte("blockCount")

Functions

func Backup

func Backup(odb *OpenchainDB) (tag string, err error)

func DefaultOption

func DefaultOption() baseOpt

func DropDB

func DropDB(path string) error

func GetBackupPath

func GetBackupPath(tag string) []string

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

type DBIterator struct {
	*gorocksdb.Iterator
	// contains filtered or unexported fields
}

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

func (h *GlobalDataDB) DeleteKey(cfName string, key []byte) 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) GetValue

func (h *GlobalDataDB) GetValue(cfName string, key []byte) ([]byte, error)

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

func (*GlobalDataDB) PutValue

func (h *GlobalDataDB) PutValue(cfName string, key []byte, value []byte) 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 StartDB

func StartDB(tag string, vp *viper.Viper) (*OpenchainDB, error)

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

Jump to

Keyboard shortcuts

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