aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/chaincmd.go111
-rw-r--r--cmd/geth/main.go2
-rw-r--r--cmd/geth/usage.go1
3 files changed, 89 insertions, 25 deletions
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go
index 582f0b768..c91545c7f 100644
--- a/cmd/geth/chaincmd.go
+++ b/cmd/geth/chaincmd.go
@@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"os"
+ "path/filepath"
"runtime"
"strconv"
"sync/atomic"
@@ -167,6 +168,22 @@ Remove blockchain and state databases`,
The arguments are interpreted as block numbers or hashes.
Use "ethereum dump 0" to dump the genesis block.`,
}
+ inspectCommand = cli.Command{
+ Action: utils.MigrateFlags(inspect),
+ Name: "inspect",
+ Usage: "Inspect the storage size for each type of data in the database",
+ ArgsUsage: " ",
+ Flags: []cli.Flag{
+ utils.DataDirFlag,
+ utils.AncientFlag,
+ utils.CacheFlag,
+ utils.TestnetFlag,
+ utils.RinkebyFlag,
+ utils.GoerliFlag,
+ utils.SyncModeFlag,
+ },
+ Category: "BLOCKCHAIN COMMANDS",
+ }
)
// initGenesis will initialise the given JSON format genesis file and writes it as
@@ -368,9 +385,12 @@ func exportPreimages(ctx *cli.Context) error {
func copyDb(ctx *cli.Context) error {
// Ensure we have a source chain directory to copy
- if len(ctx.Args()) != 1 {
+ if len(ctx.Args()) < 1 {
utils.Fatalf("Source chaindata directory path argument missing")
}
+ if len(ctx.Args()) < 2 {
+ utils.Fatalf("Source ancient chain directory path argument missing")
+ }
// Initialize a new chain for the running node to sync into
stack := makeFullNode(ctx)
defer stack.Close()
@@ -385,7 +405,7 @@ func copyDb(ctx *cli.Context) error {
dl := downloader.New(0, chainDb, syncBloom, new(event.TypeMux), chain, nil, nil)
// Create a source peer to satisfy downloader requests from
- db, err := rawdb.NewLevelDBDatabase(ctx.Args().First(), ctx.GlobalInt(utils.CacheFlag.Name)/2, 256, "")
+ db, err := rawdb.NewLevelDBDatabaseWithFreezer(ctx.Args().First(), ctx.GlobalInt(utils.CacheFlag.Name)/2, 256, ctx.Args().Get(1), "")
if err != nil {
return err
}
@@ -420,34 +440,65 @@ func copyDb(ctx *cli.Context) error {
}
func removeDB(ctx *cli.Context) error {
- stack, _ := makeConfigNode(ctx)
+ stack, config := makeConfigNode(ctx)
- for _, name := range []string{"chaindata", "lightchaindata"} {
- // Ensure the database exists in the first place
- logger := log.New("database", name)
-
- dbdir := stack.ResolvePath(name)
- if !common.FileExist(dbdir) {
- logger.Info("Database doesn't exist, skipping", "path", dbdir)
- continue
- }
- // Confirm removal and execute
- fmt.Println(dbdir)
- confirm, err := console.Stdin.PromptConfirm("Remove this database?")
- switch {
- case err != nil:
- utils.Fatalf("%v", err)
- case !confirm:
- logger.Warn("Database deletion aborted")
- default:
- start := time.Now()
- os.RemoveAll(dbdir)
- logger.Info("Database successfully deleted", "elapsed", common.PrettyDuration(time.Since(start)))
- }
+ // Remove the full node state database
+ path := stack.ResolvePath("chaindata")
+ if common.FileExist(path) {
+ confirmAndRemoveDB(path, "full node state database")
+ } else {
+ log.Info("Full node state database missing", "path", path)
+ }
+ // Remove the full node ancient database
+ path = config.Eth.DatabaseFreezer
+ switch {
+ case path == "":
+ path = filepath.Join(stack.ResolvePath("chaindata"), "ancient")
+ case !filepath.IsAbs(path):
+ path = config.Node.ResolvePath(path)
+ }
+ if common.FileExist(path) {
+ confirmAndRemoveDB(path, "full node ancient database")
+ } else {
+ log.Info("Full node ancient database missing", "path", path)
+ }
+ // Remove the light node database
+ path = stack.ResolvePath("lightchaindata")
+ if common.FileExist(path) {
+ confirmAndRemoveDB(path, "light node database")
+ } else {
+ log.Info("Light node database missing", "path", path)
}
return nil
}
+// confirmAndRemoveDB prompts the user for a last confirmation and removes the
+// folder if accepted.
+func confirmAndRemoveDB(database string, kind string) {
+ confirm, err := console.Stdin.PromptConfirm(fmt.Sprintf("Remove %s (%s)?", kind, database))
+ switch {
+ case err != nil:
+ utils.Fatalf("%v", err)
+ case !confirm:
+ log.Info("Database deletion skipped", "path", database)
+ default:
+ start := time.Now()
+ filepath.Walk(database, func(path string, info os.FileInfo, err error) error {
+ // If we're at the top level folder, recurse into
+ if path == database {
+ return nil
+ }
+ // Delete all the files, but not subfolders
+ if !info.IsDir() {
+ os.Remove(path)
+ return nil
+ }
+ return filepath.SkipDir
+ })
+ log.Info("Database successfully deleted", "path", database, "elapsed", common.PrettyDuration(time.Since(start)))
+ }
+}
+
func dump(ctx *cli.Context) error {
stack := makeFullNode(ctx)
defer stack.Close()
@@ -476,6 +527,16 @@ func dump(ctx *cli.Context) error {
return nil
}
+func inspect(ctx *cli.Context) error {
+ node, _ := makeConfigNode(ctx)
+ defer node.Close()
+
+ _, chainDb := utils.MakeChain(ctx, node)
+ defer chainDb.Close()
+
+ return rawdb.InspectDatabase(chainDb)
+}
+
// hashish returns true for strings that look like hashes.
func hashish(x string) bool {
_, err := strconv.Atoi(x)
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 838029333..1b23cbd9f 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -62,6 +62,7 @@ var (
utils.BootnodesV4Flag,
utils.BootnodesV5Flag,
utils.DataDirFlag,
+ utils.AncientFlag,
utils.KeyStoreDirFlag,
utils.ExternalSignerFlag,
utils.NoUSBFlag,
@@ -203,6 +204,7 @@ func init() {
copydbCommand,
removedbCommand,
dumpCommand,
+ inspectCommand,
// See accountcmd.go:
accountCommand,
walletCommand,
diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go
index 7ec1ab03f..67b0027f2 100644
--- a/cmd/geth/usage.go
+++ b/cmd/geth/usage.go
@@ -69,6 +69,7 @@ var AppHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{
configFileFlag,
utils.DataDirFlag,
+ utils.AncientFlag,
utils.KeyStoreDirFlag,
utils.NoUSBFlag,
utils.NetworkIdFlag,