8000 fix(db): checkpoint removes a WAL whose entries are all checkpointed (#457) by adityamukho · Pull Request #525 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(db): checkpoint removes a WAL whose entries are all checkpointed (#457) - #525

Merged
adityamukho merged 1 commit into
v3from
fix/457-stale-wal-checkpoint
Oct 10, 2026
Merged

adityamukho merged 1 commit into
v3from
fix/457-stale-wal-checkpoint

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Closes #457.

Problem

do_checkpoint returned early when wal_entry_count == 0 && !pfs.is_dirty(), and that early return also skipped deleting the WAL. Replay counts only the entries it applies, so a WAL whose entries were all checkpointed already gave a count of 0. The WAL then stayed until a later write was checkpointed. This happens after a crash between a checkpoint's commit and its WAL delete, or after a failed delete (WAL-006). No data was affected, because replay skips those entries.

Fix

On the early-return path, call delete_wal. It removes the file if it exists and syncs the parent directory, as the normal path does. Every entry is at or below the committed last_checkpointed_tx_count, so deleting the file loses nothing.

Tests

  • tests/wal_test.rs: test_checkpoint_removes_wal_whose_entries_are_all_checkpointed restores a stale WAL after a checkpoint, reopens and checkpoints, then checks:

    • the WAL is gone and a second checkpoint is still a no-op;
    • the fact survives a reopen;
    • the next write does not reuse tx 1.

    It fails without the fix.

  • tests/golden_corpus_test.rs: dropped the stale_wal exemption, so v7_stale_wal and v8_stale_wal must also have no WAL after a checkpoint. The manifests keep the flag as a description of the shape (tests/golden/README.md updated).

Docs: CHANGELOG (Fixed), test counts in CLAUDE.md, README and TEST_COVERAGE (1424 / 1414 passing). No v2.x backport, because this is not a data-integrity fix.

🤖 Generated with Claude Code

https://claude.ai/code/session_012wXxZguv7PgKQjMMH4yJ5h

…457)

do_checkpoint returned early when it had nothing to flush, which also
skipped deleting the WAL. A WAL left by a crash between a checkpoint's
commit and its WAL delete, or by a failed delete, therefore stayed until
a later write was checkpointed. Every entry in it is at or below the
committed tx count, so the early return now deletes it (with the parent
directory sync) instead.

The golden-corpus test no longer exempts the stale_wal fixtures from the
WAL-gone check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012wXxZguv7PgKQjMMH4yJ5h
@codecov
codecov Bot commented Oct 10, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit edd1fe7 into v3 Oct 10, 2026
24 checks passed
@adityamukho
adityamukho deleted the fix/457-stal 7FE7 e-wal-checkpoint branch October 10, 2026 17:31
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