Skip to content

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

Merged
orelvis15 merged 3 commits into
mainfrom
feat/sync-mode
Sep 4, 2026
Merged

orelvis15 merged 3 commits into
mainfrom
feat/sync-mode

Conversation

@orelvis15

Copy link
Copy Markdown
Collaborator

Same branch and commits as #7, which GitHub closed when its base branch (#6, merged) was deleted. See #7 for the full description: SyncMode (Full / Fsync / Barrier) and GlobalStore::set_sync_mode; a small publish's asset records ride inside its journal record (publishes above 16 KiB of records still write a pack). Consumed by terragov/cavs-db's Durability modes.

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 merged commit 774639d into main Sep 4, 2026
10 checks passed
@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