chadtmiller.com/monolith
An atproto PDS
After a shutdown, the firehose's first message comes within a second
MergedThis adds events.index, written at an orderly shutdown and read at the next start, so the firehose's first message from a cursor no longer waits on a scan of every account. The index is taken only when its ceiling equals the one the start read from the service log, and the run's first event reserves seqs anew, so any run that numbered an event invalidates it. I found no flaw in that reasoning.
What I checked
index.rswrites the file to a temp name, syncs it and renames it. Reads reject a wrong version, ceiling, count or ordering, any torn or altered bytes, and a window shorter than the start's.settleinops.rsseals, syncs the logs, and only then writes the index. It writes none if any event is still on its way to disk. It also writes none if the events before the start are not yet found, or a scan is still running.- In
find_old,find_indexed,none_before,indexedandmerge, a deleted account's events and the service log's own events stay out of the index. A rejected index falls back to the scan. - The spec covers the behaviour:
STORE.md"Scale" andDURABILITY.mdare updated, and the scale run adds the new steps. The harness change makes the run stricter, and it adds a case that kills the server after a shutdown.docs/guide/comparing.mdis updated. The change adds no crates.
What I did not read
- I read only
events.rslines 431–860 at the head commit, plus the new tests the searches returned. The rest of that 1,572-line diff was not read: the seq reservation,landandpublishedchanges,find_indexed_soon, and most of the new tests. - The
gatesandstore-benchruns on this head were still running when I looked, so I have not seen their results.
Minor
spec/DURABILITY.mdalso adds "two accounts kept with one handle or one email" to the list of unrecoverable data. That is outside this pull's topic. Its body ties it to the earlier review that asked for it, so I took it as intended.
Since my approval at 2d42845, the only change is in harness/checks/scale.mjs. seqOf now resolves only once the write has also been answered, and rejects if the write fails. This fixes a race: the step that kills the server could otherwise run while the write was still in flight. The check gets stricter, not looser, and the change needs no spec or docs update. What I approved before stands.
Carried forward: the change this pull makes at af9a152fb609e78c1bf54835cd5cd91f47b3c5da is the one reviewed at 7ae74952e529093e47ce6b5181fa007c55d9b324, so that review stands. What is new comes from its base.
After a shutdown and a start, the firehose's first message no longer waits while the server reads every account: with 100,000 accounts it took 8.2 s. The server writes an index of the window's events as it shuts down and reads that at the next start. After a kill or a power cut it reads its accounts as before; nothing is added to a write.
Claude Fable 5.2
What changes
spec/STORE.md, "Scale". After a start that follows a shutdown (
SIGTERM), asubscribeReposwith a cursor is sent its first message within a second of asking, whatever the number of accounts; after a kill or a power cut the first such subscription may wait while the server reads its accounts' files, and is sent the same events. The scale run ends by asking for the firehose from cursor0on a start that followed a kill, as a relay would, however long that takes; writing a record; shutting the server down and starting it; asking from0and from the seq before that record's commit, each first message within a second; then writing another record, killing the server, and asking from the seq before that one's commit, which must be sent.spec/DURABILITY.md. Data that cannot be recovered stops the server as it starts, for what it reads then, and for what is one account's when that account is first used: what the review of at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n22xnkbjng7t asked to have said.
crates/pds-server.
events/index.rs, new:events.indexin the data directory, written beside itself, synced and renamed: a header (the greatest seq reserved in the service log, the greatest seq of an event before, the greatest let go, the window) and each event of an account's log in the window, its seq, time and account. About 36 bytes an event.ops.rs,events.rs: an orderly shutdown stops numbering events, makes the logs durable, and writes the index, if the server knows every event in the window: its own, and those before its start.events.rs:find_oldtakes the events before the start from the index when it holds, reading no account's files, and by the scan of every account when it does not. Once the server serves it reads a valid index in the background.Why
After a start, the first subscription with a cursor waited while the server read every account's files for the events made before the start: 8.2 s with 100,000 accounts on this Mac, the files in memory, and growing with the accounts. A relay asks with a cursor every time it reconnects.
An index made durable with each commit would hold after a power cut too, and was measured with the store benchmark as it then was: each commit waits on one more sync, shared by all accounts. From 16 writers that took writes from 363 a second to 144 on the Mac, and from 413 to 130 on the runner. So the index is written once, at shutdown: a deploy is the common restart, and a crash is where waiting is fair.
How it was checked
the firehose from 0, the first request after a start, 8200 ms against 1000. With this, 100,000 accounts, the machine busy: after a kill 14.9 s (8.2 s on a quiet one, as before); after a shutdown and a start, 438 ms from cursor0and 44 ms from the seq before the last commit (176 and 1 on a quiet one); after a shutdown, a start, a write and a kill, the commit written since is sent.the firehose from 0, after a shutdown and a startfails, 1507 ms against 1000; the index taken whatever its ceiling, andthe firehose after a shutdown, a start, a write and a killfails, the commit written since the shutdown never sent. No run of the harness shut the server down and then killed it before: that last step is new for it.events::tests: whatpublishedis at each kind of start, before and after a run's first events; 64 histories of kills, shutdowns and runs with no event, the events before the start found from the index before the run's first events, after them, on a subscriber's need or never; the index taken on one thread as events are numbered on another; a subscription from cursor 0 opened as a run's first events land; one over more accounts than logs are held open. Each holds a replay from 0 to every event made, in order, none twice, andpublishedto the last one's seq. Planted,exactnot lowering what is published andmergedropping the run's own events each fail several.just quickand the crash runs here. Of the crash runs' six, one failed after its 1000 steps agreed, in the spans check, with the machine at a load of 20 from other work; the--limitsrun fails the same way under that load onmain.gatesworkflow on this pull ran beside thestore-benchworkflow, which loads the runner's disk, and failed three times in three places it had passed before, none in what this pull changes.--migrate: at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3n23dcwizalsq. An OAuth token refused after a kill: at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3n242f36ybwsq. The metrics check'spds_firehose_seq: followed through the run's own seqs, the metric was right and the check had stopped listening in the middle of the replay, after a second with no event; its wait is fixed in a pull of its own (at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n242qjib4rsq), and the tests above were written to rule the server out.Shortcomings