From fb2c4c3c5256ea291fb36c9fa5f6d937bfb289d1 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Thu, 28 Aug 2025 06:43:45 +0000 Subject: [PATCH] use atomic.Uint64 Signed-off-by: jsvisa --- core/rawdb/database.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/rawdb/database.go b/core/rawdb/database.go index f39710d730..b2d776a01d 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -433,8 +433,8 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { unaccounted stat // Totals - totalSize uint64 - totalCount int64 + totalSize atomic.Uint64 + totalCount atomic.Int64 unaccountedKeys = make(map[[2]byte][]byte) unaccountedMu sync.Mutex @@ -450,8 +450,8 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { key = it.Key() size = common.StorageSize(len(key) + len(it.Value())) ) - atomic.AddUint64(&totalSize, uint64(size)) - atomic.AddInt64(&totalCount, 1) + totalSize.Add(uint64(size)) + totalCount.Add(1) switch { 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()), }) } - atomic.AddUint64(&totalSize, uint64(ancient.size())) + totalSize.Add(uint64(ancient.size())) } table := newTableWriter(os.Stdout) 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.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 { log.Error("Database contains unaccounted data", "size", unaccounted.GetSize(), "count", unaccounted.GetCount())