8000 perf: WAL fsync-per-write batching/relaxed-durability escape hatch (#302) by adityamukho · Pull Request #353 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

perf: WAL fsync-per-write batching/relaxed-durability escape hatch (#302) - #353

Merged
adityamukho merged 10 commits into
mainfrom
worktree-302-wal-sync-mode
Aug 25, 2026
Merged

adityamukho merged 10 commits into
mainfrom
worktree-302-wal-sync-mode

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • Swap WalWriter::append_entry's per-write sync_all() (fsync) for sync_data() (fdatasync) — same durability guarantee for a pure-append file, one fewer metadata flush, unconditional in both modes.
  • Add SyncMode { Full, Normal } and OpenOptions::synchronous (default Full, preserving current behavior exactly). Normal skips the per-write flush entirely; checkpoint() still fsyncs the main file unconditionally in both modes, remaining the hard durability boundary.
  • Re-export SyncMode at the crate root.
  • Document the option (README, CHANGELOG, rustdoc) alongside the existing begin_write()/commit() batching pattern that already collapses N facts into one WAL write/fsync.
  • Wiki (Architecture.md, Performance-Tuning.md) updated and pushed separately ahead of this PR.

Design: docs/superpowers/specs/2026-08-24-wal-sync-mode-design.md
Plan: docs/superpowers/plans/2026-08-25-wal-sync-mode.md

Implemented via subagent-driven development: fresh implementer per task, task-scoped review after each, one whole-branch review at the end with one fix wave. Notable mid-flight catch: an early task needed to touch src/db.rs outside its stated scope to keep the crate compiling after a signature change, and initially hardcoded SyncMode::Full there — silently making the new option a no-op. Caught in task review, fixed to use opts.synchronous, and the final whole-branch review added a dedicated regression test (test_normal_sync_mode_reaches_both_wal_writer_call_sites) so that specific defect can't reappear silently.

Test plan

🤖 Generated with Claude Code

https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY

adityamukho and others added 10 commits August 24, 2026 21:08
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY
Add test_normal_sync_mode_survives_checkpoint_and_reopen to verify that
facts written with OpenOptions::synchronous(SyncMode::Normal) survive a
checkpoint and reopen cycle. This confirms that the WAL sync mode plumbing
(threaded by Task 2) works end-to-end: opening with SyncMode::Normal,
writing facts, checkpointing, and reopening all preserve data correctly.

Task 2 already wired both WalWriter::open_or_create call sites in db.rs
to pass opts.synchronous, so this test now passes without further changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY
Adds a regression test that fails if either WalWriter call site
(open_with_options initial-open, or wal_write_stamped_batch lazy-reopen)
reverts to a hardcoded SyncMode::Full instead of honoring
opts.synchronous — closing the gap that let this exact regression slip
through once already. Also fixes five doc/wording issues from review:
a misattributed re-export doc comment in lib.rs, and expanded/corrected
doc comments on SyncMode::Normal and OpenOptions::synchronous covering
the batching durability lever, the usize::MAX checkpoint-threshold
composition, in-memory inapplicability, and precise checkpoint-flush
semantics (the main file is fsynced directly; the WAL is deleted, not
itself flushed).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY
@codecov
codecov Bot commented Aug 25, 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 e2f4912 into main Aug 25, 2026
17 checks passed
@adityamukho
adityamukho deleted the worktree-302-wal-sync-mode branch August 25, 2026 03:26
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