A3 package 2: the store's mode from config, and no append before it joins (mcl-mail#35) #36

Manually merged
terra merged 4 commits from pluto/2-store-mode into main 2026-12-02 12:57:29 +00:00
Member

A3 package 2 (martha-ai/mcl-martha#1): mail's store can run in cluster mode, and a cluster-mode node never appends before its store has joined.

Refs macula-services/mcl-mail#35, martha-ai/mcl-martha#1, reckon-db-org/reckon-db#2, #4, #14, macula-services/mcl-om#8

What changes

  1. The mode comes from config. mcl_mail_store:mode/0 reads {mcl_mail, store_mode}: single unless a release says cluster, and anything else is an error({store_mode_not_a_mode, Bad}) at boot. mcl_mail_service:event_store/0 takes mode from it. The shipped config names single, which is every box today; a clustered mcl-martha bundle is the one place that overrides it.

  2. One append seam. The nine CMD desks called evoq_command_router:dispatch/2 with identical options; they now call mailbox_dispatch:dispatch/1, which in cluster mode answers {error, store_not_joined} while reckon_db_cluster:local_healthy/1 is false. In single mode it is the same call as before, options included (asserted once).

  3. The delete-after-read path is checked like any other append. A read appends: a letter is carried twice and each carry is an event. mark_fetched_letter_read goes through the seam, and its best-effort rule is kept: a fetch served from an unjoined cluster store still answers, the carry is not recorded, and the refusal is logged.

  4. The operator rule is documented. A store that holds events refuses every join, so the node that holds the data starts first while the cluster forms; the README names the recovery step for an empty cluster that formed without it, and the rule that a one-member cluster store never reads as joined.

  5. The pin. reckon_db is ~> 5.12.0 for the build. The land waits for 5.12.1 (reckon-db#14, is_active unanswered during a leadership transfer): the floor rises to ~> 5.12.1 before this lands and no service enables cluster mode before it.

  6. Nothing here runs twice per partition. Mail publishes and subscribes to no mesh topic, so no side effect of this service is wrapped in mcl_om_singleton and a netsplit changes nothing in what mail does.

What to check

  • mailbox_dispatch is the only module that calls evoq_command_router:dispatch( in either app's source, held by a test that scans both (with a non-empty guard so it cannot pass on an empty list).
  • The refusal is counted, not read: with the router mocked, {error, store_not_joined} comes back and the mock's call count is zero.
  • The mode's default is held against the shipped config so a release cannot change one side alone.
  • local_healthy is reckon-db's own predicate (its guide, "Do not append before the store has joined"); no private copy of the join rule is made here.

Verified locally

OTP 28.4.3 / rebar 3.28.0: compile clean, MCL_LINT=1 rebar3 lint clean, rebar3 eunit 171 tests, no failures, rebar3 dialyzer clean (52 files).

A3 package 2 (martha-ai/mcl-martha#1): mail's store can run in cluster mode, and a cluster-mode node never appends before its store has joined. Refs macula-services/mcl-mail#35, martha-ai/mcl-martha#1, reckon-db-org/reckon-db#2, #4, #14, macula-services/mcl-om#8 ## What changes 1. **The mode comes from config.** `mcl_mail_store:mode/0` reads `{mcl_mail, store_mode}`: `single` unless a release says `cluster`, and anything else is an `error({store_mode_not_a_mode, Bad})` at boot. `mcl_mail_service:event_store/0` takes `mode` from it. The shipped config names `single`, which is every box today; a clustered mcl-martha bundle is the one place that overrides it. 2. **One append seam.** The nine CMD desks called `evoq_command_router:dispatch/2` with identical options; they now call `mailbox_dispatch:dispatch/1`, which in cluster mode answers `{error, store_not_joined}` while `reckon_db_cluster:local_healthy/1` is false. In single mode it is the same call as before, options included (asserted once). 3. **The delete-after-read path is checked like any other append.** A read appends: a letter is carried twice and each carry is an event. `mark_fetched_letter_read` goes through the seam, and its best-effort rule is kept: a fetch served from an unjoined cluster store still answers, the carry is not recorded, and the refusal is logged. 4. **The operator rule is documented.** A store that holds events refuses every join, so the node that holds the data starts first while the cluster forms; the README names the recovery step for an empty cluster that formed without it, and the rule that a one-member cluster store never reads as joined. 5. **The pin.** `reckon_db` is `~> 5.12.0` for the build. **The land waits for 5.12.1** (reckon-db#14, `is_active` unanswered during a leadership transfer): the floor rises to `~> 5.12.1` before this lands and no service enables cluster mode before it. 6. **Nothing here runs twice per partition.** Mail publishes and subscribes to no mesh topic, so no side effect of this service is wrapped in `mcl_om_singleton` and a netsplit changes nothing in what mail does. ## What to check - `mailbox_dispatch` is the only module that calls `evoq_command_router:dispatch(` in either app's source, held by a test that scans both (with a non-empty guard so it cannot pass on an empty list). - The refusal is counted, not read: with the router mocked, `{error, store_not_joined}` comes back and the mock's call count is zero. - The mode's default is held against the shipped config so a release cannot change one side alone. - `local_healthy` is reckon-db's own predicate (its guide, "Do not append before the store has joined"); no private copy of the join rule is made here. ## Verified locally OTP 28.4.3 / rebar 3.28.0: compile clean, `MCL_LINT=1 rebar3 lint` clean, `rebar3 eunit` 171 tests, no failures, `rebar3 dialyzer` clean (52 files).
A3 package 2: the store's mode from config, and no append before it joins (mcl-martha#1)
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 2s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m39s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 1s
f80f45423c
{mcl_mail, store_mode} is single unless a release says cluster. mode/0 refuses
anything else at boot, naming the value it got: a typo that ran a clustered box
as a single store would give every node its own history, and one that ran a lone
box as a cluster store would stop every append. The shipped config names single,
so nothing changes for a box that sets nothing.

The nine CMD desks and the delete-after-read mark now dispatch through one seam,
mailbox_dispatch, which in cluster mode answers {error, store_not_joined} while
reckon_db_cluster:local_healthy/1 is false. The join counts the store and then
joins, and an event appended in between is wiped by the join (reckon-db#4). A
read is an append too (a letter is carried twice, each carry an event), so its
mark is gated as well and stays best effort: the fetch answers, the carry is not
recorded, and the refusal is logged.

README carries the operator rule the store's own guard implies: start the node
that holds the data first, while the cluster forms, or the empty boxes form a
cluster of their own and the holder never joins. It also says a one-member
cluster store never reads as joined, so a box that runs alone belongs in single.

reckon_db moves to ~> 5.12.0 for the build. The floor rises to 5.12.1 before any
release enables cluster mode: 5.12.0's is_active can go unanswered during a
leadership transfer (reckon-db#14).

Verified on OTP 28.4.3: compile clean, MCL_LINT=1 rebar3 lint clean, rebar3
eunit 171 tests, rebar3 dialyzer clean.
Review r=1: each desk's own dispatch is counted on the mock (mcl-mail#35)
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 2s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m44s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 3s
bf7345e48f
Mercurius's required item 1. The scan in the previous commit proves no other
module calls the router; it cannot see a desk that reaches it by another route.
This runs every one of the nine desks' own dispatch/1 with a real command and
counts the mocked router: on an unjoined cluster store each answers
{error, store_not_joined} with zero calls, and on a single store each calls it
exactly once.
The floor is reckon_db ~> 5.12.1, and the release carries it (mcl-mail#35)
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m53s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 1s
04b91ae4db
5.12.0's is_active can go unanswered during a leadership transfer
(reckon-db#14), which is exactly when a joining store is asking whether it may
append. 5.12.1 answers, so the floor moves to it before any release can enable
cluster mode.

Verified on OTP 28.4.3 against reckon_db 5.12.1 from hex: compile clean, eunit
180 tests, and `rebar3 as prod release` assembles with reckon_db-5.12.1 in it.
evoq ~> 1.32: one node in charge of each aggregate (mcl-mail#35)
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 4m5s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 4s
build-and-push / guard (push) Has been skipped
build-and-push / guard-1 (push) Has been skipped
c4 model / c4-model-1 (push) Successful in 5s
c4 model / c4-model (push) Successful in 0s
build-and-push / check (push) Successful in 4m41s
build-and-push / The tested lock arrives whole (push) Has been skipped
build-and-push / test (push) Successful in 0s
build-and-push / build-and-push (push) Successful in 1s
build-and-push / File the tested resolve for the signer (push) Successful in 4s
build-and-push / attest (push) Successful in 0s
f181010381
A shared store has several members; a command for one mailbox must reach the
member that owns that aggregate, not whichever member the call landed on. 1.32
carries that routing (Supervisor's ruling for every clustered service).

Verified on OTP 28.4.3: compile clean, eunit 180 tests, and a release rebuilt
from an empty _build/prod/rel holds evoq 1.32.0, reckon_db 5.12.1 and
reckon_evoq 2.10.0, and nothing else by those names. The first build left a
stale evoq-1.31.1 directory beside 1.32.0; a clean rebuild is what the check
reads.
terra manually merged commit f181010381 into main 2026-12-02 12:57:29 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-services/mcl-mail!36
No description provided.