mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16: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
|
|
@ -112,8 +112,9 @@ var (
|
||||||
Category: flags.EthCategory,
|
Category: flags.EthCategory,
|
||||||
}
|
}
|
||||||
EraFlag = &flags.DirectoryFlag{
|
EraFlag = &flags.DirectoryFlag{
|
||||||
Name: "datadir.era",
|
Name: "datadir.era",
|
||||||
Usage: "Root directory for era1 history (default = inside ancient/chain)",
|
Usage: "Root directory for era1 history (default = inside ancient/chain)",
|
||||||
|
Category: flags.EthCategory,
|
||||||
}
|
}
|
||||||
MinFreeDiskSpaceFlag = &flags.DirectoryFlag{
|
MinFreeDiskSpaceFlag = &flags.DirectoryFlag{
|
||||||
Name: "datadir.minfreedisk",
|
Name: "datadir.minfreedisk",
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,18 @@ func resolveChainFreezerDir(ancient string) string {
|
||||||
return freezer
|
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-
|
// NewDatabaseWithFreezer creates a high level database on top of a given key-
|
||||||
// value data store with a freezer moving immutable chain segments into cold
|
// value data store with a freezer moving immutable chain segments into cold
|
||||||
// storage. The passed ancient indicates the path of root ancient directory
|
// 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 != "" {
|
if chainFreezerDir != "" {
|
||||||
chainFreezerDir = resolveChainFreezerDir(chainFreezerDir)
|
chainFreezerDir = resolveChainFreezerDir(chainFreezerDir)
|
||||||
}
|
}
|
||||||
|
if chainFreezerDir != "" {
|
||||||
|
eraDir = resolveChainEraDir(chainFreezerDir, eraDir)
|
||||||
|
}
|
||||||
frdb, err := newChainFreezer(chainFreezerDir, namespace, readonly, eraDir)
|
frdb, err := newChainFreezer(chainFreezerDir, namespace, readonly, eraDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printChainMetadata(db)
|
printChainMetadata(db)
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func New(datadir string) (*EraDatabase, error) {
|
||||||
// opened multiple times.
|
// opened multiple times.
|
||||||
db.cache.OnReplaced(closeEra)
|
db.cache.OnReplaced(closeEra)
|
||||||
|
|
||||||
log.Info("Opened erastore", "datadir", datadir)
|
log.Info("Opened Era store", "datadir", datadir)
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,14 @@ type openOptions struct {
|
||||||
Type string // "leveldb" | "pebble"
|
Type string // "leveldb" | "pebble"
|
||||||
Directory string // the datadir
|
Directory string // the datadir
|
||||||
AncientsDirectory string // the ancients-dir
|
AncientsDirectory string // the ancients-dir
|
||||||
EraDirectory string
|
|
||||||
Namespace string // the namespace for database relevant metrics
|
// The optional Era folder, which can be either a subfolder under
|
||||||
Cache int // the capacity(in megabytes) of the data caching
|
// ancient/chain or a directory specified via an absolute path.
|
||||||
Handles int // number of files to be open simultaneously
|
EraDirectory string
|
||||||
ReadOnly bool
|
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
|
// 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.
|
// 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 non-existent | pebble default | specified type
|
||||||
// db is existent | from db | specified type (if compatible)
|
// db is existent | from db | specified type (if compatible)
|
||||||
func openKeyValueDatabase(o openOptions) (ethdb.Database, error) {
|
func openKeyValueDatabase(o openOptions) (ethdb.Database, error) {
|
||||||
|
|
|
||||||
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,
|
Type: n.config.DBEngine,
|
||||||
Directory: n.ResolvePath(name),
|
Directory: n.ResolvePath(name),
|
||||||
AncientsDirectory: n.ResolveAncient(name, ancient),
|
AncientsDirectory: n.ResolveAncient(name, ancient),
|
||||||
EraDirectory: n.ResolveEraDirectory(ancient, era),
|
EraDirectory: era,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Cache: cache,
|
Cache: cache,
|
||||||
Handles: handles,
|
Handles: handles,
|
||||||
|
|
@ -775,17 +775,6 @@ func (n *Node) ResolveAncient(name string, ancient string) string {
|
||||||
return ancient
|
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
|
// 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
|
// 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.
|
// won't auto-close the database if it is closed by the service that opened it.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue