feat: frame TP WAL into per-commit records with validated recovery - #833
Open
zhanglei1949 wants to merge 1 commit into
Open
feat: frame TP WAL into per-commit records with validated recovery#833zhanglei1949 wants to merge 1 commit into
zhanglei1949 wants to merge 1 commit into
Conversation
Replace the legacy per-append 8-byte WAL header with a self-describing framed format (P1-2 of explicit transaction support): - One commit = one complete frame: 24B frame header (magic, record kind, commit timestamp, payload length) + payload + 8B trailer (commit marker + CRC32C over header, payload and marker). The marker is written last, so a present trailer proves the frame was fully persisted. - Each WAL file carries a 24B file header; checkpoint ownership comes from the wal directory the file lives in, not from header fields. - Real logical EOF: files are never preallocated, and a failed frame is rolled back to the clean EOF before the writer reports failure. - Recovery validates before replay: all files of the current checkpoint are parsed and checksummed up front, frames are merged by commit timestamp, and typed errors carry path/offset/timestamp. Only an incomplete trailing frame (an uncommitted crash) is discarded. - Record kinds: kInsert / kCowUpdate / kCompact; AP and embedded paths write no WAL.
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.
Fixes #832
Summary
Reframes the TP WAL from the legacy per-append 8-byte header into a self-describing framed format where one commit = one complete frame, and replaces best-effort recovery with a validate-before-replay protocol with typed errors. P1-2 of the explicit transaction support track.
New on-disk format (v1)
All fields are serialized little-endian byte-by-byte (host-endianness and struct-layout independent). The frame CRC covers the whole frame header, payload and commit marker in a single pass, so kind/timestamp/length are protected as well.
Key behaviors
*.walfiles of the current checkpoint are parsed and checksummed up front; frames from all writers are merged bycommit_timestampand replayed in global order. Errors are typed (unsupported_format/corrupted_frame/duplicate_timestamp/unknown_record_kind) and carry path + offset + timestamp. Only an incomplete trailing frame (an uncommitted crashed transaction) is discarded; any earlier inconsistency is a hard error.kInsert/kCowUpdate/kCompact. AP/embedded paths write no WAL; checkpoint-only transactions emit an empty-payloadkCompactframe.Compatibility note
WAL files written in the old per-append format are rejected during recovery as
unsupported_format; no migration path is provided. Any deployment upgrading with live TP WAL data should consolidate it via a checkpoint first.Verification
wal_codec_test: 18/18 passed (round-trip, tamper rejection, crash-injection subprocess tests: crash at each write phase leaves only committed frames, replay across compaction, bit-flipped payload rejected).transaction_test: 121 passed, 0 failed (3 pre-existing conditional skips), including the new TP-commit/replay-after-compaction e2e cases.tp_index_test: 15/15 passed.clang-format --dry-run -Werrorclean on all changed files.