Skip to content

ledger: store each catalog record once, and a command that converts a ledger - #127

Merged
krokicki merged 5 commits into
mainfrom
ledger-record-bodies
Dec 1, 2026
Merged

krokicki merged 5 commits into
mainfrom
ledger-record-bodies

Conversation

@krokicki

@krokicki krokicki commented Dec 1, 2026

Copy link
Copy Markdown
Member

Why

buffer-api's ledger kept a full copy of every catalog record for every synced catalog commit. On a ledger of 552 MB, 95% was the records table: 31 commits, 68,153 rows, 2,296 distinct record bodies. It grew about 18 MB a day, and every timed backup carried the same weight.

What changes

  • records holds a commit's ids and paths and names each body by the SHA-256 of its stored text. A new record_bodies table holds each body once, however many commits have it. Every synced commit is kept, so a plan over an older commit reads what it read before.
  • mia exec mia-buffers ledger migrate converts an existing ledger in one transaction and gives the freed space back. It refuses while buffer-api answers and finds nothing to do when run again.
  • A start, restart or release never converts stored data. The ledger reads and writes both shapes, so the code can be released first and the conversion run later, between mia down and mia up.

Measured

Ledger Before After Time
31 commits, 68,153 rows 552 MB 57 MB 2.5 s
35 commits, 77,399 rows 625 MB 60 MB 3.7 s

A sync adds about 0.5 MB afterwards. On both, every commit read back identical (paths, ids and stored body text) and SQLite's integrity check passed. The second is a running installation that was converted by the runbook and came back with the same running workflows.

Rollout

Runbook in docs/deployment.md ("converting the ledger's catalog records"): release, mia down, copy the ledger with its -wal and -shm files, ledger migrate, mia up. Code from before this change cannot read a converted ledger; the runbook says how to go back.

Notes for review

  • Design and the alternatives considered (pruning old commits, compression, files, Postgres) are in docs/specs/2026-11-26-ledger-record-bodies.md.
  • The read and write paths for an unconverted ledger (_whole_records in Ledger) can be removed once every installation is converted.
  • No workflow or activity code changes.

🤖 Generated with Claude Code

krokicki and others added 5 commits November 29, 2026 18:33
The ledger stores the whole catalog again on every daily sync: 95% of a
552 MB file is 30 copies of the same 2,296 records. The spec keeps every
synced ref and stores each record body once by content hash, converting
an existing ledger at open. Measured on a copy: 57 MB, 0.54 MB per sync.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A start converts nothing: buffer-api refuses a ledger in the old shape and
names the command, the buffers check gains a ledger line so a release stops
before it flips, and mia-buffers ledger migrate does the conversion and the
vacuum between mia down and mia up.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…erts a ledger

records names each body by the hash of its text and record_bodies holds a
body once however many synced refs contain it. A ledger whose records still
holds a body in every row is read and written as it is: opening one never
changes its shape. mia-buffers ledger migrate converts the file in one
transaction and vacuums it, and refuses while buffer-api answers.

On a copy of a 552 MB ledger with 31 refs: 57 MB after 2.5 s, every ref
reads back equal.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…(v0.3)

The runbook is down, copy, ledger migrate, up. The spec no longer has
buffer-api refuse an unconverted ledger: a release always runs the buffers
check, which needs buffer-api up, so the code has to run on either shape.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mia down left a -wal file beside dev's ledger; a copy of the main file alone
could miss writes. mia down also stops a managed Temporal, so the step no
longer says it keeps running.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@krokicki
krokicki merged commit 8ceba9e into main Dec 1, 2026
1 check passed
@krokicki
krokicki deleted the ledger-record-bodies branch December 1, 2026 16:25
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