8000 fix(wal): never append after a torn WAL entry (#513, v2.x backport) by adityamukho · Pull Request #516 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(wal): never append after a torn WAL entry (#513, v2.x backport) - #516

Merged
adityamukho merged 1 commit into
mainfrom
fix/513-wal-torn-tail-v2
Oct 10, 2026
Merged

adityamukho merged 1 commit into
mainfrom
fix/513-wal-torn-tail-v2

Conversation

@adityamukho
@adityamukho adityamukho 8000 commented Oct 10, 2026
Copy link
Copy Markdown
Collaborator

Refs #513 (data-integrity: stays open until the fix is in a published release). v2.x backport of #514 (merged on v3), for a v2.0.5 patch under the support policy.

Problem

WAL replay stops at the first partial or damaged entry, but WalWriter appended at the end of the file. After a crash during an append, the next session's commits went in after the partial entry, so a second crash before any checkpoint lost them, although each was fsynced and reported committed. A failed append (short write, ENOSPC, EIO) did the same to the next commit through that handle. Affects v0.5.0 through v2.0.4.

Fix (same as v3)

  • WalWriter::open_or_create cuts an existing WAL back to the end of its last valid entry and syncs it before appending.
  • After a failed write or sync, the writer refuses every later append with the new WAL-007 (same number as on v3). A checkpoint or reopen gives a clean writer. A rejected oversize fact (WAL-003) does not poison it.

Cherry-picked from 25582a6. The conflicts were the header-validation line, the docs and the test counts. The oversize-fact test uses v2's MAX_FACT_BYTES.

Not backported: the #390 "never retry a failed checkpoint" rule (STG-046, #515). v2's checkpoint is not copy-on-write; its crash behavior is known issue #374.

Tests

The WAL unit tests, the Minigraf WAL-007 test, and the tests/wal_test.rs torn-tail second-crash test, all as on v3. 1,231 tests (1,223 passing, 8 ignored); clippy and fmt clean.

Bindings: this adds an ErrorCode variant on v2.x, which the UniFFI bindings (Python/Java/Android/Swift) need to know about at release time.

🤖 Generated with Claude Code

https://claude.ai/code/session_012wXxZguv7PgKQjMMH4yJ5h

Backport of #514 from v3. WAL replay stops at the first partial or
damaged entry, but the writer appended at the end of the file. After a
crash during an append, the next session's commits went in after the
partial entry, so a second crash before any checkpoint lost them
although each was fsynced and reported committed. A failed append in a
running process did the same to the next commit through that handle.

- WalWriter::open_or_create cuts an existing WAL back to the end of its
  last valid entry and syncs it before appending (scan_entries, shared
  with WalReader::read_entries).
- After a failed write or sync, the writer refuses every later append
  with the new WAL-007 (same code as v3). A checkpoint or a reopen starts
  a clean writer. A rejected oversize fact (WAL-003) does not poison it.

Same tests as on v3 (the oversize fact uses v2's MAX_FACT_BYTES).

Refs #513

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

❌ Patch coverage is 96.92308% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/wal.rs 96.92% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit 4d90212 into main Oct 10, 2026
21 checks passed
@adityamukho
adityamukho deleted the fix/513-wal-torn-tail-v2 branch October 10, 2026 10:48
adityamukho added a commit that referenced this pull request Oct 10, 2026
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