chadtmiller.com/monolith
An atproto PDS
0
0
pds-store: a journal segment leaves pds_log_bytes as it is deleted
Merged Approved
This pull fixes two flakes. In the journal, a deleted segment's bytes now leave kept under the state lock that Journal::bytes reads under, so the gauge no longer counts a segment that is already gone. In the harness, exportDropped excuses a missing span when the server's own log says it dropped an export.
What I found:
- Journal:
kept_byis filled from the adopting start and from each checkpoint swap. Its entries sum tokept(k.end - MAGIC_LENmatchesadopted.bytes). Removing a segment and subtracting its bytes under one lock is consistent. A segment missing from the map takes off 0, sokeptcan't underflow. Dropping the finalkept = 0is also safe. - Harness: The excuse applies only to a missing span, and every other attribute check is unchanged. With no earlier failure line,
Math.max()gives-Infinityand the comparison is false, so the check stays strict. - Spec and changeset: The spec change in
spec/OPERATIONS.md(Metrics and Spans) and the changeset both cover the behaviour change.
The pull also asked for no change to harness/conformance.yaml, and it makes none.
I found nothing that must change.
All checks have passed
3 passed, 1 skipped
1 skipped check
releaseSkippedMerged as 3935737
Two flakes of the operations checks ejected the PAR client_id pull (batch bb70d78353df). The
pds_log_bytesone was the server's: the journal took a deleted segment's bytes off the gauge only once every segment was deleted and each deletion synced, so a read between counted bytes no longer on disk. The spans one was the check's: it did not allow for an export the server had logged as failed outside the planned outage.Claude Opus 5.5
What changes
spec/OPERATIONS.md, "Metrics". What a let-go takes off
pds_log_bytesleaves the gauge as the file changes, neither before nor after: a read of the gauge begun once the change shows in the directory counts none of it, one ended before counts all of it, however long the server takes over what it does next. A journal segment's bytes leave as it is deleted, not once the directory is synced or the other segments are gone.pds-store, journal.rs. The journal keeps the record bytes of each earlier segment by number (
kept_by), from a checkpoint's swap and from an adopting start. A checkpoint deletes each segment and takes its bytes offkeptunder the state lock thatJournal::bytesreads under. Before,keptwas set to 0 only after the loop, with a directory sync after each deletion in between.spec/OPERATIONS.md, "How it is checked", Spans. Besides spans near the outage or a kill, a span may be missing from an export the server's log says it dropped: a
trace export failedline from the request's start until the schedule delay, two export timeouts and 1.5 s after its answer; or the last such line before its start, within a minute and the timeout, with no export taken since, while failures ran on unlogged..changeset/log-bytes-journal-segments.md, a patch: operators see the gauge stop counting deleted segments.
harness/checks/operations.mjs.
exportDroppedexcuses only a span that is missing: a SERVER span, a request'sfsyncspan, acreateAccount's CLIENT span, or the root span of a request line with notraceparent. A span that is there is held to everything as before, and a missing span with no such line still fails. Thepds_log_bytesfailure now also names which canary record it was.Why
Seed 33
--commands:pds_log_bytesread 5513716 before the canary's record and 2728933 after, with no file in the data directory changed between the two listings. About 2.78 MB of that was the journal. On Linux a checkpoint deletes its segments, syncing the directory after each, and only then setkeptto 0. The harness's first listing ran after the deletions and its first read of the gauge beforekeptwent to 0. So the gauge still counted segments that were gone, the drop landed between the two reads, and no file changed between the listings. The spec as written ("no sooner than that") allowed this, so a check against it could only be deterministic if the gauge moves with the file. The spec now says so, and the journal does it: the gauge and the deletion share the journal's lock, so a listing that sees a segment gone is followed by a read of the gauge that no longer counts it. A fold of a log already worked this way: the checkpoint is renamed into place, andsealedandcheckpoint_bytesare set, under the log's lock thatlog_bytesandcheckpoint_bytesread under. Main's suggestion of mtime or ctime would not help: every write appends to its account's log and the journal, so every try would count as changed and the check would hold nothing.Seed 5: the getSession at 01:47:45.014 and three requests after it had no spans. The server logged
trace export failed,timeout, at 01:47:48.089, and the receiver took no export between 01:47:42.673 and 01:47:53.407, then three in 200 ms. The server tried for the export timeout (3 s), dropped the batch and logged it, as spec/OPERATIONS.md, "Export", says. That is not a server bug. The receiver runs in the harness's own process, and it most likely did not answer because the harness was busy. The check excused spans only in the planned outage window.Fixes the flakes in batch bb70d78353df.
How it was checked
pds_log_bytes, the lag: an env-switched plant kept the old order (deleted segments' bytes taken off after the loop, 1.5 s later), with the harness waiting 2.5 s after the canary's account so that the journal's checkpoint deleted its segments before the first listing, and 1.5 s after the write. Seed 33--commandsfailed as the queue did: record 1 read 2895679 before and 2700365 after, with onlyevents.0.log,journal/4.logand the canary'srepo.0.loggrown between the listings: the run failed. With the fix and the same waits: 2696204 before and 2700009 after (+3805), and the run passed.pds_log_bytes, a gauge that ignores writes: unchanged from harness: pds_log_bytes grows across a write that lets nothing go, where it failed seed 31.~api/sign-inat 02:10:54.269 with no span. The same drop with atrace export failedline, as a real timeout leaves: the run passed (all 400 steps agree).--commandsand seed 5, with the fix: all four pass.cargo test -p pds-store journal: 34 passed.gatesworkflow's, on this pull.Shortcomings
An account loaded between the two reads of the gauge, with logs from before its checkpoint still on disk (a fold whose old logs are not yet deleted), changes the gauge with no file changed. The canary loads nothing else, so it should not come up. The spans excuse rests on the server's word: a server that logs failures it never had could hide lost spans for the 6.7 s or so after each such line, and only spans that are missing.