Skip to content

Commit

Permalink
Add fsync after creating new manifest
Browse files Browse the repository at this point in the history
This simple PR adds an fsync call on the manifest file when a new
manifest file is generated at the start.

In absence of this, the code updates the "CURRENT" and deletes the
previous manifest file and a crash at this point could leave the latest
manifest with a single incomplete record. Under this situation,
a restart is expected to lead to [manifest corrupt error](https://github.com/syndtr/goleveldb/blob/5c35d600f0caac04c20d52438103f1a7aa612598/leveldb/session.go#L192)
This seems to explain the error observed in issue#335. We too have observed this error in our environment.
  • Loading branch information
manish-sethi committed Feb 17, 2021
1 parent 5c35d60 commit c8c5f51
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions leveldb/session_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ func (s *session) newManifest(rec *sessionRecord, v *version) (err error) {
if err != nil {
return
}
if !s.o.GetNoSync() {
err = writer.Sync()
if err != nil {
return
}
}
err = s.stor.SetMeta(fd)
return
}
Expand Down

0 comments on commit c8c5f51

Please sign in to comment.