Skip to content

Commit

Permalink
revert additional locking in hashdb/Database.Cap
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Oct 11, 2023
1 parent 202caf5 commit 0c3b1c2
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions trie/triedb/hashdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,23 +331,19 @@ func (db *Database) Cap(limit common.StorageSize) error {
// by only uncaching existing data when the database write finalizes.
start := time.Now()
batch := db.diskdb.NewBatch()
db.lock.RLock()
nodes, storage := len(db.dirties), db.dirtiesSize

// db.dirtiesSize only contains the useful data in the cache, but when reporting
// the total memory consumption, the maintenance metadata is also needed to be
// counted.
size := db.dirtiesSize + common.StorageSize(len(db.dirties)*cachedNodeSize)
size += db.childrenSize
db.lock.RUnlock()

// Keep committing nodes from the flush-list until we're below allowance
oldest := db.oldest
for size > limit && oldest != (common.Hash{}) {
// Fetch the oldest referenced node and push into the batch
db.lock.RLock()
node := db.dirties[oldest]
db.lock.RUnlock()
rawdb.WriteLegacyTrieNode(batch, oldest, node.node)

// If we exceeded the ideal batch size, commit and reset
Expand Down

0 comments on commit 0c3b1c2

Please sign in to comment.