Skip to content

Commit

Permalink
Add workaround for empty manifest file
Browse files Browse the repository at this point in the history
  • Loading branch information
albrow committed Nov 1, 2019
1 parent b765c4a commit 3ff7350
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions leveldb/storage/file_storage_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ func (f *browserFSFile) Write(b []byte) (n int, err error) {
// regardless of the encoding used. Encoding to hex seems like the most
// reliable way to do it.
rawBytesWritten := js.Global().Get("browserFS").Call("writeSync", f.fd, hex.EncodeToString(b), f.currOffset, "hex")

// Note: This a workaround for an issue that can cause data inconsistency
// (specifically an empty MANIFEST file). Normally fsync is not required on
// every write unless WriteOptions.Sync is set to true. However, we have
// observed that leveldb does not call fsync after creating a new MANIFEST
// file and deleting the old one. In BrowserFS, this means that the contents
// are never actually written to the file. On the next boot, leveldb will
// attempt to read from the manifest file and return an error because it is
// empty.
if err := f.Sync(); err != nil {
return 0, err
}

bytesWritten := rawBytesWritten.Int()
f.currOffset += int64(bytesWritten)
if bytesWritten != len(b) {
Expand Down

0 comments on commit 3ff7350

Please sign in to comment.