chadtmiller.com/monolith
An atproto PDS
0
0
Tables: files held open, blocks of 4 KiB, a block cache in parts
Merged Approved
This pull holds an account's table file open between reads, with at most 64 files open across the cache. It cuts data blocks to 4 KiB, stores shortened index keys, and splits the block cache into 64 locked parts under one byte budget. I found nothing that must change.
- Reopen check: a table opened again is accepted only if its device, inode, size and mtime match the ones it was opened from, and otherwise the read is an error. A snapshot holds the
Arc<File>it began with, so a compaction or delete can't swap it mid-send. - Shortened index keys:
shortengives a key at or after the block's last key and before the next block's first. I checked it for the prefix case, the 0xff case and strict ordering, whichopen_fileenforces.find,beforeand the grouped shared-prefix compare are correct, including when the search key is shorter than the shared prefix. Old tables with whole last keys read the same way, since readers never assumed whole keys. - File slots:
Slot::holdnever holds its own file lock while it takes the order lock, and eviction takes only one other slot's file lock at a time, so I see no lock inversion. Drops decrement the open count. - Cache:
putcounts bytes before it holds the item, takes one part lock at a time, and skips items over an eighth of the budget. - Spec and harness: the
openFilescheck now builds real tables, so it can fail on this rule, andLIMITS.mdstates the 64-table bound.STORE.mddoesn't describe the table layout, so the block-size change needs no spec edit.
I did not read bench/store/src/reads.rs, bench/store/README.md and bench/store/RESULTS.md, which are benchmark code and generated output. I also did not read the tests in table.rs from line 1230 on, and the checks that ran were not consulted.
Merged as 0a88af0
An account's table is read faster and by more threads at once: its file stays open between reads, its blocks are 4 KiB, and the block cache is in 64 parts. On the runner a record from the cache takes 1.6 µs where it took 4.2, sixteen threads read 994 thousand a second where they read 337 thousand, and an account touched holds 11.5 KiB where it held 34.8.
Claude Fable 5.2
What changes
spec/LIMITS.md, "Open files and threads". At most 64 accounts' tables are open at once, each one file descriptor, the least recently read closed to make room and opened again when next read; a repository or a space repo being sent holds its table's file until it is sent. Its check gives each of its 300 accounts a table.
harness/checks/limits.mjs. That check,
openFiles.crates/pds-store,
table.rs.BlockCache(pds_store::table::OPEN). A table whose file was closed opens it again at its next read and takes it only if its device, inode, size and time of change are those it was opened from: else the read is an error, never another table's bytes.TableWriterwrites blocks of 4 KiB, where it wrote 16. The index is cheaper, which is what makes that affordable: the shortest key that parts two blocks in place of a block's whole last key, and in memory each of sixteen keys as what follows the bytes it shares with the first: 17 to 23 bytes a block, where it took about 77. Tables written before read as they did.BlockCacheis in 64 parts, each behind its own lock, under one budget of bytes for all, counted before an item is held. A read looks in the cache before the bloom filter.crates/pds-server. The callers: a store opens its table once with the cache; a
getRepoand a space repo being sent hold the file they began with.bench/store. The reads part reads the tables as the server reads them now; a row with every file held open, one of the layout before, and the benchmark's own reader with other checks on the same 4 KiB files.
Why
The store benchmark, beside RocksDB on the runner: a record not in the cache took a table 27 µs against 12.6, a listing of 50 took 404 against 187, sixteen threads read 337 thousand records a second from the cache against 443 thousand, and an account touched held 34.8 KiB against 12.6. The file was opened for each block read, a block was 16 KiB, and the cache was behind one lock.
How it was checked
cargo test -p pds-store -p pds-server: 31 and 387. New: more tables read than may be open, none leaked, each still read; a table replaced or deleted while open (one replaced by another whose blocks sit at the same offsets with good checks reads as an error); a table in the layout before, built byte for byte, still reads; the cache's budget held under sixteen threads.gatesworkflow's runs; before isbench/store/RESULTS.mdas it was:ulimit -n 256(--limits,openFiles) had no account with a table: planted, tables' files never closed, it passed. It now gives each account three records of 140000 bytes, which compacts its log into a table, and reads one back from each after the start. Planted again:getLatestCommitunder the limit fails, the server out of descriptors. Against the server as it was, which opened a table's file for each block and held none, it passes, as it must: the rule is one this change could break, not one the server broke.just nightlyhere on this branch's head, the space repos' change under it as it has since merged: the six crash runs, the performance step and the scale run all pass.Shortcomings
Review
table.rs: that a table opened again is the one that was opened, and that the index's shortened keys part blocks as whole keys did.