8000 fix(storage): never rewind the tx counter on WAL replay (#447) by adityamukho · Pull Request #448 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(storage): never rewind the tx counter on WAL replay (#447) - #448

Merged
adityamukho merged 1 commit into
mainfrom
fix/447-tx-counter-rewind
Oct 6, 2026
Merged

adityamukho merged 1 commit into
mainfrom
fix/447-tx-counter-rewind

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

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-of answers 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_wal skips WAL entries at or below it, then calls FactStorage::restore_tx_counter(). That function stored the highest tx_count among the facts it had just loaded. When every entry was skipped, nothing was loaded, and the counter was stored as 0.

Fix. restore_tx_counter now 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_idempotent whenever 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/3 and current results, before and after another reopen. Without the fix it fails: as-of 1 is [] instead of [30].
  • restore_tx_counter_never_moves_backwards (unit).
  • Full suite: 1,211 passing, 8 ignored. cargo clippy --all-features -- -D warnings is 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

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
@adityamukho
adityamukho merged commit 5b736b8 into main Oct 6, 2026
19 checks passed
@adityamukho
adityamukho deleted the fix/447-tx-counter-rewind branch October 6, 2026 03:08
@codecov
codecov Bot commented Oct 6, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0