chadtmiller.com/monolith
An atproto PDS
0
0
A log's age is read from its files: the first write after 2 W compacts
Merged Approved
This makes a log's age for Policy::max_age run from its files' times (began, read at open), so the first write after 2 W compacts even across a restart or a reload. spec/STORE.md states the behaviour and the new harness step, so spec and code agree.
began: it reads the times before the open repairs anything. A sealed log counts from its seal time. An appended log counts from the earlier of its birth and last change. Unreadable or future times count as now, which only delays a fold and never causes a wrong one.- Tests:
compacts_by_ageis updated, andcompacts_by_age_its_files_tellcovers the four sealed/old combinations. - Harness: the harness change makes the check stricter. It adds a burst, a restart and a settled check without prior reads, and keeps the old check.
- Scope: I found no new crates and no
docs/guidemention of the settled check that would need updating. I did not run the code.
Merged as 3218378
After a restart, an account that had been quiet for
2 Wkept its old events and folded writes on disk indefinitely: its first write did not compact it. On a staged server, after a night's soak, that left the data directory at 2.1 times the settled bound. Now a log's age is read from its files, so the first write after2 Wcompacts it, restarted or not.Claude Opus 5.5
What changes
spec/STORE.md. "Bounds", "Settled": the quiet
2 Wholds whether or not the server was started again meanwhile. "How it is checked": the--storerun ends by rewriting every key of every account eight times, waiting2 W, killing and starting the server, and writing once to each account with nothing read first, then holding the data directory to the settled bound within 10 seconds; then the check it had, without a start.harness/checks/store.mjs. That step, and the settled check as
settled(why), run twice.crates/pds-store. A log's generation age, for the age trigger (
Policy::max_age), counts from when its file was made, read from the file's times when the log is opened (generations.rs,began), not from when this process opened it:Inner::beforeholds how old the generation already was, and the trigger comparesbefore + began.elapsed()withmax_age. A log the open itself makes after a sealed one takes the sealed log's time; a new log, or times that cannot be read or are in the future, now. Nothing new is written to disk.crates/pds-server. Docs of the account and service policies only: both open through
Wal::open_log_with, so accounts loaded at first use, stores the cache loads again, and the service log are all fixed by the one change.Why
An account's store is loaded on its first use after a start, and its log's age began at that load. The first write after a start therefore found a young log: no fold by age, and none by size either, its log being smaller than its table. Nothing folds a store on quiet time alone, so the events past the window and the writes since the last fold stayed. The
--storerun never restarted between its quiet and its write, and read every account after its restart, which loaded every store, so it could not see it.Seen on spec-pds.chadtmiller.com after a night's soak of 50 accounts beside the reference: repositories of 33 MiB in all, tables of 1130 MiB; restarted with
Wof 5 minutes, quiet for 12, then a write to each account, no table was rewritten and the data directory stayed at 1580 MiB against a bound of about 745.How it was checked
inner.beforeleft at zero): the same failure.node compare.mjs --store --crash-every 40 --steps 120passes, both settled checks ok, the settled size 1.10 times the live state.cargo test -p pds-store --lib generations: 33, among themcompacts_by_age, which pinned the old behaviour and now holds a log opened after its age to fold on its first write, andcompacts_by_age_its_files_tell, new: a log written to and a sealed one, old and young by their files' times, folding on their first write only when old, each surviving a start after.Wof 2 minutes, 4 minutes of load, stopped, quiet past2 W, started again, one write to each): before, 37.5 MiB against a bound of 34.3, no table rewritten; after, 9.7 MiB, the tables rewritten.Shortcomings
2 Wlater than it could, as before this change.just quickwas not run here; the gates are thegatesworkflow's.Review
crates/pds-store/src/generations.rs,began: which file's times stand for when a generation began, and that they are read before the open repairs anything.