Skip to content

Missing value log fsync on MemTableFlush and vlog rotation results in dangling value pointers after a crash #2366

Backlog

Description

@sli67

Describe the bug

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

  1. Open a DB with WithSyncWrites(false), WithValueThreshold(64) and WithVerifyValueChecksum(true).
  2. 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.
  3. 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.
  4. Reopen: badger.Open succeeds. Get on the flushed keys returns "" with err == nil.

Expected behavior

  1. In DB.handleMemTableFlush(), fsync the latest vlog file to make sure keys made persistent point to persistent vlog content.
  2. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions