Skip to content
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

trie: handle more batch commit errors in Database #25674

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,9 @@ func (db *Database) Commit(node common.Hash, report bool, callback func(common.H
// Uncache any leftovers in the last batch
db.lock.Lock()
defer db.lock.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this up again -- it's nice to keep the Lock() and defer Unlock() right after eachother, it makes it obvious that the pair is complete. And in this instance it doesn't seem to be any particular reason to not do that.

Plus it makes the diff smaller. IMO the section here could look like this:

db.lock.Lock()
defer db.lock.Unlock()
if err := batch.Replay(uncacher); err != nil{
    return err
}
batch.Reset


batch.Replay(uncacher)
if err := batch.Replay(uncacher); err != nil {
return err
}
batch.Reset()

// Reset the storage counters and bumped metrics
Expand Down Expand Up @@ -711,9 +712,12 @@ func (db *Database) commit(hash common.Hash, batch ethdb.Batch, uncacher *cleane
return err
}
db.lock.Lock()
batch.Replay(uncacher)
err := batch.Replay(uncacher)
batch.Reset()
db.lock.Unlock()
if err != nil {
return err
}
}
return nil
}
Expand Down