Repository navigation
feat: Add Write-Ahead Log With Torn-Write Recovery - #2
Merged
Merged
Conversation
Log put/delete records with CRC-32 framing and fsync, then apply to the memtable. Open replays the log, truncates a torn tail, and rejects checksum failures in the middle of the file.
Replay compared the length word to MAX_PAYLOAD before checking whether those bytes exist. A 20MB length on a tiny log failed open and dropped the good prefix. Truncate to the last good offset when the claimed record runs past EOF, and fsync after every recovery set_len so a later append cannot be buried by the old size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Puts a length-prefixed WAL under Store so put and delete survive process exit. Each record carries a CRC-32 over the payload. Open replays the log into the memtable. A short tail, or a last-record length that runs past EOF, is truncated to the last good offset and fsynced before appends resume. Payload-too-large is corruption only when those bytes are actually present in the file. A checksum miss in the middle of the file is still treated as corruption.
Mutations fsync before they hit the memtable, so a crash after return still recovers. Tests cover reopen, truncated tails, an inflated last-record length, a flipped last-record checksum, and a flipped mid-log byte.
Closes #1