cmd/geth: add db commands stats, compact, put, get, delete (#22014)

This PR introduces:

- db.put to put a value into the database
- db.get to read a value from the database
- db.delete to delete a value from the database
- db.stats to check compaction info from the database
- db.compact to trigger a db compaction

It also moves inspectdb to db.inspect.
This commit is contained in:
Martin Holst Swende
2021-02-23 11:27:32 +01:00
committed by GitHub
parent 3ecfdccd9a
commit c4a2b682ff
7 changed files with 401 additions and 152 deletions

View File

@ -270,8 +270,8 @@ func (s *stat) Count() string {
// InspectDatabase traverses the entire database and checks the size
// of all different categories of data.
func InspectDatabase(db ethdb.Database) error {
it := db.NewIterator(nil, nil)
func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
it := db.NewIterator(keyPrefix, keyStart)
defer it.Release()
var (
@ -307,8 +307,9 @@ func InspectDatabase(db ethdb.Database) error {
bloomTrieNodes stat
// Meta- and unaccounted data
metadata stat
unaccounted stat
metadata stat
unaccounted stat
shutdownInfo stat
// Totals
total common.StorageSize
@ -359,6 +360,8 @@ func InspectDatabase(db ethdb.Database) error {
bytes.HasPrefix(key, []byte("bltIndex-")) ||
bytes.HasPrefix(key, []byte("bltRoot-")): // Bloomtrie sub
bloomTrieNodes.Add(size)
case bytes.Equal(key, uncleanShutdownKey):
shutdownInfo.Add(size)
default:
var accounted bool
for _, meta := range [][]byte{
@ -413,6 +416,7 @@ func InspectDatabase(db ethdb.Database) error {
{"Key-Value store", "Storage snapshot", storageSnaps.Size(), storageSnaps.Count()},
{"Key-Value store", "Clique snapshots", cliqueSnaps.Size(), cliqueSnaps.Count()},
{"Key-Value store", "Singleton metadata", metadata.Size(), metadata.Count()},
{"Key-Value store", "Shutdown metadata", shutdownInfo.Size(), shutdownInfo.Count()},
{"Ancient store", "Headers", ancientHeadersSize.String(), ancients.String()},
{"Ancient store", "Bodies", ancientBodiesSize.String(), ancients.String()},
{"Ancient store", "Receipt lists", ancientReceiptsSize.String(), ancients.String()},