forked from lei.chen/myxce
feat(ha-single-leader-role): remove CTRL_PRIMARY_COMMITTING enum + remaining decls — compiler-enforced (task 5.2)
This commit is contained in:
parent
7f974e766b
commit
93dfc02717
10 changed files with 44 additions and 55 deletions
|
|
@ -437,13 +437,12 @@ void ha_compute_safe_committed_lsn(ha_elect_ctx_t *ctx,
|
|||
}
|
||||
|
||||
/*
|
||||
* raft_cb_become_leader: node won the election — enter COMMITTING state.
|
||||
* raft_cb_become_leader: node won the election — enter CTRL_PRIMARY directly.
|
||||
*
|
||||
* Equivalent of ha_elect_evaluate_and_signal CTRL_PRIMARY path:
|
||||
* - enter CTRL_PRIMARY_COMMITTING
|
||||
* - enter CTRL_PRIMARY (no transitional state)
|
||||
* - call cluster_init_phase2 on first boot
|
||||
* - reset repl_ack_count, push config, send ctrlhello
|
||||
* - arm committing timeout watchdog
|
||||
* - push config, send ctrlhello
|
||||
*
|
||||
* ha->raft_c must be non-NULL (production path only; test mode uses noop stubs).
|
||||
*/
|
||||
|
|
@ -469,7 +468,7 @@ static void raft_cb_become_leader(void *ctx, uint64_t term)
|
|||
uint64_t safe_lsn = 0;
|
||||
uint64_t safe_tag = 0;
|
||||
ha_compute_safe_committed_lsn(ectx, &safe_lsn, &safe_tag);
|
||||
/* Store results for use in WAL truncation and COMMITTING phase.
|
||||
/* Store results for use in WAL truncation and post-election commit.
|
||||
* safe_lsn is the highest LSN on a majority; entries above it
|
||||
* may not have been committed on all nodes and must be truncated. */
|
||||
if (c) {
|
||||
|
|
@ -486,7 +485,7 @@ static void raft_cb_become_leader(void *ctx, uint64_t term)
|
|||
* Req 2.3 (ha-repl-hardening). */
|
||||
atomic_store_explicit(&ha->last_known_committed_lsn, safe_lsn,
|
||||
memory_order_release);
|
||||
/* Update committed config tag baseline for the COMMITTING decision loop */
|
||||
/* Update committed config tag baseline for the post-election decision loop */
|
||||
atomic_store_explicit(&ha->committed_config_tag, safe_tag,
|
||||
memory_order_release);
|
||||
}
|
||||
|
|
@ -520,7 +519,7 @@ static void raft_cb_become_leader(void *ctx, uint64_t term)
|
|||
", first_boot=%d)", term, is_first_boot);
|
||||
|
||||
/* Req 2.1 (ha-repl-hardening): re-initialize per-standby convergence
|
||||
* tracking for THIS committing round. Stale converged flags from a
|
||||
* tracking for THIS primary term. Stale converged flags from a
|
||||
* previous term (demote → re-elect cycle) must not satisfy the
|
||||
* majority-convergence gate before standbys re-report their state. */
|
||||
memset(ha->standby_reported_tag, 0, sizeof(ha->standby_reported_tag));
|
||||
|
|
@ -823,7 +822,7 @@ int ha_init(ha_state_t *ha, const ha_config_t *cfg, int my_priority)
|
|||
|
||||
/* ha-repl-hardening Task 1.4: per-standby convergence tracking arrays.
|
||||
* memset(ha, 0, sizeof(*ha)) above already zeroes these arrays; the explicit
|
||||
* note documents the invariant: on entry to CTRL_PRIMARY_COMMITTING every
|
||||
* note documents the invariant: on promotion to CTRL_PRIMARY every
|
||||
* standby starts as not-converged (tag=0, lsn=0, converged=false). */
|
||||
|
||||
/* heartbeat_seen starts at 0: no heartbeat seen yet.
|
||||
|
|
@ -1237,8 +1236,8 @@ ha_repl_action_t ha_evaluate_repl_action(uint64_t standby_tag,
|
|||
/*
|
||||
* ha_process_standby_state — update per-standby convergence tracking.
|
||||
*
|
||||
* Called on each heartbeat reply from a standby (CTRL_PRIMARY_COMMITTING or
|
||||
* CTRL_PRIMARY). Stores (reported_tag, reported_lsn) into the per-standby
|
||||
* Called on each heartbeat reply from a standby (CTRL_PRIMARY).
|
||||
* Stores (reported_tag, reported_lsn) into the per-standby
|
||||
* arrays, evaluates convergence, and logs INFO on the first
|
||||
* not-converged → converged transition (Req 7.2). Regression resets the flag
|
||||
* (Req 2.5).
|
||||
|
|
@ -2071,14 +2070,14 @@ int (*ha_phase2_hook)(void *c) = NULL;
|
|||
|
||||
/*
|
||||
* ha_send_ctrlhello_hook: test-only seam for ha_send_ctrlhello_to_all_standbys.
|
||||
* When non-NULL, the COMMITTING path calls this INSTEAD OF the real function
|
||||
* When non-NULL, the post-election path calls this INSTEAD OF the real function
|
||||
* (cluster.c is not linked in unit-test binary). Req 7.2.
|
||||
*/
|
||||
int (*ha_send_ctrlhello_hook)(void *c) = NULL;
|
||||
|
||||
/*
|
||||
* ha_push_config_hook: test-only seam for push_config_transport_only.
|
||||
* When non-NULL, the COMMITTING path calls this INSTEAD OF the real function
|
||||
* When non-NULL, the post-election path calls this INSTEAD OF the real function
|
||||
* (config_repl.c's push_config_transport_only needs a real cluster). Req 7.1.
|
||||
*/
|
||||
int (*ha_push_config_hook)(void *c) = NULL;
|
||||
|
|
@ -2976,7 +2975,7 @@ int election_timeout_fn_for_test(ha_state_t *ha, ha_elect_ctx_t *ctx,
|
|||
/*
|
||||
* repl_catchup_done_pkt_for_test: build a minimal io_packet_t encoding
|
||||
* Request{opcode=replCatchUpDone, body_which=nodata}.
|
||||
* Used by peer_ctrl_msg_handler tests to verify the COMMITTING dispatch path.
|
||||
* Used by peer_ctrl_msg_handler tests to verify the repl-ack dispatch path.
|
||||
*/
|
||||
io_packet_t *repl_catchup_done_pkt_for_test(void)
|
||||
{
|
||||
|
|
@ -3273,7 +3272,7 @@ void ha_start_election_async(ha_state_t *ha, cluster_t *c,
|
|||
INFO("ha_start_election_async: no local config (tag=0, n_peers=%d) — "
|
||||
"participating as voter only, not starting own election", n_peers);
|
||||
/* Transition to CTRL_STANDBY so myapp_run schedules fetch_config_from_primary.
|
||||
* The primary will push config via ctrlhello once it enters COMMITTING. */
|
||||
* The primary will push config via ctrlhello once it becomes CTRL_PRIMARY. */
|
||||
atomic_store_explicit(&ha->role, (int32_t)CTRL_STANDBY, memory_order_release);
|
||||
/* Free ctx — no vote sends will happen from this node this round. */
|
||||
atomic_store_explicit(&ha->elect_ctx, NULL, memory_order_release);
|
||||
|
|
@ -3285,8 +3284,8 @@ void ha_start_election_async(ha_state_t *ha, cluster_t *c,
|
|||
raft_start_election(&ha->raft);
|
||||
|
||||
/* For single-node, raft_start_election fires on_become_leader synchronously.
|
||||
* on_become_leader (raft_cb_become_leader) handles role → COMMITTING,
|
||||
* phase2, and committing timeout. Free the ctx here since no raft callbacks
|
||||
* on_become_leader (raft_cb_become_leader) handles role -> CTRL_PRIMARY and
|
||||
* phase2. Free the ctx here since no raft callbacks
|
||||
* will reference it after raft_start_election returns for single-node. */
|
||||
if (n_peers == 1) {
|
||||
atomic_store_explicit(&ha->elect_ctx, NULL, memory_order_release);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue