mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
core/rawdb, node: fix era path resolution
This commit is contained in:
parent
d65c46526d
commit
6a5e0b40cd
5 changed files with 30 additions and 22 deletions
|
|
@ -114,6 +114,7 @@ var (
|
|||
EraFlag = &flags.DirectoryFlag{
|
||||
Name: "datadir.era",
|
||||
Usage: "Root directory for era1 history (default = inside ancient/chain)",
|
||||
Category: flags.EthCategory,
|
||||
}
|
||||
MinFreeDiskSpaceFlag = &flags.DirectoryFlag{
|
||||
Name: "datadir.minfreedisk",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ type openOptions struct {
|
|||
Type string // "leveldb" | "pebble"
|
||||
Directory string // the datadir
|
||||
AncientsDirectory string // the ancients-dir
|
||||
|
||||
// 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
|
||||
|
|
|
|||
13
node/node.go
13
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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue