Skip to content

Commit

Permalink
cmd/geth, node: rename backingdb to db.engine
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Feb 8, 2023
1 parent 5f3d2ce commit 82638af
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
30 changes: 15 additions & 15 deletions cmd/geth/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,40 +147,40 @@ func TestCustomBackend(t *testing.T) {
}
for i, tt := range []backendTest{
{ // When not specified, it should default to leveldb
execArgs: []string{"--backingdb", "leveldb"},
execArgs: []string{"--db.engine", "leveldb"},
execExpect: "0x0000000000001338",
},
{ // Explicit leveldb
initArgs: []string{"--backingdb", "leveldb"},
execArgs: []string{"--backingdb", "leveldb"},
initArgs: []string{"--db.engine", "leveldb"},
execArgs: []string{"--db.engine", "leveldb"},
execExpect: "0x0000000000001338",
},
{ // Explicit leveldb first, then autodiscover
initArgs: []string{"--backingdb", "leveldb"},
initArgs: []string{"--db.engine", "leveldb"},
execExpect: "0x0000000000001338",
},
{ // Explicit pebble
initArgs: []string{"--backingdb", "pebble"},
execArgs: []string{"--backingdb", "pebble"},
initArgs: []string{"--db.engine", "pebble"},
execArgs: []string{"--db.engine", "pebble"},
execExpect: "0x0000000000001338",
},
{ // Explicit pebble, then auto-discover
initArgs: []string{"--backingdb", "pebble"},
initArgs: []string{"--db.engine", "pebble"},
execExpect: "0x0000000000001338",
},
{ // Can't start pebble on top of leveldb
initArgs: []string{"--backingdb", "leveldb"},
execArgs: []string{"--backingdb", "pebble"},
execExpect: `Fatal: Failed to register the Ethereum service: backingdb choice was pebble but found pre-existing leveldb database in specified data directory`,
initArgs: []string{"--db.engine", "leveldb"},
execArgs: []string{"--db.engine", "pebble"},
execExpect: `Fatal: Failed to register the Ethereum service: db.engine choice was pebble but found pre-existing leveldb database in specified data directory`,
},
{ // Can't start leveldb on top of pebble
initArgs: []string{"--backingdb", "pebble"},
execArgs: []string{"--backingdb", "leveldb"},
execExpect: `Fatal: Failed to register the Ethereum service: backingdb choice was leveldb but found pre-existing pebble database in specified data directory`,
initArgs: []string{"--db.engine", "pebble"},
execArgs: []string{"--db.engine", "leveldb"},
execExpect: `Fatal: Failed to register the Ethereum service: db.engine choice was leveldb but found pre-existing pebble database in specified data directory`,
},
{ // Reject invalid backend choice
initArgs: []string{"--backingdb", "mssql"},
initExpect: `Fatal: Invalid choice for backing db 'mssql', allowed 'leveldb' or 'pebble'`,
initArgs: []string{"--db.engine", "mssql"},
initExpect: `Fatal: Invalid choice for db.engine 'mssql', allowed 'leveldb' or 'pebble'`,
// Since the init fails, this will return the (default) mainnet genesis
// block nonce
execExpect: `0x0000000000000042`,
Expand Down
18 changes: 9 additions & 9 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ var (
Usage: "URL for remote database",
Category: flags.LoggingCategory,
}
BackingDBFlag = &cli.StringFlag{
Name: "backingdb",
DBEngineFlag = &cli.StringFlag{
Name: "db.engine",
Usage: "Backing database implementation to use ('leveldb' or 'pebble')",
Value: "leveldb",
Category: flags.EthCategory,
Expand Down Expand Up @@ -1023,7 +1023,7 @@ var (

func init() {
if rawdb.PebbleEnabled {
DatabasePathFlags = append(DatabasePathFlags, BackingDBFlag)
DatabasePathFlags = append(DatabasePathFlags, DBEngineFlag)
}
}

Expand Down Expand Up @@ -1509,13 +1509,13 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
if ctx.IsSet(InsecureUnlockAllowedFlag.Name) {
cfg.InsecureUnlockAllowed = ctx.Bool(InsecureUnlockAllowedFlag.Name)
}
if ctx.IsSet(BackingDBFlag.Name) {
backingDB := ctx.String(BackingDBFlag.Name)
if backingDB != "leveldb" && backingDB != "pebble" {
Fatalf("Invalid choice for backing db '%s', allowed 'leveldb' or 'pebble'", backingDB)
if ctx.IsSet(DBEngineFlag.Name) {
dbEngine := ctx.String(DBEngineFlag.Name)
if dbEngine != "leveldb" && dbEngine != "pebble" {
Fatalf("Invalid choice for db.engine '%s', allowed 'leveldb' or 'pebble'", dbEngine)
}
log.Info(fmt.Sprintf("Using %s as backing db", backingDB))
cfg.BackingDB = backingDB
log.Info(fmt.Sprintf("Using %s as db engine", dbEngine))
cfg.DBEngine = dbEngine
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,18 +349,18 @@ type OpenOptions struct {
func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) {
existingDb := hasPreexistingDb(o.Directory)
if len(existingDb) != 0 && len(o.Type) != 0 && o.Type != existingDb {
return nil, fmt.Errorf("backingdb choice was %v but found pre-existing %v database in specified data directory", o.Type, existingDb)
return nil, fmt.Errorf("db.engine choice was %v but found pre-existing %v database in specified data directory", o.Type, existingDb)
}
if o.Type == dbPebble || existingDb == dbPebble {
if PebbleEnabled {
log.Info("Using pebble as the backing database")
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly)
} else {
return nil, errors.New("backingdb 'pebble' not supported on this platform")
return nil, errors.New("db.engine 'pebble' not supported on this platform")
}
}
if len(o.Type) != 0 && o.Type != dbLeveldb {
return nil, fmt.Errorf("unknown backingdb %v", o.Type)
return nil, fmt.Errorf("unknown db.engine %v", o.Type)
}
log.Info("Using leveldb as the backing database")
// Use leveldb, either as default (no explicit choice), or pre-existing, or chosen explicitly
Expand Down
2 changes: 1 addition & 1 deletion ethdb/pebble/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
package pebble

import (
"fmt"
"runtime"
"sync"
"sync/atomic"
"time"

"fmt"
"github.com/cockroachdb/pebble"
"github.com/cockroachdb/pebble/bloom"
"github.com/ethereum/go-ethereum/common"
Expand Down
2 changes: 1 addition & 1 deletion node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type Config struct {
// EnablePersonal enables the deprecated personal namespace.
EnablePersonal bool `toml:"-"`

BackingDB string `toml:",omitempty"`
DBEngine string `toml:",omitempty"`
}

// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
Expand Down
2 changes: 1 addition & 1 deletion node/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var DefaultConfig = Config{
MaxPeers: 50,
NAT: nat.Any(),
},
BackingDB: "",
DBEngine: "",
}

// DefaultDataDir is the default data directory to use for the databases and other
Expand Down
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func (n *Node) OpenDatabase(name string, cache, handles int, namespace string, r
db = rawdb.NewMemoryDatabase()
} else {
db, err = rawdb.Open(rawdb.OpenOptions{
Type: n.config.BackingDB,
Type: n.config.DBEngine,
Directory: n.ResolvePath(name),
Namespace: namespace,
Cache: cache,
Expand Down Expand Up @@ -742,7 +742,7 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient
db = rawdb.NewMemoryDatabase()
} else {
db, err = rawdb.Open(rawdb.OpenOptions{
Type: n.config.BackingDB,
Type: n.config.DBEngine,
Directory: n.ResolvePath(name),
AncientsDirectory: n.ResolveAncient(name, ancient),
Namespace: namespace,
Expand Down

0 comments on commit 82638af

Please sign in to comment.