A cluster join never wipes a store that holds data (reckon-db#2) #3

Manually merged
terra merged 2 commits from neptunus/join-keeps-events into main 2026-12-02 07:18:26 +00:00
Member

Refs reckon-db-org/reckon-db#2 (the threat model and Done-when are in the issue; the data definition is in c7712). Step 1b of martha-ai/mcl-martha#1's LAN addendum.

What changes

  • join_existing_cluster/2, the one path every join takes (cold-start election, a found multi-member cluster, join_cluster/2), now checks the local store first. A store that holds data (any node under [streams]) refuses: the join answers refused, an error names the store and the target, and the join is not retried. A store that cannot be counted does not join either (failed, retried).
  • elect_coordinator/3 ranks the nodes that hold data first, and names break ties. So the holder coordinates and an empty node joins it.
  • Healer: unchanged. It resets an orphaned replica first, so that replica's store is empty when it rejoins.

Tests

  • New reckon_db_cluster_join_keeps_events_SUITE (two real peers, cluster mode):
    • higher_named_holder_keeps_its_events: B (higher name) holds 5 events and A is empty. They form one two-member cluster, and both nodes read all 5 events.
    • both_holding_refuse_and_keep_their_events: both nodes hold events. join_cluster/1 and join_cluster/2 on B answer refused and the refusals are logged. Neither node joins and each keeps its own events. No further refusal is logged after a wait longer than a retry delay.
  • Unit tests in reckon_db_store_coordinator_election_tests: holder-high, holder-low, both holding, none holding, and a holder among three nodes. Also classify_stream_count, join_action and join_decision. The existing election tests now call /3 with no holders (/2 was left with no caller).
  • reckon_db_cluster_join_subscriptions_SUITE:pre_join_subscription_survives_join no longer appends an event on the joiner before the join, because that join is now refused. Its subscription check is unchanged.

Mutants (10, all killed; script mutants.sh):

  • main_coordinator (main's file): the suite goes red.
  • drop_check: the suite goes red.
  • held_joins: the unit tests and the suite go red.
  • invert_check: the unit tests and the suite go red.
  • unknown_empty: the unit tests go red.
  • unknown_joins: the unit tests go red.
  • no_ranking: the unit tests and the suite go red.
  • no_self_holder: the suite goes red.
  • no_remote_holder: the suite goes red.
  • refused_retries: the suite goes red.
Refs reckon-db-org/reckon-db#2 (the threat model and Done-when are in the issue; the data definition is in c7712). Step 1b of martha-ai/mcl-martha#1's LAN addendum. **What changes** - `join_existing_cluster/2`, the one path every join takes (cold-start election, a found multi-member cluster, `join_cluster/2`), now checks the local store first. A store that holds data (any node under `[streams]`) refuses: the join answers `refused`, an error names the store and the target, and the join is not retried. A store that cannot be counted does not join either (`failed`, retried). - `elect_coordinator/3` ranks the nodes that hold data first, and names break ties. So the holder coordinates and an empty node joins it. - Healer: unchanged. It resets an orphaned replica first, so that replica's store is empty when it rejoins. **Tests** - New `reckon_db_cluster_join_keeps_events_SUITE` (two real peers, cluster mode): - `higher_named_holder_keeps_its_events`: B (higher name) holds 5 events and A is empty. They form one two-member cluster, and both nodes read all 5 events. - `both_holding_refuse_and_keep_their_events`: both nodes hold events. `join_cluster/1` and `join_cluster/2` on B answer `refused` and the refusals are logged. Neither node joins and each keeps its own events. No further refusal is logged after a wait longer than a retry delay. - Unit tests in `reckon_db_store_coordinator_election_tests`: holder-high, holder-low, both holding, none holding, and a holder among three nodes. Also `classify_stream_count`, `join_action` and `join_decision`. The existing election tests now call `/3` with no holders (`/2` was left with no caller). - `reckon_db_cluster_join_subscriptions_SUITE:pre_join_subscription_survives_join` no longer appends an event on the joiner before the join, because that join is now refused. Its subscription check is unchanged. **Mutants** (10, all killed; script `mutants.sh`): - `main_coordinator` (main's file): the suite goes red. - `drop_check`: the suite goes red. - `held_joins`: the unit tests and the suite go red. - `invert_check`: the unit tests and the suite go red. - `unknown_empty`: the unit tests go red. - `unknown_joins`: the unit tests go red. - `no_ranking`: the unit tests and the suite go red. - `no_self_holder`: the suite goes red. - `no_remote_holder`: the suite goes red. - `refused_retries`: the suite goes red.
khepri_cluster:join resets the joining node's tree. The cold-start
election made the lowest node name coordinator and every other
store-runner join it, so a standalone store holding events wiped itself
when it met a node whose name sorted lower; a holder that found an
existing cluster, or was told join_cluster/2, was reset the same way.

- join_existing_cluster now refuses when the local store holds data (any
  node under the streams root): it answers `refused', logs an error that
  names the store and the target, and is not retried. A store that
  cannot be counted does not join either (`failed', retried).
- The election ranks nodes that hold data first; names break ties. So an
  empty node joins the holder.
- Two-node CT suite: the higher-named node holds events and keeps them
  in the cluster; two holders both refuse and both keep their events,
  and no refusal repeats past a retry delay.
- The pre-join subscription case no longer appends on the joiner before
  the join (that join is now refused); it keeps its subscription check.
- .dialyzer_baseline: the same five findings, reworded. Adding `refused'
  to the join types changed their text (the unreturned `waiting' in three
  specs, the unreachable catch-all in post_join_result/2, the healer spec
  supertype), so the ratchet saw five fixed and five new; --update swaps
  the hashes. The count stays 151 (the header said 152).

Refs reckon-db-org/reckon-db#2, martha-ai/mcl-martha#1
Merge remote-tracking branch 'origin/main' into neptunus/join-keeps-events
Some checks failed
lint-and-test / rust (clippy, deny warnings) (pull_request) Successful in 38s
lint-and-test / compile + NIFs + xref + lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (pull_request) Failing after 10m8s
lint-and-test / rust (clippy, deny warnings) (push) Successful in 33s
lint-and-test / compile + NIFs + xref + lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (push) Failing after 9m26s
9d8ce2a18d
terra manually merged commit 9d8ce2a18d into main 2026-12-02 07:18:26 +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
reckon-db-org/reckon-db!3
No description provided.