use atomic.Uint64

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-08-28 06:43:45 +00:00
parent 45dd6c5e2c
commit fb2c4c3c52

View file

@ -433,8 +433,8 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
unaccounted stat unaccounted stat
// Totals // Totals
totalSize uint64 totalSize atomic.Uint64
totalCount int64 totalCount atomic.Int64
unaccountedKeys = make(map[[2]byte][]byte) unaccountedKeys = make(map[[2]byte][]byte)
unaccountedMu sync.Mutex unaccountedMu sync.Mutex
@ -450,8 +450,8 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
key = it.Key() key = it.Key()
size = common.StorageSize(len(key) + len(it.Value())) size = common.StorageSize(len(key) + len(it.Value()))
) )
atomic.AddUint64(&totalSize, uint64(size)) totalSize.Add(uint64(size))
atomic.AddInt64(&totalCount, 1) totalCount.Add(1)
switch { switch {
case bytes.HasPrefix(key, headerPrefix) && len(key) == (len(headerPrefix)+8+common.HashLength): case bytes.HasPrefix(key, headerPrefix) && len(key) == (len(headerPrefix)+8+common.HashLength):
@ -604,16 +604,16 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
fmt.Sprintf("%d", ancient.count()), fmt.Sprintf("%d", ancient.count()),
}) })
} }
atomic.AddUint64(&totalSize, uint64(ancient.size())) totalSize.Add(uint64(ancient.size()))
} }
table := newTableWriter(os.Stdout) table := newTableWriter(os.Stdout)
table.SetHeader([]string{"Database", "Category", "Size", "Items"}) table.SetHeader([]string{"Database", "Category", "Size", "Items"})
table.SetFooter([]string{"", "Total", common.StorageSize(atomic.LoadUint64(&totalSize)).String(), fmt.Sprintf("%d", atomic.LoadInt64(&totalCount))}) table.SetFooter([]string{"", "Total", common.StorageSize(totalSize.Load()).String(), fmt.Sprintf("%d", totalCount.Load())})
table.AppendBulk(stats) table.AppendBulk(stats)
table.Render() table.Render()
log.Info("Parallel database inspection completed", "total_entries", atomic.LoadInt64(&totalCount), "elapsed", common.PrettyDuration(time.Since(start))) log.Info("Parallel database inspection completed", "total_entries", 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())