read model: ETS rebuilt from the log, and no rocksdb (macula-ci-images#19) #26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "juno/19-off-rocksdb"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refs macula-io/macula-ci-images#19 — the mcl-mail step of "port them off, then delete".
What changes
The letter read model stops being a barrel_docdb database on the data volume and becomes an ETS
ordered_setowned by a process, rebuilt from the event store at every boot.mailboxes_read_modelis a gen_server owning two tables: the letters, keyed{CitizenDid, -DepositedAt, LetterId}so a forward walk reads newest first, and a small index for a fetch by id. The API is unchanged (upsert_deposited/2,carried/3,mark_replied/2,mark_archived/2,find/2,list_unarchived/3);open/1anddb/0are gone with the store.mailboxes_read_model_replayfills it at every start: pagesevoq_event_store:read_all_globalfrom position 0 in order, applies each event through the projection's ownproject/4(same shape, same metadata as the live feed), and stops only on a SHORT page — the store answering "nothing at that offset". A failed read, a raise, or a failed apply is a failure, never a short page: the owner drops both tables and starts again from 0.get_mailboxandget_letteranswer{error, replaying}until that replay reaches the end of the log, because an empty table would tell a citizen their mailbox is empty while it fills. The flag belongs to the table (design r=1 R2): it is created and dies with the process that owns the table, andproject_mailboxes_supisrest_for_onewith the owner first, so a restarted owner takes the projection with it and never opens over an empty table.barrel_docdband therocksdboverride are gone fromrebar.config;barrel_docdb/project_mailboxesare gone fromconfig/sys.config.src; the image builds inmacula-ci-otpand runs onmacula-pq-runtime, both pinned by digest on the forge registry, as the siblings do. README,architecture/README.mdand the C4 diagrams (SVGs regenerated) say the same. Version 0.7.0.Proof
Gates on the tip, in the pinned
macula-ci-otp@sha256:3e202cf7…image: compile rc=0,rebar3 lint(MCL_LINT=1) rc=0,rebar3 eunit: All 148 tests passed,rebar3 dialyzerrc=0. (rebar3 xrefis red onmcl_mail_store:ensure/2,/5, unused exports, the same on main; it is not a gate here.)New tests: the store tests now run on the ETS model, including the two readiness cases (a read refused until caught up, and a restarted model replaying before it answers); two more pin the gate itself — a report from another process leaves reads refused, and a failed replay leaves the owner answering
replaying; and the service tests replace the rocksdb pin guards with the plain-pair pins and "no rocksdb dependency or override".The replay at ~12 MB of letters
3,000 deposits of 4 KB through the real CMD desks into a store of 82 MB on disk, one owner started, the clock from
start_link/0to the first answered read:letters_read=3000of 3,000,table=3000, a fetch by idok,replay_ms=110— with the store's read index emptied first, so the replay pays the scan-and-sort a restart pays; with that index already built (as a boot's own subscription catch-up leaves it) the same replay is 65 ms. The measurement is a script, not part of the repository; the numbers are in the handoff.ci=for the tip isnoneon the forge for a reason that is not this branch's: both pull-request runs queued and no job on any repository has started for over half an hour (the runner pool), so the proof above is the same four gates run by hand in the pinned image.Behaviour changes, in the CHANGELOG
letter_idascending (the table's key order) instead of descending. The order stays total and flag-free, which is what a page cursor needs; no cursor outlives a release.read => trueshape the purge rule used to recognise — are not carried over: the model has no history but the log.Not in the suite
The replay against a real store: a test's reads reach evoq's own
.appdefault store id, not the service's, becausesys.configis what sets it at a release boot; the store itself starts. That gap is filed as mcl-mail#27.The letter read model was a barrel_docdb database on the data volume, which put the erlang rocksdb binding -- and a system librocksdb -- under a service whose letters are already durable in reckon-db and which replayed that log in full at every boot anyway. mailboxes_read_model now owns one ordered_set keyed {CitizenDid, -DepositedAt, LetterId}, plus a small index for a fetch by id. Nothing of it is written to disk: mailboxes_read_model_replay reads the whole event store through the projection's own project/4 at every start, in order, from position 0, and stops only on a short page -- so the replay and the live feed cannot disagree about what an event means, and every apply is idempotent the way the model already was. A read is refused, by name (replaying), until that replay reaches the end of the log: an empty table would answer "your mailbox is empty" while it fills. The flag belongs to the table -- it is created and dies with the process that owns it, and rest_for_one restarts the projection with it -- so a restarted model is never open over an empty table. barrel_docdb and the rocksdb override are gone with it; the image builds in macula-ci-otp and runs on macula-pq-runtime, both pinned by digest on the forge registry. Two behaviour changes, both in the CHANGELOG: same-millisecond ties now list by letter id ascending, and a letter read once under 0.6.1 gets the one grace read after the cutover. Refs macula-ci-images#19The gate opened on any `replayed` report that reached the owner, because the report carried no sender. The owner is called by name, and a driver that ends normally is not killed with its owner, so a leftover driver could open a later owner's gate over a table nobody filled. The replay now reports with its own pid, and the owner believes only the driver it started -- for the failure report too. After a report it is no longer the driver, so the exit that follows is not treated as a failure. A failed replay also left the owner's state as its own `{noreply, State}' return value, so every later read answered `{error, unknown_request}' -- a refusal that does not look like `replaying', so nothing upstream noticed. And `handle_info/2`'s driver-exit clause could never run, because the owner did not trap exits: it does now, so a driver that dies mid-page is a table dropped and filled again rather than the owner's own death. Two tests, both without a store: a report from another process leaves reads refused, and a failed replay leaves the owner answering `replaying'. Refs macula-ci-images#19