mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
inspect --workers
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
fb2c4c3c52
commit
1b0289c6c6
2 changed files with 18 additions and 13 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -89,7 +90,13 @@ Remove blockchain and state databases`,
|
|||
Action: inspect,
|
||||
Name: "inspect",
|
||||
ArgsUsage: "<prefix> <start>",
|
||||
Flags: slices.Concat(utils.NetworkFlags, utils.DatabaseFlags),
|
||||
Flags: slices.Concat(utils.NetworkFlags, utils.DatabaseFlags, []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
Name: "workers",
|
||||
Usage: "Number of parallel workers for database inspection",
|
||||
Value: runtime.NumCPU(),
|
||||
},
|
||||
}),
|
||||
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.`,
|
||||
}
|
||||
|
|
@ -329,7 +336,8 @@ func inspect(ctx *cli.Context) error {
|
|||
db := utils.MakeChainDatabase(ctx, stack, true)
|
||||
defer db.Close()
|
||||
|
||||
return rawdb.InspectDatabase(db, prefix, start)
|
||||
workers := ctx.Int("workers")
|
||||
return rawdb.InspectDatabase(db, prefix, start, workers)
|
||||
}
|
||||
|
||||
func checkStateContent(ctx *cli.Context) error {
|
||||
|
|
|
|||
|
|
@ -394,7 +394,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) error {
|
||||
func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte, workers int) error {
|
||||
var (
|
||||
start = time.Now()
|
||||
|
||||
|
|
@ -538,20 +538,17 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
|||
return it.Error()
|
||||
}
|
||||
|
||||
// Create error group for parallel processing
|
||||
var g errgroup.Group
|
||||
var eg errgroup.Group
|
||||
eg.SetLimit(workers)
|
||||
|
||||
log.Info("Starting parallel database inspection", "workers", workers)
|
||||
|
||||
// Split key space into 256 ranges (0x00 to 0xFF)
|
||||
log.Info("Starting parallel database inspection", "workers", 256)
|
||||
for i := 0; i < 256; i++ {
|
||||
rangePrefix := []byte{byte(i)}
|
||||
g.Go(func() error {
|
||||
return processRange(rangePrefix)
|
||||
})
|
||||
eg.Go(func() error { return processRange(rangePrefix) })
|
||||
}
|
||||
|
||||
// Wait for all workers to complete
|
||||
if err := g.Wait(); err != nil {
|
||||
if err := eg.Wait(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -613,7 +610,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
|||
table.AppendBulk(stats)
|
||||
table.Render()
|
||||
|
||||
log.Info("Parallel database inspection completed", "total_entries", totalCount.Load(), "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
log.Info("Database inspection completed", "count", totalCount.Load(), "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
|
||||
if unaccounted.GetSize() > 0 {
|
||||
log.Error("Database contains unaccounted data", "size", unaccounted.GetSize(), "count", unaccounted.GetCount())
|
||||
|
|
|
|||
Loading…
Reference in a new issue