Skip to content

store: the caller chooses what a sync waits for - #7

Closed
orelvis15 wants to merge 3 commits into
perf/ledger-journalfrom
feat/sync-mode
Closed

orelvis15 wants to merge 3 commits into
perf/ledger-journalfrom
feat/sync-mode

Conversation

@orelvis15

@orelvis15 orelvis15 commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

What

Stacked on #6. Every sync point in cavs-store went through Rust's sync_all, which on macOS is F_FULLFSYNC (the drive's cache flushed, milliseconds per call). SQLite and PostgreSQL default to fsync(2) there. SyncMode names the choice and GlobalStore::set_sync_mode applies it to the packfile, the record pack, the ledger journal and snapshot and their directory syncs; PackWriter::finish_with takes it, finish stays Full.

mode macOS elsewhere
Full (default, unchanged) F_FULLFSYNC fsync
Fsync fsync(2) fsync
Barrier F_BARRIERFSYNC fdatasync

The write order — chunks before the ledger that names them — is the same in every mode. Consumed by cavsdb::Durability::{Full, Standard, Batch, Relaxed} in terragov/cavs-db#9.

A small publish's records ride in its journal record. The record pack was a third file and a third sync per publish; for a one-file save it holds three kilobytes. The journal record now carries a publish's asset records inline, the ledger keeps each asset's byte range in the journal, and a snapshot moves every record still living in a journal into one pack before it is written. Measured with every publish inline first: a 200-asset commit's journal grew 60 KB a save instead of 34, the snapshot rotated twice as often and commit-cost lost 16%; so a publish above 16 KiB of records still writes a pack and the journal names it. With that rule commit-cost stays where it was (Standard 10,881 obj/s) and a one-file graph save at Full goes from 14.2 ms to 11.1–12.1.

Tests

One per SyncMode on a publish/reopen round trip, the mode helpers on a file and a directory, and the journal/record tests extended for inline records (a batch's records ride in its journal record; a snapshot moves them into one pack and reads follow). Workspace clippy (-D warnings), fmt and tests green.

Every sync point in the store went through Rust's sync_all, which on
macOS is F_FULLFSYNC: the drive's cache flushed, milliseconds per call
on a laptop SSD, and five of them in a cavsdb commit were three quarters
of what the commit cost after the ledger stopped growing with the store.
SQLite and PostgreSQL default to fsync(2) on the same machine, which is
what the comparison against them was silently paying for.

SyncMode names the choice — Full, Fsync, Barrier — and set_sync_mode
applies it to the packfile, the record pack, the journal, the snapshot
and their directory syncs. The order of writes does not change with the
mode: a chunk is on its way to the drive before the ledger names it in
every one of them. Full stays the default, because the store does not
know what it is asked to hold.
A publish wrote its asset records to a record pack of their own — one
file and one sync per commit next to the pack and the journal. For a
one-file save that file is three kilobytes, and the sync it costs is the
same as the ledger's.

The journal record now carries a publish's records inline, so the
ledger and the records are one append and one sync; the ledger keeps
each asset's byte range in the journal, and a snapshot is written only
after every record still living in a journal has moved into one record
pack the snapshot can name. Reads follow the reference wherever it
points: a pending publish, a journal, a pack, a flat file from before.

Measured both ways before settling the rule. Every publish inline made
a 200-asset commit's journal grow at 60 KB a save instead of 34, the
snapshot rotate twice as often and the rotation carry the migration:
commit-cost lost 16% at Standard. So a publish above 16 KiB of records
still writes a pack and the journal only names it, which keeps
commit-cost where it was (Standard 10,881 objects/s) and gives the
one-file graph save the fewer files: 11.4 ms at Full against 14.2 with
the pack, 4.6 at Standard against 4.9.

A journal reference read from a pre-1.8 index.json is discarded, and a
record whose journal is gone loses its record rather than blocking the
save that would have moved it.
@orelvis15
orelvis15 deleted the branch perf/ledger-journal September 4, 2026 01:33
@orelvis15 orelvis15 closed this Sep 4, 2026
@orelvis15
orelvis15 deleted the feat/sync-mode branch September 4, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant