Notes: a save writes its file while history records it, and doesn't wait for "done" (#298) #378

Closed
kayg wants to merge 1 commit from issue/298-save-overlap into dev
Owner

Part of #298 (storage latency). Independent of the other #298 PRs (its numbers come from their storage-bench).

What
A note save made four flushes one after another: the pending record in history, the new file, the folder, then the "done" record. Now:

  • the new file is written and flushed under its temporary name while history records the pending save, and swapped in only once that record is durable, so "history before the file" (ADR 0020) still holds;
  • the "done" record (promote) is queued without waiting. If a crash loses it, the pending row still matches the file on disk, and the next start promotes it: room/load.rs already handles exactly that case.

fsio::write_unless_changed is split into Prepared::new (write and flush the temporary file) and Prepared::place (check the file, swap in, flush the folder); write_unless_changed is the two in a row, unchanged for its callers. A Prepared that is dropped unplaced removes its temporary file. History gets set_pending_queued and promote_queued.

Checked with strace on the VM: per save, the history flush and the temporary file's flush now run at the same time, then the folder; "done" lands later.

Numbers (perf VM, NVMe zvol, storage-bench save, 200 saves of 0.5–30 KB notes, median of 3 runs; dev vs this):

p50 p90 p99
dev 39.8 53.6 127.5
this 16.2 27.2 134.6
dev, 300 KB note 59.8 89.9 117.4
this, 300 KB note 31.0 47.8 91.3

The p99 is the disk's own flush noise on this VM (a raw 4 KiB flush is p99 5–60 ms depending on the hour; see #298).

Tests: all notes tests (crash before and after the write, a write error after the rename, #222 swaps), and a new fsio test that an unplaced write leaves the file and no temp file behind.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Part of #298 (storage latency). Independent of the other #298 PRs (its numbers come from their `storage-bench`). **What** A note save made four flushes one after another: the pending record in history, the new file, the folder, then the "done" record. Now: - the new file is written and flushed under its temporary name **while** history records the pending save, and swapped in only once that record is durable, so "history before the file" (ADR 0020) still holds; - the "done" record (`promote`) is queued without waiting. If a crash loses it, the pending row still matches the file on disk, and the next start promotes it: `room/load.rs` already handles exactly that case. `fsio::write_unless_changed` is split into `Prepared::new` (write and flush the temporary file) and `Prepared::place` (check the file, swap in, flush the folder); `write_unless_changed` is the two in a row, unchanged for its callers. A `Prepared` that is dropped unplaced removes its temporary file. `History` gets `set_pending_queued` and `promote_queued`. Checked with strace on the VM: per save, the history flush and the temporary file's flush now run at the same time, then the folder; "done" lands later. **Numbers** (perf VM, NVMe zvol, `storage-bench save`, 200 saves of 0.5–30 KB notes, median of 3 runs; dev vs this): | | p50 | p90 | p99 | |---|---|---|---| | dev | 39.8 | 53.6 | 127.5 | | this | **16.2** | **27.2** | 134.6 | | dev, 300 KB note | 59.8 | 89.9 | 117.4 | | this, 300 KB note | **31.0** | **47.8** | 91.3 | The p99 is the disk's own flush noise on this VM (a raw 4 KiB flush is p99 5–60 ms depending on the hour; see #298). **Tests**: all notes tests (crash before and after the write, a write error after the rename, #222 swaps), and a new fsio test that an unplaced write leaves the file and no temp file behind. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Notes: a save writes its file while history records it, and doesn't wait for "done" (#298)
Some checks failed
CI / server (pull_request) Successful in 1m13s
CI / rust (pull_request) Failing after 1m34s
CI / web (pull_request) Failing after 2m24s
9c3ce334cf
A note save made four flushes one after another: the pending record in
history, the new file, the folder, and the "done" record. Now the new
file is written and flushed under its temporary name while history
records the pending save, and swapped in once that is durable (history
before the file still holds, ADR 0020). The "done" record is queued
without waiting: if a crash loses it, the pending row still matches the
file and the next start promotes it (room/load.rs already does).

fsio's write_unless_changed is now Prepared::new (write and flush the
temporary file) plus Prepared::place (check and swap in).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Replaced by a new PR from issue/298-save-overlap-2: this version stopped waiting for the "done" record, which CI's edit_while_closed_is_merged_on_open showed can double text after a crash plus an outside edit. The new one waits for it. Details on #298.

Replaced by a new PR from `issue/298-save-overlap-2`: this version stopped waiting for the "done" record, which CI's `edit_while_closed_is_merged_on_open` showed can double text after a crash plus an outside edit. The new one waits for it. Details on #298.
kayg closed this pull request 2026-10-15 03:15:35 +00:00
Some checks failed
CI / server (pull_request) Successful in 1m13s
CI / rust (pull_request) Failing after 1m34s
CI / web (pull_request) Failing after 2m24s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!378
No description provided.