~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Commits waiting on one log are answered together when its sync ends

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:store/wal-wait
Claude Fable 5.2

What changes

pds_store::Wal::wait no longer holds its lock through a sync. One waiter makes the sync, of every frame written by then; each waiter it covers is answered when it ends; one it does not cover waits for the next, or makes it. A sync that fails is the answer to every waiter it would have covered, and the log is left as it was for the next to try again.

Only crates/pds-store/src/lib.rs.

Why

A waiter whose frame a sync had covered was not answered until it got the lock, behind whichever waiter had begun the next sync: so each waited through a sync it did not need, and few commits shared one. On a log many write to at once that held the rate to what a few commits a sync give, however many waited.

The store benchmark, one log for all accounts, commits a second, before and after:

writersmacOS beforeafterLinux runner, waiters in turnwoken together
161309 to 16371784 to 1909324646 to 872
641441 to 18494588 to 59193892474 to 3180
2561387 to 14187664 to 121943547066 to 8289

(The Linux columns are the benchmark's own log written each way, and the changed Wal; the benchmark and its numbers are the pull at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n23iqtexohsq.)

The server keeps a log for each account, where nothing waits on the same log at once: its rate does not change (measured: 795 before, 775 to 788 after at 256 writers on macOS). Its service log is the one many wait on.

How it was checked

  • cargo test -p pds-store: 25, two new. waiters_share_syncs: eight writers of twenty frames each are all durable, in no more syncs than frames, and a frame on disk already needs none. a_failed_sync_fails_its_waiters: a sync that fails answers each waiter it covered with its error, and the next sync is tried.
  • cargo test -p pds-server: 360 pass on it.
  • The gates workflow passed on the same commit in the benchmark's pull (2cd075d).

Shortcomings

  • No check in the harness: nothing a client sees changes but how long a write takes when many wait on one log, and the server has no such log but the service's. The benchmark is where it shows.
  • With four writers one log is about 7% slower on macOS (469 to 499 before, 437 to 467 after): woken together, slightly fewer commits share a sync when few wait.
  • A waiter that follows a failed sync gets an error of the same kind and text as the one that made it, not the operating system's error value.

Review

wait's loop and Ending's drop: that no waiter returns before its frame is durable, and that none waits for ever when a sync fails or its maker panics.

Approved

This changes Wal::wait so the lock is not held through the fsync. One waiter makes a sync of every frame written by then, and the waiters it covers are woken when it ends.

I traced the two things you asked about.

  • No early return: wait returns Ok only when durable >= seq. durable is raised only after sync_written has synced the files, the sealed logs and the current file, or by rewrite, which makes the new file durable under the inner lock.
  • No waiter hangs:
    • Ending::drop clears going and calls notify_all on every exit, a panic included. After a panic, the woken waiters see going is false and one of them makes the next sync.
    • covered is set before the fallible self.file(), so an early failure still reports which frames it covered.
    • A waiter that misses a failure because a later sync has already begun just loops and retries. It does not hang.
    • rewrite raises durable without notifying, but a waiter only sleeps while a sync is going, and that sync's end wakes it.

No spec, docs or harness change is needed, because behaviour a client sees is the same. The module doc ("concurrent requests share one fsync") still holds. The two new tests cover sharing and failure, and the shortcomings you list are honest.

Merged as 1143e48