Enable memdb support.
This commit adds the btcdb memdb backend as a supported database type. Note that users will NOT want to run in this mode because, being memory only, it obviously does not persist the database when shutdown. It is being added for testing purposes to help prevent constant abuse to developer's hard drive when churning the block database multiple times a day.
This commit is contained in:
parent
f309e899f3
commit
f12ca20372
2 changed files with 31 additions and 4 deletions
|
@ -975,8 +975,24 @@ func warnMultipeDBs() {
|
|||
}
|
||||
}
|
||||
|
||||
// loadBlockDB opens the block database and returns a handle to it.
|
||||
func loadBlockDB() (btcdb.Db, error) {
|
||||
// setupBlockDB loads (or creates when needed) the block database taking into
|
||||
// account the selected database backend. It also contains additional logic
|
||||
// such warning the user if there are multiple databases which consume space on
|
||||
// the file system and ensuring the regression test database is clean when in
|
||||
// regression test mode.
|
||||
func setupBlockDB() (btcdb.Db, error) {
|
||||
// The memdb backend does not have a file path associated with it, so
|
||||
// handle it uniquely. We also don't want to worry about the multiple
|
||||
// database type warnings when running with the memory database.
|
||||
if cfg.DbType == "memdb" {
|
||||
btcdLog.Infof("Creating block database in memory.")
|
||||
db, err := btcdb.CreateDB(cfg.DbType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
warnMultipeDBs()
|
||||
|
||||
// The database name is based on the database type.
|
||||
|
@ -989,8 +1005,8 @@ func loadBlockDB() (btcdb.Db, error) {
|
|||
btcdLog.Infof("Loading block database from '%s'", dbPath)
|
||||
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
|
||||
if err != nil {
|
||||
// Return the error if it's not because the database doesn't
|
||||
// exist.
|
||||
// Return the error if it's not because the database
|
||||
// doesn't exist.
|
||||
if err != btcdb.DbDoesNotExist {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1006,6 +1022,16 @@ func loadBlockDB() (btcdb.Db, error) {
|
|||
}
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// loadBlockDB opens the block database and returns a handle to it.
|
||||
func loadBlockDB() (btcdb.Db, error) {
|
||||
db, err := setupBlockDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get the latest block height from the database.
|
||||
_, height, err := db.NewestSha()
|
||||
if err != nil {
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/conformal/btcdb"
|
||||
_ "github.com/conformal/btcdb/ldb"
|
||||
_ "github.com/conformal/btcdb/memdb"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
"github.com/conformal/go-flags"
|
||||
|
|
Loading…
Reference in a new issue