Loading…
Reference in a new issue
No description provided.
Delete branch "neptunus/14-leader-activation-worker"
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 #14, Refs #15
reckon_db 5.12.1: two fixes in the cluster start path, one release (Supervisor ruling: #15 folded into #14). This PR carries the version bump (app.src, README, CHANGELOG), so one land plus a tag ships it.
#14: the leader worker answers
is_active/1while it activatesActivation (save the default subscription, list the subscriptions, start an emitter pool for each, resume the links) ran inside
reckon_db_leader's own loop.is_active/1is a 5 s call to that loop, so on a slow box it timed out for as long as activation ran. The node monitor makes that call every tick, andleadership_transfer_new_leader_serves_existing_subscriptionwaits on it (tag run 6803, job 27753, attempt 1). Hygiea's analysis is in c8259.The activation now runs in a linked, monitored process of its own, as the DCB re-index already does. Its answer
{leadership_activated, Pid, Count}setsactive = trueonly whenPidis the running activation.r2 (Mercurius r1 FAIL, livelock): an activate asked for while one runs never replaces it. The node monitor ticks every 5 s and asks again while
is_active/1isfalse, so a replaced slow activation would be killed every tick and never finish. It is kept as ONE rerun (save_defaultswins oversubscriptions_only) that starts when the running one answers or crashes.Races, each with its case in
test/unit/reckon_db_leader_tests.erl. Every case holds the activation at a gate in the mocked subscription list and opens it by message, so nothing waits on a sleep:falsein under 1 s while held, andtrueonce done.is_active_answers_while_the_activation_runs. On the 5.12.0 module this case dies on{timeout,{gen_server,call,[…,is_active]}}.do_activate, then oneactivate). The running one stays alive, runs to its end (links resumed) and makes the leader active. Then exactly ONE rerun runs, it saves defaults (exists/2called twice), and no third run starts.activates_asked_while_one_runs_leave_it_running_and_rerun_once. Mutant: the r1 kill-and-replace leader (8ecae78) fails four of this case's asserts.an_answer_not_from_the_running_activation_sets_nothing.a_crashed_activation_leaves_the_leader_up_and_inactive.a_rerun_asked_before_a_crash_still_runs.#14 Done-when 3: with a mutant that keeps the gaining leader from starting the subscription's emitter pool (
start_emitter(mutant_no_such_store, …)),reckon_db_cluster_join_subscriptions_SUITE:leadership_transfer_new_leader_serves_existing_subscriptionfails (Failed 1 tests. Passed 0). On the r2 code it passes.#15: a store started after its node connected joins
A node joined only on a
nodeupor an explicitjoin_cluster/1. A store started after the nodes had connected stayed a cluster of one. The coordinator now starts its own join loop ininit/1(cluster mode only): the existingretry_join, jittered 3-8 s, with the #2 holder guard.The loop now keeps one pending retry. It uses
erlang:start_timer, and the ref is kept in state. A new schedule cancels the old timer, and a fired timer whose ref is not current does nothing. Before, every nodeup orjoin_cluster/1answeringwaiting,no_nodesorcoordinatoradded a chain of its own. With the loop now always running, that would have doubled it on the first nodeup.Test:
test/integration/reckon_db_cluster_join_on_start_SUITE.erlboots A's store, connects B to A, then boots B's store with no join call. Both see one two-member cluster within 60 s. On the 5.12.0 coordinator, after 60 s A's members are[A]and B's are[B].Trade-off:
clusteris the default mode, so a lone cluster-mode node now runs the loop (no_nodes, every 3-8 s, at info level). That is what any nodeup orjoin_cluster/1call already started.Not in this PR
Nothing deactivates the leader worker when the node loses the lead:
reckon_db_node_monitor:handle_no_leader/3only logs. This is unchanged here and outside the ruled scope, so I note it rather than fix it.Proof
Local gate on
acc1aa9(pinned rebar 3.28.0, OTP 28): xref ok, lint ok, eunit 732/732, ct 302/302 (check_ct.sh; a second run under double load had 1 red in reckon_db_cluster_join_keeps_events_SUITE, reckon-db#17, 3/3 green alone), proper ok, dialyzer ratchet ok. Each new test is red on the 5.12.0 module it guards (logs kept by the builder).