Read model: a failed replay waits before it retries, and the count is what the projection kept (mcl-mail#28) #29

Open
ceres wants to merge 1 commit from ceres/28-replay-gate-followups into main
Member

Four follow-ups from the review of PR 26 (3d296ace), all four taken in one pass (mcl-mail#28).

1. No backoff between failed replays. replay_failed/2 started a new driver inside the same call, so a store that was down got a fresh driver as fast as each attempt could fail, each reading the log from position 0 — the opposite of what the replay's own wait is for. The pause now starts at 100 ms and doubles per failed attempt up to 5 s; the gate stays off across every attempt, and the first report that reaches the end of the log puts the count back to 0.

2. events_applied counted events read. It added length(Events) per page, most of which belong to other projections. The count is now what project/4 kept: the pre-filter is gone, so project/4's own ok/skip is the answer and nothing in front of it decides.

3. The tests that the mutants walked through. Tests first, and each one red before the change that makes it green:

  • a_replay_failed_from_another_process_does_not_empty_the_table_test — the {replay_failed, Driver, Reason} pid match;
  • a_stranger_exit_does_not_empty_the_table_test — the {'EXIT', Driver, Reason} pid match;
  • a_dead_driver_refills_the_table_before_it_answers_test — a driver killed mid-page: both tables dropped, a new driver started, reads refused until it reports, and the index dropped too (a stale index would skip the re-projected deposit);
  • a_failed_replay_waits_before_it_tries_again_test — no start in the first moments, and a start count over 2.4 s that only a growing pause keeps at or under 8;
  • mailboxes_read_model_replay_tests — the paging loop driven to its end with the store stood in for at evoq_event_store:read_all_global/3 (mcl-mail#27's test-side store, one call deep): a full page does not end the log, the next read starts at exactly the batch, a short page ends it with no further read, both pages' letters land, and the count is the kept events of both pages and not the events read.

4. The lost-live-mark race is written down where it lives, in replay_failed/2: the drop empties a table the live projection writes into, so a mark applied just before the wipe comes back only if the new scan reads its event again; where the store's read index lags behind an event that arrived during the failure, the gate can open without it. Narrow, heals at the next restart — not fixed here, and said so on the issue.

Proof

  • rebar3 eunit: All 154 tests passed (32 in the two read-model modules).
  • Nine mutants, each applied to the real tree and restored in a finally; all nine killed, each by the test named for it (a compile failure does not count): the two pid matches, the refill, the index wipe, a fixed pause, a full page ending the log, the offset not advancing, the count taken from what was read, and a skipped event counted as applied.
  • rebar3 lint (MCL_LINT=1) and rebar3 dialyzer: clean.

Local toolchain: Erlang/OTP 28.4.3, rebar3 3.28.0, the toolchain lint.yml pins.

Refs #28, #26.

Four follow-ups from the review of PR 26 (`3d296ace`), all four taken in one pass (mcl-mail#28). **1. No backoff between failed replays.** `replay_failed/2` started a new driver inside the same call, so a store that was down got a fresh driver as fast as each attempt could fail, each reading the log from position 0 — the opposite of what the replay's own wait is for. The pause now starts at 100 ms and doubles per failed attempt up to 5 s; the gate stays off across every attempt, and the first report that reaches the end of the log puts the count back to 0. **2. `events_applied` counted events read.** It added `length(Events)` per page, most of which belong to other projections. The count is now what `project/4` kept: the pre-filter is gone, so `project/4`'s own `ok`/`skip` is the answer and nothing in front of it decides. **3. The tests that the mutants walked through.** Tests first, and each one red before the change that makes it green: - `a_replay_failed_from_another_process_does_not_empty_the_table_test` — the `{replay_failed, Driver, Reason}` pid match; - `a_stranger_exit_does_not_empty_the_table_test` — the `{'EXIT', Driver, Reason}` pid match; - `a_dead_driver_refills_the_table_before_it_answers_test` — a driver killed mid-page: both tables dropped, a new driver started, reads refused until it reports, and the index dropped too (a stale index would skip the re-projected deposit); - `a_failed_replay_waits_before_it_tries_again_test` — no start in the first moments, and a start count over 2.4 s that only a growing pause keeps at or under 8; - `mailboxes_read_model_replay_tests` — the paging loop driven to its end with the store stood in for at `evoq_event_store:read_all_global/3` (mcl-mail#27's test-side store, one call deep): a full page does not end the log, the next read starts at exactly the batch, a short page ends it with no further read, both pages' letters land, and the count is the kept events of both pages and not the events read. **4. The lost-live-mark race** is written down where it lives, in `replay_failed/2`: the drop empties a table the live projection writes into, so a mark applied just before the wipe comes back only if the new scan reads its event again; where the store's read index lags behind an event that arrived during the failure, the gate can open without it. Narrow, heals at the next restart — not fixed here, and said so on the issue. ## Proof - `rebar3 eunit`: **All 154 tests passed** (32 in the two read-model modules). - Nine mutants, each applied to the real tree and restored in a `finally`; **all nine killed**, each by the test named for it (a compile failure does not count): the two pid matches, the refill, the index wipe, a fixed pause, a full page ending the log, the offset not advancing, the count taken from what was read, and a skipped event counted as applied. - `rebar3 lint` (MCL_LINT=1) and `rebar3 dialyzer`: clean. Local toolchain: Erlang/OTP 28.4.3, rebar3 3.28.0, the toolchain `lint.yml` pins. Refs #28, #26.
Read model: a failed replay waits before it retries, and the count is what the projection kept (mcl-mail#28)
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 5s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m56s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 2s
b8af6b7792
Four follow-ups from the review of PR 26, taken up together.

1. replay_failed/2 no longer starts a driver at once: the pause before the next
   attempt starts at 100 ms and doubles per failed attempt up to 5 s, so a store
   that is still opening is not hammered by attempts that each read the log from
   position 0, and a boot whose store never comes is still retried.
2. The replay counts the events the projection KEPT, not the events it read:
   project/4's own answer is the count, so an event of another projection is the
   skip it already was and the `events_applied' in both log lines is no longer a
   scan count.
3. Tests first for what the suite did not kill: a report and an exit are believed
   only from the owner's own driver, a driver killed mid-page costs both tables
   and reads stay refused until its successor reports, the retry pause grows, and
   the paging loop is driven to the end of a log against a store stood in for at
   evoq_event_store:read_all_global/3.
4. The one lossy edge is written down in replay_failed/2: a mark applied live just
   before the wipe can be missed by the new scan while the store's read index lags
   behind it, and the next restart heals it.
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 5s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m56s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 2s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin ceres/28-replay-gate-followups:ceres/28-replay-gate-followups
git switch ceres/28-replay-gate-followups
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!29
No description provided.