mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
cmd/geth: report disk space cleared on prune-history completion
Fixes #31916. Snapshot the on-disk size of the prunable chain-freezer tables (bodies and receipts) before and after the prune step, and include the delta as cleared= on the existing "History pruning completed" log line. Operators see the impact of the run immediately without inspecting the data directory by hand. The header and hash tables are intentionally excluded from the measurement because they are configured with prunable=false and are never truncated. If AncientSize fails for any table the helper returns 0 so the log shows "cleared=0.00 B" rather than a partial, misleading figure.
This commit is contained in:
parent
21c5a287f9
commit
5984bde7c4
1 changed files with 25 additions and 1 deletions
|
|
@ -775,17 +775,41 @@ func pruneHistory(ctx *cli.Context) error {
|
|||
|
||||
log.Info("Starting history pruning", "head", currentHeader.Number, "target", targetBlock, "targetHash", targetBlockHash.Hex())
|
||||
start := time.Now()
|
||||
sizeBefore := prunableFreezerSize(chaindb)
|
||||
rawdb.PruneTransactionIndex(chaindb, targetBlock)
|
||||
if _, err := chaindb.TruncateTail(targetBlock); err != nil {
|
||||
return fmt.Errorf("failed to truncate ancient data: %v", err)
|
||||
}
|
||||
log.Info("History pruning completed", "tail", targetBlock, "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
sizeAfter := prunableFreezerSize(chaindb)
|
||||
var cleared common.StorageSize
|
||||
if sizeBefore > sizeAfter {
|
||||
cleared = common.StorageSize(sizeBefore - sizeAfter)
|
||||
}
|
||||
log.Info("History pruning completed", "tail", targetBlock, "elapsed", common.PrettyDuration(time.Since(start)), "cleared", cleared)
|
||||
|
||||
// TODO(s1na): what if there is a crash between the two prune operations?
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// prunableFreezerSize returns the total on-disk size of the chain freezer
|
||||
// tables that prune-history truncates (bodies and receipts). The header and
|
||||
// hash tables are retained long-term and are not measured here.
|
||||
func prunableFreezerSize(db ethdb.Database) uint64 {
|
||||
var total uint64
|
||||
for _, table := range []string{rawdb.ChainFreezerBodiesTable, rawdb.ChainFreezerReceiptTable} {
|
||||
size, err := db.AncientSize(table)
|
||||
if err != nil {
|
||||
// If we can't read the size of any prunable table, the delta would
|
||||
// be misleading. Return 0 so the caller logs "cleared=0.00 B" rather
|
||||
// than a partial figure.
|
||||
return 0
|
||||
}
|
||||
total += size
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// downloadEra is the era1 file downloader tool.
|
||||
func downloadEra(ctx *cli.Context) error {
|
||||
flags.CheckExclusive(ctx, eraBlockFlag, eraEpochFlag, eraAllFlag)
|
||||
|
|
|
|||
Loading…
Reference in a new issue