forked from cerc-io/plugeth
core, eth, trie: expose more detailed dirty ram tracking for diff layers (#27971)
This commit is contained in:
+14
-10
@@ -55,9 +55,12 @@ type backend interface {
|
||||
// according to the state scheme.
|
||||
Initialized(genesisRoot common.Hash) bool
|
||||
|
||||
// Size returns the current storage size of the memory cache in front of the
|
||||
// persistent database layer.
|
||||
Size() common.StorageSize
|
||||
// Size returns the current storage size of the diff layers on top of the
|
||||
// disk layer and the storage size of the nodes cached in the disk layer.
|
||||
//
|
||||
// For hash scheme, there is no differentiation between diff layer nodes
|
||||
// and dirty disk layer nodes, so both are merged into the second return.
|
||||
Size() (common.StorageSize, common.StorageSize)
|
||||
|
||||
// Update performs a state transition by committing dirty nodes contained
|
||||
// in the given set in order to update state from the specified parent to
|
||||
@@ -165,18 +168,19 @@ func (db *Database) Commit(root common.Hash, report bool) error {
|
||||
return db.backend.Commit(root, report)
|
||||
}
|
||||
|
||||
// Size returns the storage size of dirty trie nodes in front of the persistent
|
||||
// database and the size of cached preimages.
|
||||
func (db *Database) Size() (common.StorageSize, common.StorageSize) {
|
||||
// Size returns the storage size of diff layer nodes above the persistent disk
|
||||
// layer, the dirty nodes buffered within the disk layer, and the size of cached
|
||||
// preimages.
|
||||
func (db *Database) Size() (common.StorageSize, common.StorageSize, common.StorageSize) {
|
||||
var (
|
||||
storages common.StorageSize
|
||||
preimages common.StorageSize
|
||||
diffs, nodes common.StorageSize
|
||||
preimages common.StorageSize
|
||||
)
|
||||
storages = db.backend.Size()
|
||||
diffs, nodes = db.backend.Size()
|
||||
if db.preimages != nil {
|
||||
preimages = db.preimages.size()
|
||||
}
|
||||
return storages, preimages
|
||||
return diffs, nodes, preimages
|
||||
}
|
||||
|
||||
// Initialized returns an indicator if the state data is already initialized
|
||||
|
||||
@@ -624,7 +624,10 @@ func (db *Database) Update(root common.Hash, parent common.Hash, block uint64, n
|
||||
|
||||
// Size returns the current storage size of the memory cache in front of the
|
||||
// persistent database layer.
|
||||
func (db *Database) Size() common.StorageSize {
|
||||
//
|
||||
// The first return will always be 0, representing the memory stored in unbounded
|
||||
// diff layers above the dirty cache. This is only available in pathdb.
|
||||
func (db *Database) Size() (common.StorageSize, common.StorageSize) {
|
||||
db.lock.RLock()
|
||||
defer db.lock.RUnlock()
|
||||
|
||||
@@ -632,7 +635,7 @@ func (db *Database) Size() common.StorageSize {
|
||||
// the total memory consumption, the maintenance metadata is also needed to be
|
||||
// counted.
|
||||
var metadataSize = common.StorageSize(len(db.dirties) * cachedNodeSize)
|
||||
return db.dirtiesSize + db.childrenSize + metadataSize
|
||||
return 0, db.dirtiesSize + db.childrenSize + metadataSize
|
||||
}
|
||||
|
||||
// Close closes the trie database and releases all held resources.
|
||||
|
||||
@@ -383,16 +383,16 @@ func (db *Database) Close() error {
|
||||
|
||||
// Size returns the current storage size of the memory cache in front of the
|
||||
// persistent database layer.
|
||||
func (db *Database) Size() (size common.StorageSize) {
|
||||
func (db *Database) Size() (diffs common.StorageSize, nodes common.StorageSize) {
|
||||
db.tree.forEach(func(layer layer) {
|
||||
if diff, ok := layer.(*diffLayer); ok {
|
||||
size += common.StorageSize(diff.memory)
|
||||
diffs += common.StorageSize(diff.memory)
|
||||
}
|
||||
if disk, ok := layer.(*diskLayer); ok {
|
||||
size += disk.size()
|
||||
nodes += disk.size()
|
||||
}
|
||||
})
|
||||
return size
|
||||
return diffs, nodes
|
||||
}
|
||||
|
||||
// Initialized returns an indicator if the state data is already
|
||||
|
||||
Reference in New Issue
Block a user