From ff247428afefc5c5c78bffac0368cd48d3c6dc16 Mon Sep 17 00:00:00 2001 From: gary Date: Fri, 22 May 2026 13:45:40 +0800 Subject: [PATCH] core/rawdb: fix db inspect --- core/rawdb/ancient_utils.go | 66 +++++++++++++++++-------------------- core/rawdb/database.go | 4 +-- 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index 914ad9f6d8..32d5eeb90b 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -24,24 +24,23 @@ import ( "github.com/ethereum/go-ethereum/ethdb" ) -type tableSize struct { - name string - size common.StorageSize +type tableInfo struct { + name string + size common.StorageSize + count uint64 } // freezerInfo contains the basic information of the freezer. type freezerInfo struct { - name string // The identifier of freezer - head uint64 // The number of last stored item in the freezer - tail uint64 // The number of first stored item in the freezer - count uint64 // The number of stored items in the freezer - sizes []tableSize // The storage size per table + name string // The identifier of freezer + head uint64 // The number of last stored item in the freezer + tables []tableInfo // Per-table storage size and item count } // size returns the storage size of the entire freezer. func (info *freezerInfo) size() common.StorageSize { var total common.StorageSize - for _, table := range info.sizes { + for _, table := range info.tables { total += table.size } return total @@ -49,46 +48,41 @@ func (info *freezerInfo) size() common.StorageSize { func inspect(name string, order map[string]freezerTableConfig, reader ethdb.AncientReader) (freezerInfo, error) { info := freezerInfo{name: name} - for t := range order { - size, err := reader.AncientSize(t) - if err != nil { - return freezerInfo{}, err - } - info.sizes = append(info.sizes, tableSize{name: t, size: common.StorageSize(size)}) - } - // Retrieve the number of last stored item + + // Retrieve the number of last stored item. ancients, err := reader.Ancients() if err != nil { return freezerInfo{}, err } if ancients > 0 { info.head = ancients - 1 - } else { - info.head = 0 } - - // Retrieve the highest tail across all known tail groups. The inspected - // freezer info uses a single tail value for display, which corresponds to - // the most-pruned group. - groups := make(map[string]struct{}) + // Resolve per-group tails so each table can report its own item count. + groupTails := make(map[string]uint64) for _, cfg := range order { - if cfg.tailGroup != "" { - groups[cfg.tailGroup] = struct{}{} + if cfg.tailGroup == "" { + continue } - } - for g := range groups { - t, err := reader.Tail(g) + if _, ok := groupTails[cfg.tailGroup]; ok { + continue + } + t, err := reader.Tail(cfg.tailGroup) if err != nil { return freezerInfo{}, err } - if t > info.tail { - info.tail = t - } + groupTails[cfg.tailGroup] = t } - if ancients == 0 { - info.count = 0 - } else { - info.count = info.head - info.tail + 1 + for t, cfg := range order { + size, err := reader.AncientSize(t) + if err != nil { + return freezerInfo{}, err + } + var count uint64 + if ancients > 0 { + tail := groupTails[cfg.tailGroup] // 0 for non-prunable tables + count = ancients - tail + } + info.tables = append(info.tables, tableInfo{name: t, size: common.StorageSize(size), count: count}) } return info, nil } diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 9e49ee23dd..57abcdb25d 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -658,12 +658,12 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { return err } for _, ancient := range ancients { - for _, table := range ancient.sizes { + for _, table := range ancient.tables { stats = append(stats, []string{ fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)), strings.Title(table.name), table.size.String(), - fmt.Sprintf("%d", ancient.count), + fmt.Sprintf("%d", table.count), }) } total.Add(uint64(ancient.size()))