A cluster join never wipes a store that holds events #2
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Purpose (fix): in cluster mode, a cluster join never wipes a store that holds events. This includes two standalone boxes meeting on a LAN, whatever their node names are.
Refs martha-ai/mcl-martha#1 (step 1b of A3 in the LAN addendum). No service switches to
mode = clusterbefore this lands.The owner's words
The harm
In cluster mode, a nodeup runs
reckon_db_store_coordinator's cold-start election.src/reckon_db_store_coordinator.erl:303-338).khepri_cluster:join, which resets the joiner's local tree (:354-384).:238-263) protects only a node whose configured member set is already larger than one.So a standalone node that holds events wipes its own store as soon as it meets a node whose name sorts lower. Which node loses its data is decided by the order of the names, not by which node holds the data.
The same reset happens on the other two join paths:
handle_cluster_nodes/3);join_cluster/2.Threat model
khepri_cluster:join, the joining node checks its own store and refuses to join while it holds at least one event. The check runs on the node that would lose the data, so a wrong or unreachable answer from the peer can never cause a wipe; the worst it can cause is that no cluster forms.reset_and_rejoin(reckon_db_store_healer.erl). It acts only on a replica that is already in a multi-member configuration and has been orphaned; it deliberately clears that replica first, and the majority still holds the data. After its reset the store is empty, so the new guard lets its rejoin through unchanged.Done when
khepri_cluster:join. This holds on all three paths: the cold-start election, a found multi-member cluster, andjoin_cluster/2. The node logs the refusal, naming the store and the target node.rebar3 eunitandscripts/check_ct.sh. No test reaches an outside host.Threat model, appended while building (the body above is unchanged):
khepri:count(Store, [streams, *])). Every appended event lives under one, and a fresh store has none, sinceinit_store_pathscreates only the root. So Done-when 1 holds: a store with at least one event is always counted as holding data.reckon_db_streams:has_events/1): that goes throughread_all_global's index, which is a full scan-and-sort whenever its 30 s cache is cold. The election reruns every 3-8 s on a coordinator that is still standalone. In the "both hold events" case that is forever, so the cost would never stop. Counting the root's children costs about as much as the number of stream types.khepri:count), so it needs nothing new on the peer's side.Landed: main =
9d8ce2a(fast-forward fromaf75fd49, PR 3, by Terra). Done-when, against what landed:khepri_cluster:joinon any of the three paths (cold-start election, found multi-member cluster,join_cluster/2). The refusal is logged with the store and the target. Guardjoin_unless_holdingin reckon_db_store_coordinator. Jupiter PASS r=1.join_action).4bd17ca, OTP 28: xref, lint, eunit 712, ct 300, proper, dialyzer, all green. On the forge (9d8ce2a), push run 21 and PR run 22 passed everything except one case,reckon_db_concurrent_append_SUITEtwenty_writers_on_one_stream_keep_every_event. That case also fails on main without #2, and Mars ruled those two jobs accepted reds under #7. Both runs passed the new join suites. No test reaches an outside host.