-
Notifications
You must be signed in to change notification settings - Fork 20.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core/rawdb: improve database stats output #31463
Merged
+94
−54
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74bdd7c
core/rawdb: add database stats for filtermaps
fjl 00e72b4
core/rawdb: fix precise filtermaps inspect
fjl e6bdfc8
core/rawdb: put back reporting of bloombits data in InspectDatabase
fjl ce59ba5
core/rawdb: shorten text
fjl 000460b
core/rawdb: improve tracking on unaccounted keys
fjl 7ca68af
core/rawdb: fix tracking of filtermaps row keys
fjl 2103b17
core/rawdb: improve condition
fjl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,10 @@ import ( | |
"bytes" | ||
"errors" | ||
"fmt" | ||
"maps" | ||
"os" | ||
"path/filepath" | ||
"slices" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -360,24 +362,27 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { | |
logged = time.Now() | ||
|
||
// Key-value store statistics | ||
headers stat | ||
bodies stat | ||
receipts stat | ||
tds stat | ||
numHashPairings stat | ||
hashNumPairings stat | ||
legacyTries stat | ||
stateLookups stat | ||
accountTries stat | ||
storageTries stat | ||
codes stat | ||
txLookups stat | ||
accountSnaps stat | ||
storageSnaps stat | ||
preimages stat | ||
filterMaps stat | ||
beaconHeaders stat | ||
cliqueSnaps stat | ||
headers stat | ||
bodies stat | ||
receipts stat | ||
tds stat | ||
numHashPairings stat | ||
hashNumPairings stat | ||
legacyTries stat | ||
stateLookups stat | ||
accountTries stat | ||
storageTries stat | ||
codes stat | ||
txLookups stat | ||
accountSnaps stat | ||
storageSnaps stat | ||
preimages stat | ||
beaconHeaders stat | ||
cliqueSnaps stat | ||
bloomBits stat | ||
filterMapRows stat | ||
filterMapLastBlock stat | ||
filterMapBlockLV stat | ||
|
||
// Verkle statistics | ||
verkleTries stat | ||
|
@@ -393,6 +398,11 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { | |
|
||
// Totals | ||
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. | ||
for it.Next() { | ||
|
@@ -436,19 +446,33 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { | |
metadata.Add(size) | ||
case bytes.HasPrefix(key, genesisPrefix) && len(key) == (len(genesisPrefix)+common.HashLength): | ||
metadata.Add(size) | ||
case bytes.HasPrefix(key, []byte(filterMapsPrefix)): | ||
filterMaps.Add(size) | ||
case bytes.HasPrefix(key, skeletonHeaderPrefix) && len(key) == (len(skeletonHeaderPrefix)+8): | ||
beaconHeaders.Add(size) | ||
case bytes.HasPrefix(key, CliqueSnapshotPrefix) && len(key) == 7+common.HashLength: | ||
cliqueSnaps.Add(size) | ||
case bytes.HasPrefix(key, ChtTablePrefix) || | ||
bytes.HasPrefix(key, ChtIndexTablePrefix) || | ||
bytes.HasPrefix(key, ChtPrefix): // Canonical hash trie | ||
|
||
// new log index | ||
case bytes.HasPrefix(key, filterMapRowPrefix) && len(key) <= len(filterMapRowPrefix)+9: | ||
filterMapRows.Add(size) | ||
case bytes.HasPrefix(key, filterMapLastBlockPrefix) && len(key) == len(filterMapLastBlockPrefix)+4: | ||
filterMapLastBlock.Add(size) | ||
case bytes.HasPrefix(key, filterMapBlockLVPrefix) && len(key) == len(filterMapBlockLVPrefix)+8: | ||
filterMapBlockLV.Add(size) | ||
|
||
// old log index (deprecated) | ||
case bytes.HasPrefix(key, bloomBitsPrefix) && len(key) == (len(bloomBitsPrefix)+10+common.HashLength): | ||
bloomBits.Add(size) | ||
case bytes.HasPrefix(key, bloomBitsMetaPrefix) && len(key) < len(bloomBitsMetaPrefix)+8: | ||
bloomBits.Add(size) | ||
|
||
// LES indexes (deprecated) | ||
case bytes.HasPrefix(key, chtTablePrefix) || | ||
bytes.HasPrefix(key, chtIndexTablePrefix) || | ||
bytes.HasPrefix(key, chtPrefix): // Canonical hash trie | ||
chtTrieNodes.Add(size) | ||
case bytes.HasPrefix(key, BloomTrieTablePrefix) || | ||
bytes.HasPrefix(key, BloomTrieIndexPrefix) || | ||
bytes.HasPrefix(key, BloomTriePrefix): // Bloomtrie sub | ||
case bytes.HasPrefix(key, bloomTrieTablePrefix) || | ||
bytes.HasPrefix(key, bloomTrieIndexPrefix) || | ||
bytes.HasPrefix(key, bloomTriePrefix): // Bloomtrie sub | ||
bloomTrieNodes.Add(size) | ||
|
||
// Verkle trie data is detected, determine the sub-category | ||
|
@@ -468,24 +492,19 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { | |
default: | ||
unaccounted.Add(size) | ||
} | ||
|
||
// Metadata keys | ||
case slices.ContainsFunc(knownMetadataKeys, func(x []byte) bool { return bytes.Equal(x, key) }): | ||
metadata.Add(size) | ||
|
||
default: | ||
var accounted bool | ||
for _, meta := range [][]byte{ | ||
databaseVersionKey, headHeaderKey, headBlockKey, headFastBlockKey, headFinalizedBlockKey, | ||
lastPivotKey, fastTrieProgressKey, snapshotDisabledKey, SnapshotRootKey, snapshotJournalKey, | ||
snapshotGeneratorKey, snapshotRecoveryKey, txIndexTailKey, fastTxLookupLimitKey, | ||
uncleanShutdownKey, badBlockKey, transitionStatusKey, skeletonSyncStatusKey, | ||
persistentStateIDKey, trieJournalKey, snapshotSyncStatusKey, snapSyncStatusFlagKey, | ||
} { | ||
if bytes.Equal(key, meta) { | ||
metadata.Add(size) | ||
accounted = true | ||
break | ||
unaccounted.Add(size) | ||
if len(key) >= 2 { | ||
prefix := [2]byte(key[:2]) | ||
if _, ok := unaccountedKeys[prefix]; !ok { | ||
unaccountedKeys[prefix] = bytes.Clone(key) | ||
} | ||
} | ||
if !accounted { | ||
unaccounted.Add(size) | ||
} | ||
} | ||
count++ | ||
if count%1000 == 0 && time.Since(logged) > 8*time.Second { | ||
|
@@ -502,7 +521,10 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { | |
{"Key-Value store", "Block number->hash", numHashPairings.Size(), numHashPairings.Count()}, | ||
{"Key-Value store", "Block hash->number", hashNumPairings.Size(), hashNumPairings.Count()}, | ||
{"Key-Value store", "Transaction index", txLookups.Size(), txLookups.Count()}, | ||
{"Key-Value store", "Log search index", filterMaps.Size(), filterMaps.Count()}, | ||
{"Key-Value store", "Log index filter-map rows", filterMapRows.Size(), filterMapRows.Count()}, | ||
{"Key-Value store", "Log index last-block-of-map", filterMapLastBlock.Size(), filterMapLastBlock.Count()}, | ||
{"Key-Value store", "Log index block-lv", filterMapBlockLV.Size(), filterMapBlockLV.Count()}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does LV denote There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it means logvalue |
||
{"Key-Value store", "Log bloombits (deprecated)", bloomBits.Size(), bloomBits.Count()}, | ||
{"Key-Value store", "Contract codes", codes.Size(), codes.Count()}, | ||
{"Key-Value store", "Hash trie nodes", legacyTries.Size(), legacyTries.Count()}, | ||
{"Key-Value store", "Path trie state lookups", stateLookups.Size(), stateLookups.Count()}, | ||
|
@@ -543,10 +565,23 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { | |
|
||
if unaccounted.size > 0 { | ||
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 | ||
} | ||
|
||
// 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. | ||
func printChainMetadata(db ethdb.KeyValueStore) { | ||
fmt.Fprintf(os.Stderr, "Chain metadata\n") | ||
|
@@ -566,6 +601,7 @@ func ReadChainMetadata(db ethdb.KeyValueStore) [][]string { | |
} | ||
return fmt.Sprintf("%d (%#x)", *val, *val) | ||
} | ||
|
||
data := [][]string{ | ||
{"databaseVersion", pp(ReadDatabaseVersion(db))}, | ||
{"headBlockHash", fmt.Sprintf("%v", ReadHeadBlockHash(db))}, | ||
|
@@ -582,5 +618,8 @@ func ReadChainMetadata(db ethdb.KeyValueStore) [][]string { | |
if b := ReadSkeletonSyncStatus(db); b != nil { | ||
data = append(data, []string{"SkeletonSyncStatus", string(b)}) | ||
} | ||
if fmr, ok, _ := ReadFilterMapsRange(db); ok { | ||
data = append(data, []string{"filterMapsRange", fmt.Sprintf("%+v", fmr)}) | ||
} | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we deprecate the LES stats by any chance?