mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-15 16:33:47 +00:00
core/rawdb: improve tracking on unaccounted keys
This commit is contained in:
parent
ce59ba5d38
commit
000460b89e
1 changed files with 30 additions and 16 deletions
|
|
@ -20,8 +20,10 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -396,6 +398,11 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
||||||
|
|
||||||
// Totals
|
// Totals
|
||||||
total common.StorageSize
|
total common.StorageSize
|
||||||
|
|
||||||
|
// This map tracks example keys for unaccounted data.
|
||||||
|
// For each unique two-byte prefix, the first unaccounted key encountered
|
||||||
|
// by the iterator will be stored.
|
||||||
|
unaccountedKeys = make(map[[2]byte][]byte)
|
||||||
)
|
)
|
||||||
// Inspect key-value database first.
|
// Inspect key-value database first.
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
|
|
@ -486,23 +493,17 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
||||||
unaccounted.Add(size)
|
unaccounted.Add(size)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
var accounted bool
|
if slices.ContainsFunc(knownMetadataKeys, func(x []byte) bool { return bytes.Equal(x, key) }) {
|
||||||
for _, meta := range [][]byte{
|
metadata.Add(size)
|
||||||
databaseVersionKey, headHeaderKey, headBlockKey, headFastBlockKey, headFinalizedBlockKey,
|
} else {
|
||||||
lastPivotKey, fastTrieProgressKey, snapshotDisabledKey, SnapshotRootKey, snapshotJournalKey,
|
|
||||||
snapshotGeneratorKey, snapshotRecoveryKey, txIndexTailKey, fastTxLookupLimitKey,
|
|
||||||
uncleanShutdownKey, badBlockKey, transitionStatusKey, skeletonSyncStatusKey,
|
|
||||||
persistentStateIDKey, trieJournalKey, snapshotSyncStatusKey, snapSyncStatusFlagKey,
|
|
||||||
filterMapsRangeKey,
|
|
||||||
} {
|
|
||||||
if bytes.Equal(key, meta) {
|
|
||||||
metadata.Add(size)
|
|
||||||
accounted = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !accounted {
|
|
||||||
unaccounted.Add(size)
|
unaccounted.Add(size)
|
||||||
|
// track unaccounted key examples:
|
||||||
|
if len(key) >= 2 {
|
||||||
|
prefix := [2]byte(key[:2])
|
||||||
|
if _, ok := unaccountedKeys[prefix]; !ok {
|
||||||
|
unaccountedKeys[prefix] = bytes.Clone(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
|
@ -564,10 +565,23 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
||||||
|
|
||||||
if unaccounted.size > 0 {
|
if unaccounted.size > 0 {
|
||||||
log.Error("Database contains unaccounted data", "size", unaccounted.size, "count", unaccounted.count)
|
log.Error("Database contains unaccounted data", "size", unaccounted.size, "count", unaccounted.count)
|
||||||
|
for _, e := range slices.SortedFunc(maps.Values(unaccountedKeys), bytes.Compare) {
|
||||||
|
log.Error(fmt.Sprintf(" example key: %x", e))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the list of known 'metadata' keys stored in the databasse.
|
||||||
|
var knownMetadataKeys = [][]byte{
|
||||||
|
databaseVersionKey, headHeaderKey, headBlockKey, headFastBlockKey, headFinalizedBlockKey,
|
||||||
|
lastPivotKey, fastTrieProgressKey, snapshotDisabledKey, SnapshotRootKey, snapshotJournalKey,
|
||||||
|
snapshotGeneratorKey, snapshotRecoveryKey, txIndexTailKey, fastTxLookupLimitKey,
|
||||||
|
uncleanShutdownKey, badBlockKey, transitionStatusKey, skeletonSyncStatusKey,
|
||||||
|
persistentStateIDKey, trieJournalKey, snapshotSyncStatusKey, snapSyncStatusFlagKey,
|
||||||
|
filterMapsRangeKey,
|
||||||
|
}
|
||||||
|
|
||||||
// printChainMetadata prints out chain metadata to stderr.
|
// printChainMetadata prints out chain metadata to stderr.
|
||||||
func printChainMetadata(db ethdb.KeyValueStore) {
|
func printChainMetadata(db ethdb.KeyValueStore) {
|
||||||
fmt.Fprintf(os.Stderr, "Chain metadata\n")
|
fmt.Fprintf(os.Stderr, "Chain metadata\n")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue