Skip to content

Commit

Permalink
core/rawdb: improve freezerTable.Sync (ethereum#26245)
Browse files Browse the repository at this point in the history
While investigating ethereum#22374, I noticed that the Sync operation of the
freezer does not take the table lock. It also doesn't call sync for all files
if there is an error with one of them. I doubt this will fix anything, but
didn't want to drop the fix on the floor either.

(cherry picked from commit 193f350)
  • Loading branch information
fjl authored and lochjin committed Nov 28, 2022
1 parent 22ef7c2 commit fd6fe54
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions core/rawdb/freezer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,13 +875,20 @@ func (t *freezerTable) advanceHead() error {
// Sync pushes any pending data from memory out to disk. This is an expensive
// operation, so use it with care.
func (t *freezerTable) Sync() error {
if err := t.index.Sync(); err != nil {
return err
}
if err := t.meta.Sync(); err != nil {
return err
t.lock.Lock()
defer t.lock.Unlock()

var err error
trackError := func(e error) {
if e != nil && err == nil {
err = e
}
}
return t.head.Sync()

trackError(t.index.Sync())
trackError(t.meta.Sync())
trackError(t.head.Sync())
return err
}

// DumpIndex is a debug print utility function, mainly for testing. It can also
Expand Down

0 comments on commit fd6fe54

Please sign in to comment.