diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index bd91c6573d..2c675337e1 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -112,8 +112,9 @@ var ( Category: flags.EthCategory, } EraFlag = &flags.DirectoryFlag{ - Name: "datadir.era", - Usage: "Root directory for era1 history (default = inside ancient/chain)", + Name: "datadir.era", + Usage: "Root directory for era1 history (default = inside ancient/chain)", + Category: flags.EthCategory, } MinFreeDiskSpaceFlag = &flags.DirectoryFlag{ Name: "datadir.minfreedisk", diff --git a/core/rawdb/database.go b/core/rawdb/database.go index b661287851..d56dc1df74 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -186,6 +186,18 @@ func resolveChainFreezerDir(ancient string) string { return freezer } +// resolveChainEraDir is a helper function which resolves the absolute path of era database. +func resolveChainEraDir(chainFreezerDir string, era string) string { + switch { + case era == "": + return filepath.Join(chainFreezerDir, "era") + case !filepath.IsAbs(era): + return filepath.Join(chainFreezerDir, era) + default: + return era + } +} + // NewDatabaseWithFreezer creates a high level database on top of a given key- // value data store with a freezer moving immutable chain segments into cold // storage. The passed ancient indicates the path of root ancient directory @@ -198,6 +210,9 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace st if chainFreezerDir != "" { chainFreezerDir = resolveChainFreezerDir(chainFreezerDir) } + if chainFreezerDir != "" { + eraDir = resolveChainEraDir(chainFreezerDir, eraDir) + } frdb, err := newChainFreezer(chainFreezerDir, namespace, readonly, eraDir) if err != nil { printChainMetadata(db) diff --git a/core/rawdb/eradb/eradb.go b/core/rawdb/eradb/eradb.go index 537492edeb..d01b4de550 100644 --- a/core/rawdb/eradb/eradb.go +++ b/core/rawdb/eradb/eradb.go @@ -74,7 +74,7 @@ func New(datadir string) (*EraDatabase, error) { // opened multiple times. db.cache.OnReplaced(closeEra) - log.Info("Opened erastore", "datadir", datadir) + log.Info("Opened Era store", "datadir", datadir) return db, nil } diff --git a/node/database.go b/node/database.go index 492ec643b6..929a7263b6 100644 --- a/node/database.go +++ b/node/database.go @@ -32,11 +32,14 @@ type openOptions struct { Type string // "leveldb" | "pebble" Directory string // the datadir AncientsDirectory string // the ancients-dir - EraDirectory string - Namespace string // the namespace for database relevant metrics - Cache int // the capacity(in megabytes) of the data caching - Handles int // number of files to be open simultaneously - ReadOnly bool + + // The optional Era folder, which can be either a subfolder under + // ancient/chain or a directory specified via an absolute path. + EraDirectory string + Namespace string // the namespace for database relevant metrics + Cache int // the capacity(in megabytes) of the data caching + Handles int // number of files to be open simultaneously + ReadOnly bool } // openDatabase opens both a disk-based key-value database such as leveldb or pebble, but also @@ -62,8 +65,8 @@ func openDatabase(o openOptions) (ethdb.Database, error) { // openKeyValueDatabase opens a disk-based key-value database, e.g. leveldb or pebble. // -// type == null type != null -// +---------------------------------------- +// type == null type != null +// +---------------------------------------- // db is non-existent | pebble default | specified type // db is existent | from db | specified type (if compatible) func openKeyValueDatabase(o openOptions) (ethdb.Database, error) { diff --git a/node/node.go b/node/node.go index 9913db374e..e058116ab1 100644 --- a/node/node.go +++ b/node/node.go @@ -746,7 +746,7 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient Type: n.config.DBEngine, Directory: n.ResolvePath(name), AncientsDirectory: n.ResolveAncient(name, ancient), - EraDirectory: n.ResolveEraDirectory(ancient, era), + EraDirectory: era, Namespace: namespace, Cache: cache, Handles: handles, @@ -775,17 +775,6 @@ func (n *Node) ResolveAncient(name string, ancient string) string { return ancient } -// ResolveEraDirectory returns the absolute path of the era directory. -func (n *Node) ResolveEraDirectory(ancient, era string) string { - switch { - case era == "": - era = filepath.Join(ancient, "era") - case !filepath.IsAbs(era): - era = n.ResolvePath(era) - } - return era -} - // closeTrackingDB wraps the Close method of a database. When the database is closed by the // service, the wrapper removes it from the node's database map. This ensures that Node // won't auto-close the database if it is closed by the service that opened it.