You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing value log fsync on MemTableFlush and vlog rotation results in dangling value pointers after a crash #2366
When SyncWrites = false, a power loss could lose the contents in a value log. However, keys flushed into SST pointing to that value log could preserve. After restart these keys read as an empty string and err = nil.
DB.handleMemTableFlush() flushes the vlog pointers to SST, but it does not make the vlog content the pointers point to persistent. If a crash happens right after this call, we would have vlog pointers pointing past the end of the vlog file after restart.
To Reproduce
Open a DB with WithSyncWrites(false), WithValueThreshold(64) and WithVerifyValueChecksum(true).
Write keys with 1 KB values (so they go to the value log), then more writes until the memtable is flushed to 000001.sst. Observe the syncs: 000001.sst, then MANIFEST, but no sync of 000001.vlog.
Simulate a power loss before the kernel writes back the value log (about 30 s by default): keep the synced 000001.sst and MANIFEST, and drop the unsynced 000001.vlog data.
Reopen: badger.Open succeeds. Get on the flushed keys returns "" with err == nil.
Expected behavior
In DB.handleMemTableFlush(), fsync the latest vlog file to make sure keys made persistent point to persistent vlog content.
While rotating the vlogs, fsync the old vlog in logFile.doneWriting unconditionally, even when SyncWrites=false. This corresponds to the comments on vlog.sync() that During rotation, previous value log file also gets synced to disk.. But [BREAKING]: Change how Badger handles WAL #1555 added a SyncWrites=true condition to the fsync, which breaks crash consistency and makes that comment inaccurate.
Environment
OS: Windows-WSL
Language GO
Version v4.9.6
Additional context
Related but different: #2364 / #2365 (missing directory syncs on value log rotation and L0 flush). That makes the new files' names durable, not the value log data written to them later, so it doesn't fix this.
Activity