diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f15290600..0fe21e3d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `OpenOptions` `#[non_exhaustive]` would immunise every future field addition, but is itself a breaking change, so it is a decision to make at the same time as the version number rather than after it. +- **`OpenOptions` gains a second post-1.0 field: `synchronous`** (#302). Same semver consequence as `allow_unlocked` above — a struct-literal `OpenOptions { .. }` built without `..Default::default()` no longer compiles. One in-tree literal (`src/db.rs`, a test) needed updating; every other in-tree construction already used the spread form or the chainable builder. - **Minimum supported Rust version is now 1.89** (was effectively 1.85, implied by `edition = "2024"`). Required for `std::fs::File::try_lock`, stabilised in 1.89. Declared as `rust-version` in `Cargo.toml`, so cargo reports a clear @@ -117,6 +118,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **`or`/`or-join` branches can now short-circuit** (#250): branches are still sorted cheapest-first (landed earlier), but once the branches evaluated so far already produce a match for every incoming binding, remaining (costlier) branches are skipped instead of always being evaluated. This is always safe for `or-join` — branches are projected down to already-bound outer variables before merging, so a skipped branch could only have produced a row identical to one already kept. For plain `or`, it's only safe when the branches evaluated so far introduce no variable beyond what's already bound in the incoming scope (a pure filter) — a branch that binds a genuinely new variable can legitimately contribute a distinct row for an already-"covered" key, so that case still evaluates every branch, exactly as before. Benchmark: `disjunction/or_short_circuit` and `disjunction/or_join_short_circuit` (10k facts, both branches fully covering) show ~11% and ~27% improvement respectively. +- **WAL writes no longer pay a full `fsync()`, and can skip the per-write flush entirely** (#302): `WalWriter::append_entry` called `File::sync_all()` (fsync) after every write, flushing inode metadata the WAL — a pure-append file — never needed alongside the data. It now calls `File::sync_data()` (fdatasync) instead: same durability guarantee, one fewer metadata flush, for every existing caller, no other change required. A new `OpenOptions::synchronous` field (`SyncMode::Full`, the default, matches this fdatasync behavior; `SyncMode::Normal` skips the per-write flush altogether) lets bulk loaders/migrations that can safely re-run from a checkpoint watermark trade per-write durability for throughput — `checkpoint()` still fsyncs the main file unconditionally in both modes, so it remains the hard durability boundary regardless of `synchronous`. Separately: `begin_write()` + N `execute()` + one `commit()` already collapsed N facts into a single WAL write / single fsync before this change; that existing batching pattern is now documented (README, wiki Performance Tuning page) since it was easy to miss. + ## v1.2.3 — 2026-08-10 No changes to the core crate. Released so the language bindings have a version diff --git a/README.md b/README.md index c567379225..b687b34211 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,8 @@ Benchmarks on Intel Core i7-1065G7 @ 1.30GHz, 16 GB RAM, Rust 1.92.0. See [BENCH File-backed databases enforce a maximum fact size of **4 080 serialised bytes** per fact. In-memory databases have no limit. +**Durability tuning:** every write is `fsync`'d immediately by default (`SyncMode::Full`). Bulk loaders/migrations that can safely re-run from a checkpoint watermark on failure can trade that for throughput with `OpenOptions::new().synchronous(SyncMode::Normal)` — `checkpoint()` still fsyncs unconditionally in both modes. See the [Performance Tuning wiki page](https://github.com/project-minigraf/minigraf/wiki/Performance-Tuning#configuration-knobs) for the full tradeoff and the write-batching pattern that pairs with it. + ## Contributing This is a solo-maintained project with a long-term vision. Read [PHILOSOPHY.md](PHILOSOPHY.md) and [ROADMAP.md](ROADMAP.md) before proposing features. diff --git a/docs/superpowers/plans/2026-08-25-wal-sync-mode.md b/docs/superpowers/plans/2026-08-25-wal-sync-mode.md new file mode 100644 index 0000000000..7ea4d6a7b4 --- /dev/null +++ b/docs/superpowers/plans/2026-08-25-wal-sync-mode.md @@ -0,0 +1,533 @@ +# WAL Sync Mode Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Replace `WalWriter`'s per-write `fsync()` with a cheaper `fdatasync()`, and add an opt-in `OpenOptions::synchronous` mode that skips per-write flushing entirely for bulk loaders, while `checkpoint()` stays a hard durability boundary in both modes. + +**Architecture:** A new `SyncMode { Full, Normal }` enum lives in `src/db.rs` next to `OpenOptions` (public API surface) and is re-exported at the crate root. `OpenOptions` gains a `synchronous: SyncMode` field (default `Full`), threaded through to `WalWriter` at construction. `WalWriter` stores the mode and branches on it in `append_entry`: `Full` calls `sync_data()` (fdatasync — replaces the old `sync_all()`), `Normal` skips the flush call entirely. No change to `checkpoint()`'s own fsync behavior. + +**Tech Stack:** Rust, `std::fs::File::sync_data()`/`sync_all()`, existing `anyhow::Result` error plumbing. + +**Spec:** `docs/superpowers/specs/2026-08-24-wal-sync-mode-design.md` + +## Global Constraints + +- Default (`SyncMode::Full`) must preserve exactly the current behavior for every existing caller, including those using `..Default::default()` or the chainable builders. +- `checkpoint()` (explicit, auto-threshold, or the clean-close `Drop` in `Inner::drop`, `src/db.rs:234-247`) fsyncs the main file unconditionally in both modes — do not touch that path. +- No third `Off`/never-sync tier, no runtime mode switching after `open()`, no per-`WriteTransaction` override (see spec's Non-goals). +- Testing convention (`CLAUDE.md`): never use `{:?}` debug format of `Result`/`Fact`/`Value`/`EdnValue`/anything transitively containing `Uuid` in `assert!`/`assert_eq!` messages — CodeQL flags it. Use plain string messages, `unwrap()`/`expect()`, or assert on count/bool only. + +--- + +### Task 1: `SyncMode` enum and `OpenOptions::synchronous` + +**Files:** +- Modify: `src/db.rs` (enum + struct field + `Default` impl + builder method + one existing test struct literal) +- Test: `src/db.rs` (`#[cfg(test)] mod tests` at the bottom of the same file — this codebase keeps `db.rs` unit tests inline) + +**Interfaces:** +- Produces: `pub enum SyncMode { Full, Normal }` (derives `Debug, Clone, Copy, PartialEq, Eq`), `OpenOptions::synchronous: SyncMode`, `OpenOptions::synchronous(self, mode: SyncMode) -> Self` builder method. Tasks 2 and 3 consume this type and field. + +- [ ] **Step 1: Write the failing test** + +Add near `test_open_with_options_custom_threshold` (around `src/db.rs:1584`): + +```rust + #[test] + fn test_sync_mode_defaults_to_full() { + assert_eq!(OpenOptions::default().synchronous, SyncMode::Full, "default sync mode"); + } + + #[test] + fn test_sync_mode_builder_sets_normal() { + let opts = OpenOptions::new().synchronous(SyncMode::Normal); + assert_eq!(opts.synchronous, SyncMode::Normal, "builder should set Normal"); + } +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `cargo test --lib test_sync_mode_defaults_to_full test_sync_mode_builder_sets_normal` +Expected: FAIL — `SyncMode` and `OpenOptions::synchronous` do not exist yet (compile error). + +- [ ] **Step 3: Add the `SyncMode` enum** + +In `src/db.rs`, insert immediately before the `// ─── OpenOptions ─────...` comment (currently just above `pub struct OpenOptions`): + +```rust +// ─── SyncMode ──────────────────────────────────────────────────────────────── + +/// Controls how aggressively WAL writes are flushed to disk. +/// +/// Independent of [`Minigraf::checkpoint`], which always fsyncs the main +/// `.graph` file regardless of this setting — see [`OpenOptions::synchronous`]. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum SyncMode { + /// `fdatasync` after every WAL write. Default; matches Minigraf's + /// behavior before this option existed — every committed `transact`/ + /// `retract` is durable immediately. + Full, + /// No per-write flush. The WAL entry is still `write_all()`'d — safe + /// across an ordinary process crash — but not forced to disk until the + /// next checkpoint (auto-threshold, explicit `checkpoint()`, or clean + /// close). Data written since the last checkpoint is lost only on OS + /// crash or power loss, not process death. Intended for bulk loaders + /// that can safely re-run from a checkpoint watermark on failure. + Normal, +} +``` + +- [ ] **Step 4: Add the field, `Default`, and builder method** + +In `struct OpenOptions`, add after the `allow_unlocked` field (`src/db.rs:100`, right before the closing `}`): + +```rust + /// Controls WAL write durability. See [`SyncMode`]. Defaults to `SyncMode::Full`. + pub synchronous: SyncMode, +``` + +In `impl Default for OpenOptions` (`src/db.rs:103-113`), add to the struct literal: + +```rust + allow_unlocked: false, + synchronous: SyncMode::Full, +``` + +In `impl OpenOptions`, add a builder method after `allow_unlocked` (`src/db.rs:150-154`): + +```rust + /// Set the WAL durability mode. See [`SyncMode`]. + #[must_use] + pub fn synchronous(mut self, mode: SyncMode) -> Self { + self.synchronous = mode; + self + } +``` + +- [ ] **Step 5: Fix the pre-existing struct-literal test that now fails to compile** + +`test_open_with_options_custom_threshold` (`src/db.rs:1589`) builds `OpenOptions` as a full struct literal without `..Default::default()`, so it needs the new field added explicitly: + +```rust + let opts = OpenOptions { + wal_checkpoint_threshold: 5, + page_cache_size: 256, + max_derived_facts: 100_000, + max_results: 1_000_000, + allow_unlocked: false, + synchronous: SyncMode::Full, + }; +``` + +- [ ] **Step 6: Run tests to verify they pass** + +Run: `cargo test --lib test_sync_mode_defaults_to_full test_sync_mode_builder_sets_normal test_open_with_options_custom_threshold` +Expected: PASS (3 tests) + +- [ ] **Step 7: Commit** + +```bash +git add src/db.rs +git commit -m "feat: add SyncMode enum and OpenOptions::synchronous field" +``` + +--- + +### Task 2: Thread `SyncMode` through `WalWriter`, swap `sync_all()` for `sync_data()` + +**Files:** +- Modify: `src/wal.rs` +- Test: `src/wal.rs` (`#[cfg(all(test, not(target_arch = "wasm32")))] mod tests` at the bottom) + +**Interfaces:** +- Consumes: `crate::db::SyncMode` (from Task 1). +- Produces: `WalWriter::open_or_create(path: &Path, sync_mode: SyncMode) -> Result` (signature change — was `open_or_create(path: &Path)`). Task 3 calls this with the new signature. + +- [ ] **Step 1: Write the failing test** + +Add near the end of the `tests` module in `src/wal.rs` (after `test_wal_single_fact_round_trip`, around line 394): + +```rust + #[test] + fn test_wal_normal_mode_write_and_replay() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("test.wal"); + + let alice = Uuid::new_v4(); + let fact = make_fact(alice, ":name", Value::String("Alice".to_string()), 1); + + // Normal mode skips the per-write flush; the entry must still be + // durable-within-process (write_all()'d) and correctly replayable. + let mut writer = WalWriter::open_or_create(&path, SyncMode::Normal).unwrap(); + writer.append_entry(1, std::slice::from_ref(&fact)).unwrap(); + + let mut reader = WalReader::open(&path).unwrap(); + let entries = reader.read_entries().unwrap(); + assert_eq!(entries.len(), 1); + assert_eq!(entries[0].tx_count, 1); + assert_eq!(entries[0].facts.len(), 1); + assert_eq!(entries[0].facts[0].entity, fact.entity); + } +``` + +- [ ] **Step 2: Run test to verify it fails** + +Run: `cargo test --lib test_wal_normal_mode_write_and_replay` +Expected: FAIL — `open_or_create` doesn't take a second argument yet (compile error). + +- [ ] **Step 3: Add the import** + +At the top of `src/wal.rs`, add to the `use` block (after `use crate::graph::types::Fact;`): + +```rust +use crate::db::SyncMode; +``` + +- [ ] **Step 4: Add the `sync_mode` field to `WalWriter`** + +Change (around `src/wal.rs:143-146`): + +```rust +pub struct WalWriter { + file: File, +} +``` + +to: + +```rust +pub struct WalWriter { + file: File, + sync_mode: SyncMode, +} +``` + +- [ ] **Step 5: Update `open_or_create` to accept and store the mode** + +Change the signature and both `Ok(WalWriter { file })` construction sites inside it (`src/wal.rs:152-172`): + +```rust + pub fn open_or_create(path: &Path, sync_mode: SyncMode) -> Result { + // Try atomic create-new first (no TOCTOU window) + match OpenOptions::new() + .read(true) + .write(true) + .create_new(true) + .open(path) + { + Ok(mut file) => { + write_wal_header(&mut file)?; + file.seek(SeekFrom::End(0))?; + return Ok(WalWriter { file, sync_mode }); + } + Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {} + Err(e) => return Err(e.into()), + } + + // File exists — validate its header and seek to end for appending + let mut file = OpenOptions::new().read(true).write(true).open(path)?; + match check_wal_header_length(&mut file)? { + WalHeaderState::Present => validate_wal_header(&mut file)?, + // A previous crash landed between this file's creation and its + // header write completing; no entry could have been appended + // yet, so re-initialize it as a fresh, empty WAL. + WalHeaderState::Absent => write_wal_header(&mut file)?, + } + file.seek(SeekFrom::End(0))?; + Ok(WalWriter { file, sync_mode }) + } +``` + +- [ ] **Step 6: Branch on `sync_mode` in `append_entry`** + +Change (`src/wal.rs:186-191`): + +```rust + pub fn append_entry(&mut self, tx_count: u64, facts: &[Fact]) -> Result<()> { + let entry_bytes = serialize_entry(tx_count, facts)?; + self.file.write_all(&entry_bytes)?; + self.file.sync_all()?; + Ok(()) + } +``` + +to: + +```rust + pub fn append_entry(&mut self, tx_count: u64, facts: &[Fact]) -> Result<()> { + let entry_bytes = serialize_entry(tx_count, facts)?; + self.file.write_all(&entry_bytes)?; + match self.sync_mode { + SyncMode::Full => self.file.sync_data()?, + SyncMode::Normal => {} + } + Ok(()) + } +``` + +Also update the doc comment directly above `append_entry` — it currently reads "Serialize `facts` as a WAL entry and append it to the file, then fsync." Change the second sentence to: "Then flushes to disk, unless `sync_mode` is `SyncMode::Normal` — see [`SyncMode`]." + +- [ ] **Step 7: Update all existing test call sites to pass `SyncMode::Full`** + +Every existing test in this file constructs a `WalWriter` expecting the pre-change (always-fsync) behavior, so they all take `SyncMode::Full` explicitly. Run this from the worktree root to apply the mechanical substitution: + +```bash +sed -i 's/WalWriter::open_or_create(&path)/WalWriter::open_or_create(\&path, SyncMode::Full)/g' src/wal.rs +``` + +Verify it changed exactly the 10 pre-existing call sites (lines 368, 383, 407, 430, 465, 480, 541, 575, 595, 609 before this edit) and left the function definition (`pub fn open_or_create(path: &Path) -> Result {`) untouched: + +```bash +grep -c "WalWriter::open_or_create(&path, SyncMode::Full)" src/wal.rs +``` + +Expected: `10` + +- [ ] **Step 8: Run tests to verify they pass** + +Run: `cargo test --lib wal::` +Expected: PASS (all `wal.rs` unit tests, including the new `test_wal_normal_mode_write_and_replay`) + +- [ ] **Step 9: Commit** + +```bash +git add src/wal.rs +git commit -m "feat: thread SyncMode through WalWriter, swap sync_all for sync_data" +``` + +--- + +### Task 3: Thread `opts.synchronous` through both `db.rs` call sites, integration test + +**Files:** +- Modify: `src/db.rs` +- Test: `src/db.rs` (inline `mod tests`) + +**Interfaces:** +- Consumes: `WalWriter::open_or_create(path: &Path, sync_mode: SyncMode) -> Result` (Task 2), `OpenOptions::synchronous: SyncMode` (Task 1). + +- [ ] **Step 1: Write the failing test** + +Add near `test_open_with_options_custom_threshold` in `src/db.rs`: + +```rust + #[test] + fn test_normal_sync_mode_survives_checkpoint_and_reopen() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("test.graph"); + + { + let db = OpenOptions::new() + .synchronous(SyncMode::Normal) + .path(&path) + .open() + .unwrap(); + db.execute(r#"(transact [[:alice :name "Alice"]])"#).unwrap(); + db.execute(r#"(transact [[:bob :name "Bob"]])"#).unwrap(); + db.checkpoint().unwrap(); + } + + let db = Minigraf::open(&path).unwrap(); + let facts = db.inner.fact_storage.get_asserted_facts().unwrap(); + assert_eq!(facts.len(), 2, "both facts should survive checkpoint + reopen under Normal sync mode"); + } +``` + +- [ ] **Step 2: Run test to verify it fails** + +Run: `cargo test --lib test_normal_sync_mode_survives_checkpoint_and_reopen` +Expected: FAIL — `WalWriter::open_or_create` call sites in `db.rs` don't pass a `SyncMode` yet (compile error, since Task 2 changed the signature). + +- [ ] **Step 3: Update the call site in `open_with_options`** + +Change (`src/db.rs:344-348`): + +```rust + let wal = if wal_path.exists() { + Some(WalWriter::open_or_create(&wal_path)?) + } else { + None + }; +``` + +to: + +```rust + let wal = if wal_path.exists() { + Some(WalWriter::open_or_create(&wal_path, opts.synchronous)?) + } else { + None + }; +``` + +- [ ] **Step 4: Update the call site in `wal_write_stamped_batch`** + +Change (`src/db.rs:1124-1127`): + +```rust + if wal.is_none() { + let wal_path = Minigraf::wal_path_for(db_path); + *wal = Some(WalWriter::open_or_create(&wal_path)?); + } +``` + +to: + +```rust + if wal.is_none() { + let wal_path = Minigraf::wal_path_for(db_path); + *wal = Some(WalWriter::open_or_create(&wal_path, opts.synchronous)?); + } +``` + +(`opts: &OpenOptions` is already a parameter of `wal_write_stamped_batch` — no further plumbing needed.) + +- [ ] **Step 5: Run tests to verify they pass** + +Run: `cargo test --lib db::` +Expected: PASS (all `db.rs` unit tests, including the new one) + +- [ ] **Step 6: Commit** + +```bash +git add src/db.rs +git commit -m "feat: thread OpenOptions::synchronous into WalWriter construction" +``` + +--- + +### Task 4: Re-export `SyncMode` at the crate root + +**Files:** +- Modify: `src/lib.rs` + +**Interfaces:** +- Consumes: `pub enum SyncMode` (Task 1). +- Produces: `minigraf::SyncMode` reachable at the crate root, matching how `OpenOptions` is already exposed. + +- [ ] **Step 1: Write the failing test** + +There's no existing doc-test file for root re-exports in this codebase, so this is verified by a doc-test embedded directly in `src/lib.rs`'s module doc comment area — add this compile-checked snippet near the existing `pub use db::{Minigraf, OpenOptions, WriteTransaction};` line (`src/lib.rs:92`) as a doc comment on that same line: + +```rust +/// Re-exported at the crate root alongside [`OpenOptions`] so +/// `minigraf::SyncMode` is reachable without importing `minigraf::db`. +``` + +(This is documentation, not a runnable test — the actual verification is the compile step below, since an incorrect re-export is a compile error, not a runtime failure.) + +- [ ] **Step 2: Update the re-export** + +Change (`src/lib.rs:92`): + +```rust +pub use db::{Minigraf, OpenOptions, WriteTransaction}; +``` + +to: + +```rust +pub use db::{Minigraf, OpenOptions, SyncMode, WriteTransaction}; +``` + +- [ ] **Step 3: Verify it compiles and is reachable** + +Run: `cargo build --lib` +Expected: builds cleanly. + +Run: `cargo doc --no-deps 2>&1 | grep -i "error\|warning: unresolved"` +Expected: no output (no broken intra-doc links from the doc comments added in Tasks 1-3, which reference `[\`SyncMode\`]` and `[\`OpenOptions::synchronous\`]`). + +- [ ] **Step 4: Commit** + +```bash +git add src/lib.rs +git commit -m "feat: re-export SyncMode at the crate root" +``` + +--- + +### Task 5: Docs — README pointer and CHANGELOG entries + +**Files:** +- Modify: `README.md` +- Modify: `CHANGELOG.md` + +**Interfaces:** None — documentation only, no code interfaces produced or consumed. (The wiki's `Architecture.md` and `Performance-Tuning.md` were already updated and pushed in a separate session, ahead of this implementation.) + +- [ ] **Step 1: Add a "Durability tuning" pointer to the README's Performance section** + +In `README.md`, after the sentence "File-backed databases enforce a maximum fact size of **4 080 serialised bytes** per fact. In-memory databases have no limit." (end of the `## Performance` section, just before `## Contributing`), add: + +```markdown + +**Durability tuning:** every write is `fsync`'d immediately by default (`SyncMode::Full`). Bulk loaders/migrations that can safely re-run from a checkpoint watermark on failure can trade that for throughput with `OpenOptions::new().synchronous(SyncMode::Normal)` — `checkpoint()` still fsyncs unconditionally in both modes. See the [Performance Tuning wiki page](https://github.com/project-minigraf/minigraf/wiki/Performance-Tuning#configuration-knobs) for the full tradeoff and the write-batching pattern that pairs with it. +``` + +- [ ] **Step 2: Add a CHANGELOG entry documenting the fix** + +In `CHANGELOG.md`, under `## Unreleased` → `### Performance` (the section ending with the `or`/`or-join` short-circuit bullet, immediately before `## v1.2.3 — 2026-08-10`), append: + +```markdown + +- **WAL writes no longer pay a full `fsync()`, and can skip the per-write flush entirely** (#302): `WalWriter::append_entry` called `File::sync_all()` (fsync) after every write, flushing inode metadata the WAL — a pure-append file — never needed alongside the data. It now calls `File::sync_data()` (fdatasync) instead: same durability guarantee, one fewer metadata flush, for every existing caller, no other change required. A new `OpenOptions::synchronous` field (`SyncMode::Full`, the default, matches this fdatasync behavior; `SyncMode::Normal` skips the per-write flush altogether) lets bulk loaders/migrations that can safely re-run from a checkpoint watermark trade per-write durability for throughput — `checkpoint()` still fsyncs the main file unconditionally in both modes, so it remains the hard durability boundary regardless of `synchronous`. Separately: `begin_write()` + N `execute()` + one `commit()` already collapsed N facts into a single WAL write / single fsync before this change; that existing batching pattern is now documented (README, wiki Performance Tuning page) since it was easy to miss. +``` + +- [ ] **Step 3: Add a "Breaking-ish changes" bullet for the new `OpenOptions` field** + +In `CHANGELOG.md`, under `## Unreleased` → `### Breaking-ish changes`, immediately after the existing `allow_unlocked` bullet (the one starting "**Adding `OpenOptions::allow_unlocked` breaks struct-literal construction.**"), append a new bullet: + +```markdown +- **`OpenOptions` gains a second post-1.0 field: `synchronous`** (#302). Same semver consequence as `allow_unlocked` above — a struct-literal `OpenOptions { .. }` built without `..Default::default()` no longer compiles. One in-tree literal (`src/db.rs`, a test) needed updating; every other in-tree construction already used the spread form or the chainable builder. +``` + +- [ ] **Step 4: Verify markdown renders sensibly** + +Run: `grep -c "^## " CHANGELOG.md` before and after — should be unchanged (no accidental heading-level edits). Read back both diffs with `git diff README.md CHANGELOG.md` and confirm the new text lands in the right sections with no stray heading markers. + +- [ ] **Step 5: Commit** + +```bash +git add README.md CHANGELOG.md +git commit -m "docs: document SyncMode in README and CHANGELOG" +``` + +--- + +### Task 6: Full verification + +**Files:** None modified — verification only. + +**Interfaces:** None. + +- [ ] **Step 1: Format check** + +Run: `cargo fmt --check` +Expected: no output (clean). + +- [ ] **Step 2: Clippy** + +Run: `cargo clippy --all-targets -- -D warnings` +Expected: no warnings/errors. + +- [ ] **Step 3: Full test suite** + +Run: `cargo test` +Expected: all tests pass, including every test added in Tasks 1-3. + +- [ ] **Step 4: Confirm the #308 crash-safety regression tests are unaffected** + +The default `SyncMode::Full` must preserve exactly the fsync behavior those tests depend on. + +Run: `cargo test --test crash_kill_test` +Expected: PASS, unchanged from before this branch. + +- [ ] **Step 5: Confirm the doc comment cross-references resolve** + +Run: `cargo doc --no-deps 2>&1 | grep -i "warning"` +Expected: no new warnings beyond whatever pre-existing warnings the baseline had (compare against `git stash` output if unsure — but do not actually stash; if in doubt, note any warning text and cross-check it isn't newly introduced by `[\`SyncMode\`]` / `[\`OpenOptions::synchronous\`]` links). + +- [ ] **Step 6: Review the full diff** + +Run: `git diff origin/main --stat` and `git log --oneline origin/main..HEAD` +Expected: touches only `src/db.rs`, `src/wal.rs`, `src/lib.rs`, `README.md`, `CHANGELOG.md`, plus the spec/plan docs already committed. Five feature/doc commits (Tasks 1-5) plus the earlier spec commit — six total. diff --git a/docs/superpowers/specs/2026-08-24-wal-sync-mode-design.md b/docs/superpowers/specs/2026-08-24-wal-sync-mode-design.md new file mode 100644 index 0000000000..fccdad496b --- /dev/null +++ b/docs/superpowers/specs/2026-08-24-wal-sync-mode-design.md @@ -0,0 +1,171 @@ +# WAL Sync Mode — Design + +**Date:** 2026-08-24 +**Status:** Approved, not yet implemented +**Issue:** #302 (WAL fsync-per-write is a full fsync with no batching/relaxed-durability escape hatch) +**Depends on:** none. **Blocks:** #309 (lock fairness) — cheaper/skippable per-write fsync directly +shrinks the lock-hold window #309's starvation/timeout numbers were measured against; see +`docs/superpowers/specs/` roadmap note in project memory `project_issue_roadmap.md`. + +## Problem + +`WalWriter::append_entry` (`src/wal.rs:153-158`) does a full `sync_all()` (fsync, flushes file +data *and* inode metadata) after every WAL write: + +```rust +pub fn append_entry(&mut self, tx_count: u64, facts: &[Fact]) -> Result<()> { + let entry_bytes = serialize_entry(tx_count, facts)?; + self.file.write_all(&entry_bytes)?; + self.file.sync_all()?; + Ok(()) +} +``` + +For high-write-volume callers (bulk ingestion, migration, seeding) issuing many small +`db.execute()` calls, this is dozens of synchronous disk round-trips per logical unit of work. +Discovered while diagnosing event-loop blocking in `temporal-reasoning`'s git-history ingestion, +which issues ~20-25 separate `execute()`/`checkpoint()` calls per commit. + +Three independent improvements, increasing risk/leverage: + +1. `sync_all()` → `sync_data()` (fdatasync): skips the inode-metadata flush `sync_all()` also + does. The WAL is pure-append, so no metadata beyond file length (which `sync_data()` still + guarantees) matters here. Near-zero risk, no format change. +2. `WriteTransaction::commit()` (`src/db.rs:1050-...`) already collapses every fact staged via + `begin_write()` + N `execute()` calls into one `tx_count` and one WAL write / one fsync. Callers + issuing N bare `db.execute()` calls for unrelated facts (not hitting the #287 same-ident-batch + bug) can switch to the batched form and cut N fsyncs to 1 today, with no library change. This + is undocumented and easy to miss. +3. An opt-in relaxed-durability mode (SQLite `PRAGMA synchronous=NORMAL` equivalent): skip the + per-write fsync entirely, relying on the OS page cache and the next checkpoint (auto-threshold, + explicit, or clean-close) for durability. Biggest lever, real tradeoff — must be explicit + opt-in since the default is "every transact/retract is fsync-durable immediately." + +## Decisions + +| # | Decision | +|---|---| +| 1 | Ship all three fixes in this issue (not split #3 into its own issue) | +| 2 | `sync_all()` → `sync_data()` applies unconditionally, in both durability modes | +| 3 | New mode is a two-value enum `SyncMode { Full, Normal }` — no third "never sync" tier | +| 4 | Exposed as `OpenOptions::synchronous: SyncMode`, open-time only, default `Full` | +| 5 | `checkpoint()` (explicit, auto-threshold, or clean-close `Drop`) is unaffected in either mode — it remains the hard durability boundary | +| 6 | Document the `begin_write()`/commit()-batches-N-facts pattern (fix #2) alongside the new mode | + +### Why an enum on `OpenOptions`, not a runtime-toggleable method or per-transaction override + +`OpenOptions` already holds every other tunable that affects durability/performance trade-offs +(`wal_checkpoint_threshold`, `page_cache_size`), all fixed for the handle's lifetime and set at +`open()`. A `db.set_synchronous(mode)` method or a per-`WriteTransaction` override would add a +mutable-mode or per-call decision surface with no requester and no precedent in this codebase. +YAGNI: nothing in #302 or the ingestion use case that motivated it needs mid-session switching — +a bulk-loader that wants relaxed durability wants it for the whole load, opened once for that +purpose. + +### Why two levels, not three + +SQLite's `PRAGMA synchronous` has `OFF`/`NORMAL`/`FULL`. `OFF` never fsyncs, not even at +checkpoints — durable only on clean shutdown or explicit flush, with a much larger and +harder-to-document crash-loss window. Nothing in #302 asks for this, and Minigraf's `checkpoint()` +is already positioned as *the* durability boundary (see below) — adding a mode that skips even +that boundary contradicts the "every feature must be crash-safe" default in `PHILOSOPHY.md` §6 +without a concrete use case driving it. `Full`/`Normal` covers the actual ask. + +### Why `checkpoint()` stays a hard boundary in both modes + +`Minigraf::do_checkpoint` → `PersistentFactStorage::save()` already calls `sync_all()` on the main +`.graph` file (`src/storage/backend/file.rs:424`) unconditionally. This is what bounds `Normal` +mode's risk window to "since the last checkpoint" rather than "forever": auto-checkpoint +(`wal_checkpoint_threshold`), an explicit `checkpoint()` call, or the best-effort checkpoint in +`Inner::drop` (`src/db.rs:234-247`, skipped only by the `usize::MAX` sentinel) all still fsync the +main file. A crash between two checkpoints in `Normal` mode loses only the WAL-buffered writes +since the last one — an OS crash or power loss, not an ordinary process crash, since the WAL bytes +are still `write_all()`'d to the OS page cache regardless of mode and become durable on the next +fsync by *any* process, not just the writer. + +## Design + +### `SyncMode` + +```rust +/// Controls how aggressively WAL writes are flushed to disk. +/// +/// Independent of `checkpoint()`, which always fsyncs the main file regardless +/// of this setting — see `OpenOptions::synchronous`. +pub enum SyncMode { + /// fsync (via `fdatasync`) after every WAL write. Default; matches + /// Minigraf's behavior before this option existed. + Full, + /// No per-write fsync. The WAL entry is still `write_all()`'d — safe across + /// an ordinary process crash — but not flushed to disk until the next + /// checkpoint (explicit, threshold-triggered, or on clean close). Data + /// written since the last checkpoint is lost only on OS crash or power + /// loss, not on process death. Intended for bulk loaders/migrations that + /// can safely re-run from a checkpoint watermark on failure. + Normal, +} +``` + +Added to `OpenOptions`: + +```rust +pub struct OpenOptions { + // ...existing fields... + /// See [`SyncMode`]. Defaults to `Full`. + pub synchronous: SyncMode, +} +``` + +`Default for OpenOptions` sets `synchronous: SyncMode::Full` — unchanged behavior for every +existing caller, including those using `..Default::default()` or the chainable builders. + +### Plumbing + +- `WalWriter` gains a `sync_mode: SyncMode` field, set in `open_or_create` (both call sites in + `db.rs`: initial `open()` at `db.rs:345` and the lazy re-create after checkpoint at + `db.rs:1126` need the mode threaded through — both currently call + `WalWriter::open_or_create(&wal_path)` with just a path). +- `append_entry` branches on `self.sync_mode`: `Full` → `self.file.sync_data()`, `Normal` → no + sync call. +- `SyncMode` is defined in `src/db.rs` next to `OpenOptions` (public API surface), used by + `src/wal.rs`. + +### Semver + +`OpenOptions` already has all-public fields and is not `#[non_exhaustive]`; a field addition here +rides the same pending semver bump as `allow_unlocked` (project memory: +`constraint_openoptions_semver_break`). No new decision needed — the version-bump session already +tracks this class of change; this issue adds one more field to that same bucket. + +### Docs (fix #2) + +Add a "Durability tuning" section (README + rustdoc on `OpenOptions::synchronous`) covering both +levers together: + +- Batch unrelated writes into one `begin_write()` + N `execute()` + one `commit()` to collapse N + fsyncs into 1, at the default `Full` durability — no tradeoff, just an underused existing + feature. +- Set `synchronous: SyncMode::Normal` for bulk-loaders that can tolerate re-running from a + checkpoint watermark on OS-crash/power-loss, in exchange for skipping the per-write fsync + entirely. + +## Testing + +- `wal.rs` unit tests: `Normal`-mode entries are still written and correctly replayed on reopen. + In-process tests can't observe whether `sync_data()`/`sync_all()` was actually called or skipped + — the durability *trade-off* is not unit-testable without OS-crash injection — so these tests + cover correctness of the write/replay path under both modes, not the fsync behavior itself. +- `db.rs` integration test: open with `synchronous: Normal`, write several transactions, + `checkpoint()`, reopen — facts present. Confirms the code path doesn't break correctness. +- Regression: existing WAL/crash-safety tests (the #308-era SIGKILL corruption tests) must keep + passing unmodified, since they exercise the unchanged `Full` default. +- No new test asserts `sync_data()` specifically is called in `Full` mode — no observable + in-process difference from `sync_all()`; covered by "no behavior change" rather than a direct + assertion. + +## Non-goals + +- No `OFF`/never-sync tier (see Decisions above). +- No runtime mode switching after `open()`. +- No per-`WriteTransaction` durability override. +- No change to `checkpoint()`'s own fsync behavior — it stays unconditional in both modes. diff --git a/src/db.rs b/src/db.rs index 8d6f4e56f7..1b5d4b40a4 100644 --- a/src/db.rs +++ b/src/db.rs @@ -67,6 +67,36 @@ fn memory_page_cache_capacity(_opts: &OpenOptions) -> usize { 0 } +// ─── SyncMode ──────────────────────────────────────────────────────────────── + +/// Controls how aggressively WAL writes are flushed to disk. +/// +/// Independent of [`Minigraf::checkpoint`], which always fsyncs the main +/// `.graph` file regardless of this setting — see [`OpenOptions::synchronous`]. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum SyncMode { + /// `fdatasync` after every WAL write. Default; matches Minigraf's + /// behavior before this option existed — every committed `transact`/ + /// `retract` is durable immediately. + Full, + /// No per-write flush. The WAL entry is still `write_all()`'d — safe + /// across an ordinary process crash — but not forced to disk until the + /// next checkpoint (auto-threshold, explicit `checkpoint()`, or clean + /// close), which fsyncs the main file directly rather than the WAL — + /// the WAL is simply deleted once the main file holds the same data. + /// Data written since the last checkpoint is lost only on OS crash or + /// power loss, not process death. Intended for bulk loaders that can + /// safely re-run from a checkpoint watermark on failure. + /// + /// Combined with [`OpenOptions::wal_checkpoint_threshold`] set to + /// `usize::MAX`, nothing is ever forced to disk for the handle's + /// lifetime — no per-write flush, no auto-checkpoint, and no + /// close-time checkpoint (the same sentinel also suppresses that). + /// Callers wanting a bounded durability window should keep an explicit + /// `checkpoint()` call or a finite threshold. + Normal, +} + // ─── OpenOptions ───────────────────────────────────────────────────────────── /// Configuration options for opening a `Minigraf` database. @@ -98,6 +128,15 @@ pub struct OpenOptions { /// This does **not** override a lock that another handle actually holds. /// Opening a database twice is refused regardless of this setting. pub allow_unlocked: bool, + /// Controls WAL write durability. See [`SyncMode`]. Defaults to `SyncMode::Full`. + /// + /// The other durability/throughput lever is batching: `begin_write()` + + /// several `execute()` calls + one `commit()` collapses every staged + /// fact into a single WAL write and a single fsync, regardless of this + /// setting. + /// + /// No effect on in-memory databases, which have no WAL. + pub synchronous: SyncMode, } impl Default for OpenOptions { @@ -108,6 +147,7 @@ impl Default for OpenOptions { max_derived_facts: DEFAULT_MAX_DERIVED_FACTS, max_results: DEFAULT_MAX_RESULTS, allow_unlocked: false, + synchronous: SyncMode::Full, } } } @@ -155,6 +195,13 @@ impl OpenOptions { self } + /// Set the WAL durability mode. See [`SyncMode`]. + #[must_use] + pub fn synchronous(mut self, mode: SyncMode) -> Self { + self.synchronous = mode; + self + } + /// Set the path for a file-backed database. #[cfg(not(target_arch = "wasm32"))] pub fn path(self, path: impl AsRef) -> OpenOptionsWithPath { @@ -342,7 +389,7 @@ impl Minigraf { // Open the WAL writer only if the WAL file already exists from a previous session. // Otherwise, create it lazily on the first write. let wal = if wal_path.exists() { - Some(WalWriter::open_or_create(&wal_path)?) + Some(WalWriter::open_or_create(&wal_path, opts.synchronous)?) } else { None }; @@ -1123,7 +1170,7 @@ impl<'a> WriteTransaction<'a> { // Lazily open the WAL writer if not already open. if wal.is_none() { let wal_path = Minigraf::wal_path_for(db_path); - *wal = Some(WalWriter::open_or_create(&wal_path)?); + *wal = Some(WalWriter::open_or_create(&wal_path, opts.synchronous)?); } let wal_writer = wal @@ -1592,11 +1639,132 @@ mod tests { max_derived_facts: 100_000, max_results: 1_000_000, allow_unlocked: false, + synchronous: SyncMode::Full, }; let db = Minigraf::open_with_options(&path, opts).unwrap(); assert_eq!(db.inner.options.wal_checkpoint_threshold, 5); } + #[test] + fn test_sync_mode_defaults_to_full() { + assert_eq!( + OpenOptions::default().synchronous, + SyncMode::Full, + "default sync mode" + ); + } + + #[test] + fn test_sync_mode_builder_sets_normal() { + let opts = OpenOptions::new().synchronous(SyncMode::Normal); + assert_eq!( + opts.synchronous, + SyncMode::Normal, + "builder should set Normal" + ); + } + + // ── file-backed: normal sync mode survives checkpoint and reopen ───────────── + + #[test] + fn test_normal_sync_mode_survives_checkpoint_and_reopen() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("test.graph"); + + { + let db = OpenOptions::new() + .synchronous(SyncMode::Normal) + .path(&path) + .open() + .unwrap(); + db.execute(r#"(transact [[:alice :name "Alice"]])"#) + .unwrap(); + db.execute(r#"(transact [[:bob :name "Bob"]])"#).unwrap(); + db.checkpoint().unwrap(); + } + + let db = Minigraf::open(&path).unwrap(); + let facts = db.inner.fact_storage.get_asserted_facts().unwrap(); + assert_eq!( + facts.len(), + 2, + "both facts should survive checkpoint + reopen under Normal sync mode" + ); + } + + // ── file-backed: sync mode is plumbed through to both WalWriter call sites ── + + #[test] + fn test_normal_sync_mode_reaches_both_wal_writer_call_sites() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("test.graph"); + + { + // Lazy-reopen call site (wal_write_stamped_batch): opened here because + // no .wal file exists yet, so open_with_options leaves `wal: None` and + // the first write creates it lazily. + let opts = OpenOptions { + synchronous: SyncMode::Normal, + wal_checkpoint_threshold: usize::MAX, + ..OpenOptions::default() + }; + let db = opts.path(&path).open().unwrap(); + db.execute(r#"(transact [[:alice :name "Alice"]])"#) + .unwrap(); + + let ctx = db.inner.write_lock.lock().unwrap(); + match &*ctx { + WriteContext::File { wal, .. } => { + let wal_writer = wal.as_ref().expect("WAL should be open after a write"); + assert_eq!( + wal_writer.sync_mode(), + SyncMode::Normal, + "lazy-reopen call site should honor opts.synchronous" + ); + } + WriteContext::Memory => panic!("expected file-backed WriteContext"), + } + drop(ctx); + // Handle drops here without checkpointing: wal_checkpoint_threshold == + // usize::MAX suppresses both auto-checkpoint and the close-time + // checkpoint in `Inner::drop`, so the .wal file survives on disk. + } + + let wal_path = { + let mut p = path.as_os_str().to_owned(); + p.push(".wal"); + std::path::PathBuf::from(p) + }; + assert!( + wal_path.exists(), + "WAL file must survive the drop of a Normal-sync, MAX-threshold handle" + ); + + // Initial-open call site (open_with_options): the .wal file already + // exists on disk from the previous block, so this reopen constructs the + // WalWriter eagerly instead of lazily on first write. + let db = OpenOptions::new() + .synchronous(SyncMode::Normal) + .path(&path) + .open() + .unwrap(); + + let ctx = db.inner.write_lock.lock().unwrap(); + match &*ctx { + WriteContext::File { wal, .. } => { + let wal_writer = wal + .as_ref() + .expect("WAL should be opened eagerly since the .wal file pre-existed"); + assert_eq!( + wal_writer.sync_mode(), + SyncMode::Normal, + "initial-open call site should honor opts.synchronous" + ); + } + WriteContext::Memory => panic!("expected file-backed WriteContext"), + } + } + // ── failed commit leaves database unchanged ─────────────────────────────── #[test] diff --git a/src/lib.rs b/src/lib.rs index 41e4a4776d..12c448d36d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ pub mod browser; #[cfg(not(target_arch = "wasm32"))] pub use db::OpenOptionsWithPath; -pub use db::{Minigraf, OpenOptions, WriteTransaction}; +pub use db::{Minigraf, OpenOptions, SyncMode, WriteTransaction}; pub use repl::Repl; // EAV value types — users construct and match on these diff --git a/src/wal.rs b/src/wal.rs index 5db70135f5..41fc04695a 100644 --- a/src/wal.rs +++ b/src/wal.rs @@ -19,6 +19,7 @@ //! facts: for each fact: fact_len: u32 LE | fact_bytes: [u8; fact_len] //! ``` +use crate::db::SyncMode; use crate::graph::types::Fact; use crate::storage::packed_pages::MAX_FACT_BYTES; use anyhow::{Result, bail}; @@ -142,6 +143,7 @@ pub struct WalEntry { /// Not used for in-memory databases. pub struct WalWriter { file: File, + sync_mode: SyncMode, } impl WalWriter { @@ -149,7 +151,7 @@ impl WalWriter { /// /// If creating, writes the WAL header. /// If opening, validates the header and seeks to the end for appending. - pub fn open_or_create(path: &Path) -> Result { + pub fn open_or_create(path: &Path, sync_mode: SyncMode) -> Result { // Try atomic create-new first (no TOCTOU window) match OpenOptions::new() .read(true) @@ -160,7 +162,7 @@ impl WalWriter { Ok(mut file) => { write_wal_header(&mut file)?; file.seek(SeekFrom::End(0))?; - return Ok(WalWriter { file }); + return Ok(WalWriter { file, sync_mode }); } Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {} Err(e) => return Err(e.into()), @@ -176,17 +178,28 @@ impl WalWriter { WalHeaderState::Absent => write_wal_header(&mut file)?, } file.seek(SeekFrom::End(0))?; - Ok(WalWriter { file }) + Ok(WalWriter { file, sync_mode }) } - /// Serialize `facts` as a WAL entry and append it to the file, then fsync. + /// The `SyncMode` this writer was opened with. Used only in tests, to + /// verify that `SyncMode` reaches `WalWriter` from every call site. + #[cfg(test)] + pub(crate) fn sync_mode(&self) -> SyncMode { + self.sync_mode + } + + /// Serialize `facts` as a WAL entry and append it to the file. /// /// The entry is written atomically from the caller's perspective: /// a partial write produces a bad CRC32, which the reader discards. + /// Then flushes to disk, unless `sync_mode` is `SyncMode::Normal` — see [`SyncMode`]. pub fn append_entry(&mut self, tx_count: u64, facts: &[Fact]) -> Result<()> { let entry_bytes = serialize_entry(tx_count, facts)?; self.file.write_all(&entry_bytes)?; - self.file.sync_all()?; + match self.sync_mode { + SyncMode::Full => self.file.sync_data()?, + SyncMode::Normal => {} + } Ok(()) } @@ -365,7 +378,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("test.wal"); - let _writer = WalWriter::open_or_create(&path).unwrap(); + let _writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); let mut reader = WalReader::open(&path).unwrap(); let entries = reader.read_entries().unwrap(); @@ -380,7 +393,7 @@ mod tests { let alice = Uuid::new_v4(); let fact = make_fact(alice, ":name", Value::String("Alice".to_string()), 1); - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); writer.append_entry(1, std::slice::from_ref(&fact)).unwrap(); let mut reader = WalReader::open(&path).unwrap(); @@ -393,6 +406,27 @@ mod tests { assert_eq!(entries[0].facts[0].value, fact.value); } + #[test] + fn test_wal_normal_mode_write_and_replay() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("test.wal"); + + let alice = Uuid::new_v4(); + let fact = make_fact(alice, ":name", Value::String("Alice".to_string()), 1); + + // Normal mode skips the per-write flush; the entry must still be + // durable-within-process (write_all()'d) and correctly replayable. + let mut writer = WalWriter::open_or_create(&path, SyncMode::Normal).unwrap(); + writer.append_entry(1, std::slice::from_ref(&fact)).unwrap(); + + let mut reader = WalReader::open(&path).unwrap(); + let entries = reader.read_entries().unwrap(); + assert_eq!(entries.len(), 1); + assert_eq!(entries[0].tx_count, 1); + assert_eq!(entries[0].facts.len(), 1); + assert_eq!(entries[0].facts[0].entity, fact.entity); + } + #[test] fn test_wal_multi_fact_entry_round_trip() { let dir = tempfile::tempdir().unwrap(); @@ -404,7 +438,7 @@ mod tests { make_fact(alice, ":age", Value::Integer(30), 1), ]; - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); writer.append_entry(1, &facts).unwrap(); let mut reader = WalReader::open(&path).unwrap(); @@ -427,7 +461,7 @@ mod tests { let alice = Uuid::new_v4(); let bob = Uuid::new_v4(); - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); writer .append_entry( 1, @@ -462,7 +496,7 @@ mod tests { let bob = Uuid::new_v4(); // First open: create WAL and write entry with tx_count=1 - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); writer .append_entry( 1, @@ -477,7 +511,7 @@ mod tests { drop(writer); // Second open: exercises the fallback branch (file already exists) - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); writer .append_entry( 2, @@ -538,7 +572,7 @@ mod tests { std::fs::write(&path, b"MW").unwrap(); - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); let alice = Uuid::new_v4(); let fact = make_fact(alice, ":name", Value::String("Alice".to_string()), 1); writer.append_entry(1, std::slice::from_ref(&fact)).unwrap(); @@ -572,7 +606,7 @@ mod tests { let fact = make_fact(alice, ":name", Value::String("Alice".to_string()), 1); // Write a valid entry - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); writer.append_entry(1, &[fact]).unwrap(); drop(writer); @@ -592,7 +626,7 @@ mod tests { fn test_wal_delete_file() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("test.wal"); - WalWriter::open_or_create(&path).unwrap(); + WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); assert!(path.exists()); WalWriter::delete_file(&path).unwrap(); assert!(!path.exists()); @@ -606,7 +640,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("test.wal"); - let mut writer = WalWriter::open_or_create(&path).unwrap(); + let mut writer = WalWriter::open_or_create(&path, SyncMode::Full).unwrap(); let entity = Uuid::new_v4(); let fact = Fact::new(