mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56: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"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -89,7 +90,13 @@ Remove blockchain and state databases`,
|
||||||
Action: inspect,
|
Action: inspect,
|
||||||
Name: "inspect",
|
Name: "inspect",
|
||||||
ArgsUsage: "<prefix> <start>",
|
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",
|
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.`,
|
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)
|
db := utils.MakeChainDatabase(ctx, stack, true)
|
||||||
defer db.Close()
|
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 {
|
func checkStateContent(ctx *cli.Context) error {
|
||||||
|
|
|
||||||
|
|
@ -394,7 +394,7 @@ func (s *stat) GetCount() counter {
|
||||||
|
|
||||||
// InspectDatabase traverses the entire database and checks the size
|
// InspectDatabase traverses the entire database and checks the size
|
||||||
// of all different categories of data.
|
// 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 (
|
var (
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
|
|
||||||
|
|
@ -538,20 +538,17 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
||||||
return it.Error()
|
return it.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create error group for parallel processing
|
var eg errgroup.Group
|
||||||
var g 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++ {
|
for i := 0; i < 256; i++ {
|
||||||
rangePrefix := []byte{byte(i)}
|
rangePrefix := []byte{byte(i)}
|
||||||
g.Go(func() error {
|
eg.Go(func() error { return processRange(rangePrefix) })
|
||||||
return processRange(rangePrefix)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for all workers to complete
|
if err := eg.Wait(); err != nil {
|
||||||
if err := g.Wait(); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -613,7 +610,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
||||||
table.AppendBulk(stats)
|
table.AppendBulk(stats)
|
||||||
table.Render()
|
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 {
|
if unaccounted.GetSize() > 0 {
|
||||||
log.Error("Database contains unaccounted data", "size", unaccounted.GetSize(), "count", unaccounted.GetCount())
|
log.Error("Database contains unaccounted data", "size", unaccounted.GetSize(), "count", unaccounted.GetCount())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue