~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A log is given room ahead, so a sync carries no change of size

Closed
Closed chadtmiller.com asked to merge into main from chadtmiller.com/monolith:store/log-ahead
Claude Fable 5.2

What changes

A log is given room ahead: zeros after its frames, written by the commit that grows the file, so that the commits after it sync a file whose size does not change. Frames are written at their offsets. The first frame since a log was opened makes no room; a later one that does not fit grows the file by itself and as much again as was written since the log was opened, up to 256 KiB and to what is left before the log is compacted by size. Room is given back before a seal, when the pool closes the file, and at a start. A log ends at its last whole frame: zeros are no frame.

A log's file is locked (flock, exclusive, not waited for) for as long as a Wal holds it open to write to: frames written at offsets are not kept apart by the system as appended ones are, so a second handle on a log is an error, ResourceBusy, and writes nothing.

crates/pds-store (lib.rs, generations.rs), and in pds-server what reads a log's size, and the tests that kept two servers on one data directory.

Why

On the runner a sync of a file that grew takes 19 ms and one of a file that did not 5 to 12 (the store benchmark, "allocated ahead" rows).

How it was checked

  • cargo test -p pds-store (38) and -p pds-server (362) on this branch; new: a write torn in room at every byte, zeros read as no frame, logs with no room carried on, a log has one writer.
  • The gates workflow passed on it, at b4d1390 and at 7b5a816.
  • The store benchmark on the runner, "a log for each account, JSON frames (the server's)", commits a second, each run beside the gates workflow's:
writers / accountsmain (five runs)roomroom and the lock
4 / 40195 to 200402450
16 / 40599 to 727988909
64 / 20002624 to 317225082601
256 / 20007377 to 936395895763

Shortcomings

A draft, not ready:

  • The last row with the lock, 5763 against 7377 to 9363, is not explained. An open with the lock costs 0.4 µs more on Linux, which cannot be it; the run shared the runner with another. It wants the benchmark asked for alone (store-bench at this branch), twice, before anything is concluded: if a log for many accounts each written once or twice is slower with room, room should begin at a third frame, or not be made at all.
  • On a Mac a log for each of 2000 accounts is a tenth to a fifth slower with room (823 to 686 commits a second at 256 writers): the zeros a second commit writes, which nothing then uses.
  • Merged with main as it is now, one of the firehose's tests fails (events::tests::an_index_cut_short_is_no_index, at cache.rs:448): it keeps a second server on a data directory, as the tests fixed here did. The merge is the branch store/log-ahead-stacked.
  • The crash runs of just nightly have not been run on it here, as a change to how the server stores must be.

Review

Not yet.

Closed for the pull that carries this with the changes it was stacked beside: 3n25dt62arysq, "The store reads and syncs less: open files, XXH3, clean starts, room". There a log's room is made from its first frame, its file is locked while it is open, and the room is given back when the log is closed.