chadtmiller.com/monolith
An atproto PDS
The store reads and syncs less: open files, XXH3, clean starts, room
MergedThis pull makes four changes to the store: file-descriptor shares, the XXH3 PDSTAB02 table format, no sync at an account's first load after a clean shutdown, and room ahead of a log's frames. I found nothing that has to change.
The gates, docs, citations and store-bench-small runs all passed at the head commit.
I read the whole diff of spec/LIMITS.md, spec/STORE.md, docs/guide/operating.md, docs/guide/deploying.md, harness/checks/scale.mjs, Cargo.toml, pds-store/src/files.rs and pds-server/src/store.rs. I read the first 330 lines of table.rs. I did not read the other files, mainly generations.rs, lib.rs, cache.rs, log.rs, ops.rs and the bench/store sources. I judged the crash-safety argument for the skipped sync from its description in store.rs, not from the code.
Against .knotless/review.md:
- Spec and docs:
- The changed behaviour is in
spec/LIMITS.mdandspec/STORE.md, and the guides are updated. - The table format and the log's room are described only in code comments. The spec describes neither on-disk format today, so this fits what is already there.
OPERATIONS.mdstill describespds_fsync_duration_secondsas a log's, a sealed log's, the directory's and a checkpoint's syncs. The pull says a dozen other syncs are now counted, so you may want to widen that wording.
- The changed behaviour is in
- Harness:
- The scale check is stricter. It asserts both fewer than 20 syncs after a shutdown and at least 200 after a kill.
- The
seqOfchange only ignores errors after the event has arrived, so it loosens no check. - The pull says the new check was run against the server as it was and failed.
- Dependencies:
xxhash-rustis the one new crate. It is not an atproto or MCP crate, andBSL-1.0is already indeny.toml. harness/conformance.yaml: it is not touched.
One gap, which the pull states itself: harness/upgrade/ holds no table, so --upgrade does not exercise reading PDSTAB01 tables. Only the server's own tests cover that. Regenerating that fixture with an account compacted would close it.
My earlier approval at eb08b99 still stands. I found nothing since that breaks it, but I could not read the code that changed since.
Seven commits came after that approval. By their messages they do these things:
spec/OPERATIONS.mdnow sayspds_fsync_duration_secondscounts every sync the server makes. That was the one wording gap I noted last round.- A pool no longer closes a log whose file a sync in flight holds.
- A compaction changes no entry of its log's directory once the log's files are let go.
- No store is loaded once a shutdown has closed the logs.
- A shutdown's word counts only in the directory it was written in. This closes the copied-directory hazard.
- The benchmark results were refreshed.
All of these tighten the crash-safety and locking argument I earlier flagged, and none loosens a check.
I did not read the diff since eb08b99, which is about 2,000 lines. My tools could not page through it, so I judged these commits from their messages alone. I did not read the code in lib.rs, generations.rs or store.rs, where the locking and shutdown changes are.
At the head commit the docs and citations runs passed. gates and store-bench-small were still running when I looked. Please make sure gates is green before merging.
My approval at 79a424f stands. The only change since is small, and I read it in full.
open_locked in crates/pds-store/src/lib.rs now retries a lock it finds held for up to 100 ms (LOCK_WAIT) before it reports the log as busy. The reason given is sound: a spawned child keeps its copy of the file, and the lock with it, until it execs. A log really held by another handle still fails, only 100 ms later. The retry loop is correct. It sleeps 1 ms between tries, and only WOULDBLOCK is retried. The new test a_lock_let_go_soon_is_waited_for covers it.
This changes no behaviour that spec/ describes, so no spec or doc update is needed. It loosens no harness check.
At this head, docs and citations passed. gates and store-bench-small were still running when I looked, so please make sure gates is green before merging.
Four changes to how the store reads and syncs, together: the logs and tables open at once follow the process's limit of file descriptors; tables are checked with XXH3 in a new version of their format; an account's first use after a shutdown syncs nothing; and a log is given room ahead of its frames, so that a commit's sync carries no change of the file's size.
Claude Fable 5.2
What changes
Open files (spec/LIMITS.md, "Open files and threads"). As it starts the server raises its limit of file descriptors to its hard limit. A share is a quarter of that, between 16 and 4096: 64 under a limit of 256, as before. At most a share of accounts' logs are open at once, and a share of their tables.
pds_store::files(new):limit,raise,share. The pool of open logs is ordered by last use, where it was a list searched at each append: made for 64, it now holds thousands.Tables' check. A new version of the table's format,
PDSTAB02: each block's, the index's and the filter's check is XXH3-64 where it was the first 8 bytes of SHA-256, the filter's hashes of a key are the halves of XXH3-128, and the footer has a check of its own, so that every byte of a table is under one.TableWriterwrites it;Tablereads both versions. A table of the version before with a count of entries its blocks could not hold is refused.xxhash-rustis the crate (BSL-1.0, indeny.toml's list).The first use after a shutdown (spec/STORE.md, "The first request to a cold account"). After a start that followed a shutdown the server syncs nothing for an account's first request: a shutdown closes every log, which makes every frame durable, before it leaves its mark, and the mark says so (
durable). After a kill a log is synced as it is first used, as before; and the server then makes the whole data directory durable in the background, since a later shutdown may saydurableonly of what some run has synced. A shutdown used to sync each log once and leave it open, so that a late append or a compaction's seal could sit unsynced under the mark: it closes them now. Once it has, no store is loaded. And the word is its directory's: the mark holds the file system's id, the inodes and the change times of the data directory and ofrepos, and a start takes the word only where all of them are as found, so that a copy of a stopped server's directory, whichspec/DURABILITY.mdsays may be made any way, is to the server as one killed. Every sync the store makes is now counted bypds_fsync_duration_seconds: those at a log's opening, and a dozen others, were not.Room. A log's frames are written at their offsets, and the commit that grows the file grows it by as much again as it writes, in zeros (within what the log may hold before it is compacted, 256 KiB at most): the next commits land in room, and their sync has no new size to make durable. Room is given back before a seal, when a store is let go, at a shutdown and at a start. A log's end is its last whole frame: zeros are no frame. A log's file is locked while it is held open to write to.
harness.
scale.mjs: on the start that follows the shutdown, 200 accounts first used raise the server's count of syncs by fewer than 20; after the kill that ends the run, 200 others by at least 200. ItsseqOftakes no error of a socket it has closed.bench/store, docs. The benchmark's rows of the server's tables and logs say what they now are.
docs/guide/operating.md: "Open files", and that a data directory this version has written is not one to go back from.Why
bench/store/RESULTS.md, the runner, alone: a record not in the cache 21.2 µs with 64 tables' files open and 12.0 with all, and 8.0 with XXH3 as the check, against RocksDB's 12.6; a listing of 50, 232 µs against 164 with XXH3, RocksDB 189; a commit's sync 18 to 39 ms on a log that grows and 8 to 15 on one with room. And each account's first use after any start synced its log, about 19 ms there.How it was checked
cargo test -p pds-store -p pds-serveron the four together: 64 and 406. Each change's own, new:.tmpand a sealed last log found after a shutdown are still mended and synced; a shutdown that does not finish leaves no word; a kill, a start, an account not loaded in that run, a shutdown, a start: that account's first load syncs, unless the run had made what it found durable before it shut down, and then it syncs nothing and reads right; a shutdown before that pass ends leaves no word.ulimit -n 256fail, the server out of descriptors; in the tables, the block's check skipped, a reader that knows one version, and the footer's check and the count's bound taken out, each caught by the store's tests. And a first load made to sync whatever the mark says: the harness's scale run, at 20,000 accounts to save the wait, fails,syncs as accounts are first used after a shutdown and a start, 486 against fewer than 20.generations.rs,lib.rs,ops.rs,cache.rs,store.rs), since the reviewer said it had judged that part from its description. It found no sequence that loses an answered write, and four things, each fixed here with a test that failed before: the word carried by a copy of the directory (above); the pool closing a log whose sync was in flight, so that the log's next append found its own lock held (a_pool_closes_no_file_held_elsewhere); a store loaded after a shutdown had closed the logs, whose mending the word did not cover (a_shutdown_loads_no_store,a_load_that_failed_leaves_no_word); and a compaction's rename and deletions not under the lock its check was made under (a_compaction_deletes_nothing_past_a_close).gatesworkflow on the runner. Its first run with the fixes failed inwaiters_share_syncs: a log dropped and opened again found its lock held, while another test of the same binary spawned children. On Linux a child's copies of its parent's files are closed a moment after the parent's spawn returns, so holdingspawningover the spawn was not enough there; a log's file found locked is now tried again for 100 ms before it is taken as held (a_lock_let_go_soon_is_waited_for). The server spawns nothing.gatesworkflow on the runner. Thenightlyworkflow asked for at this branch, the six crash runs, the performance step and the scale run at 100,000 accounts: all passed ateb08b99(the six crash runs in 735 s), before the four fixes above and the lock's wait. It was not run to its end at this head.bench/store/RESULTS.md), against whatmaindid there alone the same day and against RocksDB:main(RocksDB's writes with its log files written over and its groups grown.)
Shortcomings
docs/guide/operating.mdsays to back up first).harness/upgrade/holds no table, so--upgradepasses whatever a table's format: tables of the version before are held to the server's own test alone, until that fixture is written again with an account compacted.syncfson Linux; elsewhere each account's files are given to the drive and then one sync flushes it, about 5 s for 100,000 accounts on a Mac.main's (8107 against 15183): rows of a log for each account at 256 writers move that much between runs, so this is not shown to be a loss, nor shown not to be.mvof it, achown -Rorchmod -R, as a KubernetesfsGroupdoes at each start; and on a file system that gives no id (NFS, FUSE). Not covered: a file written over in place by something that leaves the mark and both directories untouched (rsync --inplace --ignore-times -tof the whole tree).syncfs, which on a FUSE mount other than virtiofs may not reach the disk.docs/guide/deploying.md).nightlyis asked for atmainonce this has merged, and a failure of it there is a revert of this pull.Review
crates/pds-store/src/generations.rs, "An open that syncs nothing", andcrates/pds-server/src/store.rs, "What a start syncs": the one argument for what may be skipped at a log's first open, with room and the lock in it.Files::make_room,touch,forgetincrates/pds-store/src/lib.rs: the pool's order of locks.table.rs: that every byte of aPDSTAB02table is under a check, and that an old table reads as it did.