diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index 8c6f9532e8..44a52521f0 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -22,7 +22,6 @@ import ( "os" "os/signal" "path/filepath" - "runtime" "slices" "strconv" "strings" @@ -87,16 +86,10 @@ Remove blockchain and state databases`, }, } dbInspectCmd = &cli.Command{ - Action: inspect, - Name: "inspect", - ArgsUsage: " ", - Flags: slices.Concat(utils.NetworkFlags, utils.DatabaseFlags, []cli.Flag{ - &cli.IntFlag{ - Name: "workers", - Usage: "Number of parallel workers for database inspection", - Value: runtime.NumCPU(), - }, - }), + Action: inspect, + Name: "inspect", + ArgsUsage: " ", + Flags: slices.Concat(utils.NetworkFlags, utils.DatabaseFlags), Usage: "Inspect the storage size for each type of data in the database", Description: `This commands iterates the entire database. If the optional 'prefix' and 'start' arguments are provided, then the iteration is limited to the given subset of data.`, } @@ -336,8 +329,7 @@ func inspect(ctx *cli.Context) error { db := utils.MakeChainDatabase(ctx, stack, true) defer db.Close() - workers := ctx.Int("workers") - return rawdb.InspectDatabase(db, prefix, start, workers) + return rawdb.InspectDatabase(db, prefix, start) } func checkStateContent(ctx *cli.Context) error { diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 4c7e1f442c..7b972e50e1 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -23,6 +23,7 @@ import ( "maps" "os" "path/filepath" + "runtime" "slices" "strings" "sync" @@ -395,7 +396,7 @@ func (s *stat) GetCount() counter { // InspectDatabase traverses the entire database and checks the size // of all different categories of data. -func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte, workers int) error { +func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { var ( start = time.Now() count atomic.Int64 @@ -550,7 +551,10 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte, workers int) return it.Error() } - var eg errgroup.Group + var ( + eg errgroup.Group + workers = runtime.NumCPU() + ) eg.SetLimit(workers) log.Info("Starting parallel database inspection", "workers", workers)