From 82638af676046e828dbe7fa6e925e171606ec06b Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 8 Feb 2023 13:20:07 +0100 Subject: [PATCH] cmd/geth, node: rename backingdb to db.engine --- cmd/geth/genesis_test.go | 30 +++++++++++++++--------------- cmd/utils/flags.go | 18 +++++++++--------- core/rawdb/database.go | 6 +++--- ethdb/pebble/pebble.go | 2 +- node/config.go | 2 +- node/defaults.go | 2 +- node/node.go | 4 ++-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cmd/geth/genesis_test.go b/cmd/geth/genesis_test.go index 4f2d87577fbb..8e379b867a7e 100644 --- a/cmd/geth/genesis_test.go +++ b/cmd/geth/genesis_test.go @@ -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`, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 6fa5080f2a24..755a9d062f5e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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, @@ -1023,7 +1023,7 @@ var ( func init() { if rawdb.PebbleEnabled { - DatabasePathFlags = append(DatabasePathFlags, BackingDBFlag) + DatabasePathFlags = append(DatabasePathFlags, DBEngineFlag) } } @@ -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 } } diff --git a/core/rawdb/database.go b/core/rawdb/database.go index efa5991f36c2..ef80c251a457 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -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 diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index a94874125b31..c850dc5a1b2a 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -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" diff --git a/node/config.go b/node/config.go index 8273a9a1b055..37a7d5837fa2 100644 --- a/node/config.go +++ b/node/config.go @@ -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 diff --git a/node/defaults.go b/node/defaults.go index 74b59b38f1b9..96ebed81c536 100644 --- a/node/defaults.go +++ b/node/defaults.go @@ -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 diff --git a/node/node.go b/node/node.go index c3e46efc7eb1..112a771ab090 100644 --- a/node/node.go +++ b/node/node.go @@ -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, @@ -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,