Skip to content

Commit

Permalink
core/rawdb: improve freezerTable.Sync (#26245)
Browse files Browse the repository at this point in the history
While investigating #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.
  • Loading branch information
fjl authored Nov 24, 2022
1 parent ec2ec2d commit 193f350
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 @@ -867,13 +867,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
}

func (t *freezerTable) dumpIndexStdout(start, stop int64) {
Expand Down

0 comments on commit 193f350

Please sign in to comment.