Fix WAL checksum entry-buffer resize dropping buffered bytes - #959
Merged
Conversation
ChecksumWriter and ChecksumReader accumulate each WAL record in a 4KB entry buffer and grow it via resizeBufferIfNeeded when a record exceeds that size. The resize allocated a fresh (uninitialized) buffer without copying the bytes already accumulated, so any single WAL record larger than ~4KB was corrupted on write (record-length prefix lost) and failed verification on replay with 'Checksum verification failed' / 'Corrupted wal file. Read out invalid WAL record type'. Copy the valid prefix into the new buffer on resize, matching the pattern used by ColumnChunkData::resize. Adds regression tests writing a 5KB STRING record and replaying the WAL, both after close and while the original Database is still alive. Fixes #771
adsharma
force-pushed
the
fix-771-wal-checksum-resize
branch
from
September 11, 2026 23:46
6e8daf7 to
79ec03c
Compare
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 #771.
Root cause
A single WAL record larger than ~4KB failed replay with
Checksum verification failed/Corrupted wal file. Read out invalid WAL record type.ChecksumWriter/ChecksumReaderaccumulate each WAL record in a 4KB entry buffer and grow it inresizeBufferIfNeeded. The resize allocated a fresh uninitialized buffer without copying the already-buffered bytes, so the record-length prefix was lost on write (corrupting the WAL file on disk) and the checksum was computed over garbage on read. The 4KB threshold is the entry buffer's initial size (LBUG_PAGE_SIZE), matching the issue's per-record threshold observation. The same-process/GC/file-hash observations in the report follow from the corruption living in the WAL file plus uninitialized-memory nondeterminism — I reproduced the failure at the C++ level and even a fresh-process reopen failed on the corrupted WAL.Fix
Copy the valid prefix into the new buffer on resize (same pattern as
ColumnChunkData::resize), in bothchecksum_writer.cppandchecksum_reader.cpp.Tests
WalTest.LargeWALRecordReplayandWalTest.LargeWALRecordReplayWithPreviousDBAlive(5KB STRING record, replay after close and while the first DB is still alive). Verified they fail without the fix with the exact error from the issue, and pass with it.WalTestsuite: 31/31 pass. Broader CI will cover the rest.