As we all know, the database used by Hyperledger is ROCKSDB, and if you do not modify it, the data will be stored in the/var/hyperledger/production/db directory.
Now let's analyze the relevant code in the gray section of the diagram.
The code structure diagram is as follows
Start the database, initialize the OPENCHAINDB instance, and open the database. Note that this method does not guarantee the correct behavior of concurrent calls
Open opens a database that already exists in Hyperledger
Func (openchaindb *openchaindb) open () {
Missing, err: = Dirmissingorempty (DbPath)
Panic (FMT. Sprintf ("Error while trying to open DB:%s", err))
DBLOGGER.DEBUGF ("is DB path [%s] empty [%t]", DbPath, missing)
Err = OS. Mkdirall (path. Dir (DbPath), 0755)
Panic (FMT. Sprintf ("Error making directory path [%s]:%s", DbPath, Err))
OPTs: = Gorocksdb. Newdefaultoptions ()
Maxlogfilesize: = Viper. GetInt ("Peer.db.maxLogFileSize")
Dblogger.infof ("Setting rocksdb maxlogfilesize to%d", maxlogfilesize)
OPTs. Setmaxlogfilesize (Maxlogfilesize)
Keeplogfilenum: = Viper. GetInt ("Peer.db.keepLogFileNum")
Dblogger.infof ("Setting rocksdb Keeplogfilenum to%d", keeplogfilenum)
OPTs. Setkeeplogfilenum (Keeplogfilenum)
Loglevelstr: = Viper. GetString ("Peer.db.loglevel")
LogLevel, OK: = Rocksdbloglevelmap[loglevelstr]
Dblogger.infof ("Setting Rocks db Infologlevel to%d", logLevel)
OPTs. Setinfologlevel (LogLevel)
OPTs. Setcreateifmissing (missing)
OPTs. Setcreateifmissingcolumnfamilies (True)
Cfnames: = []string{"Default"}
Cfnames = Append (Cfnames, columnfamilies ...)
var cfopts []*gorocksdb. Options
cfopts = Append (cfopts, opts)
DB, Cfhandlers, err: = Gorocksdb. Opendbcolumnfamilies (opts, DbPath, Cfnames, cfopts)
Panic (FMT. Sprintf ("Error opening DB:%s", err))
OPENCHAINDB.BLOCKCHAINCF = cfhandlers[1]
OPENCHAINDB.STATECF = cfhandlers[2]
OPENCHAINDB.STATEDELTACF = cfhandlers[3]
OPENCHAINDB.INDEXESCF = Cfhandlers[4]
OPENCHAINDB.PERSISTCF = cfhandlers[5]
Newdefaultoptions Create a default options.
Func newdefaultoptions () *options {
Return Newnativeoptions (C.rocksdb_options_create ())
}
//options means that all optional options are available when opening a database in open form
bbto *blockbasedtableoptions
In destroy, we have to make sure we can release their memory.
CCMP *c.rocksdb_comparator_t
CMO *c.rocksdb_mergeoperator_t
CST *c.rocksdb_slicetransform_t
CCF *c.rocksdb_compactionfilter_t
Newdefaultoptions Create a default options.
Func newdefaultoptions () *options {
Return Newnativeoptions (C.rocksdb_options_create ())
Newnativeoptions create an Options object.
Func newnativeoptions (c *c.rocksdb_options_t) *options {
Newnativeoptions create an Options object.
Func newnativeoptions (c *c.rocksdb_options_t) *options {
Options means that when opening a database in open, all optional options
bbto *blockbasedtableoptions
In destroy, we have to make sure we can release their memory.
CCMP *c.rocksdb_comparator_t
CMO *c.rocksdb_mergeoperator_t
CST *c.rocksdb_slicetransform_t
CCF *c.rocksdb_compactionfilter_t
Setmaxlogfilesize setting the maximum size of the Infolog file
If the log file is larger than the Max_log_file_size constant, the new log will be created
If Max_log_file_size equals 0, all logs are written to a log
Func (OPTs *options) setmaxlogfilesize (value int) {
C.rocksdb_options_set_max_log_file_size (OPTS.C, c.size_t (value))
Setkeeplogfilenum setting the maximum saved log information file
Func (OPTs *options) setkeeplogfilenum (value int) {
C.rocksdb_options_set_keep_log_file_num (OPTS.C, c.size_t (value))