Repository navigation
fix(storage): never rewind the tx counter on WAL replay (#447) - #448
Merged
Merged
Conversation
Open sets the transaction counter from the file's checkpointed count, then WAL replay skips entries at or below it and calls restore_tx_counter, which stored the highest tx_count among the facts it had loaded. When every WAL entry was already checkpointed, nothing was loaded and the counter was reset to 0, so later transactions reused tx_counts already in the file and :as-of history was wrong, permanently after the next checkpoint. restore_tx_counter now only raises the counter (fetch_max). Refs #447 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Oct 6, 2026
Merged
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.
Summary
v2.x fix for #447. Reopening a file database next to a WAL whose entries were all already checkpointed rewound the transaction counter to 0. Later transactions then reused
tx_counts already in the file, so:as-ofanswers mixed old and new transactions, and the next checkpoint made that history permanent.Cause. Open sets the counter from the file's
last_checkpointed_tx_count.replay_walskips WAL entries at or below it, then callsFactStorage::restore_tx_counter(). That function stored the highesttx_countamong the facts it had just loaded. When every entry was skipped, nothing was loaded, and the counter was stored as 0.Fix.
restore_tx_counternow only raises the counter (fetch_max).restore_tx_counter_from(open and migration) is unchanged.The WAL outlives a checkpoint only after a crash between the checkpoint's commit and the WAL delete, after a failed delete (WAL-006), or with
wal_checkpoint_threshold(usize::MAX).The v3 covering-key work (PR 3 of the v8 format) found this. Its one-timestamp-per-transaction check (STG-037) failed a checkpoint in
test_stale_wal_after_checkpoint_is_idempotentwhenever the reused transaction landed in a different millisecond.Tests
wal_test::test_reopen_with_checkpointed_wal_does_not_reuse_tx_counts: transact tx 1 and 2, checkpoint, restore the pre-checkpoint WAL, reopen, retract and transact. It checks:as-of 1/2/3and current results, before and after another reopen. Without the fix it fails:as-of 1is[]instead of[30].restore_tx_counter_never_moves_backwards(unit).cargo clippy --all-features -- -D warningsis clean.Docs
CHANGELOG (Unreleased → Fixed), TEST_COVERAGE, and the test counts in CLAUDE.md and README.
#447 is a data-integrity issue, so per CONTRIBUTING.md it stays open until the fix ships in a published release.
Refs #447
🤖 Generated with Claude Code
https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn