refactor(ha-repl-hardening): standardize n_peers = total cluster size including self
- ha_state_t.n_peers now matches raft_config_t.n_peers convention: total cluster size (including self), consistently across both layers - ha_start_election_async: ha->n_peers = n_peers (candidates_count) - Convergence/counting loops: i < n_peers - 1 (skip self for standby arrays) - Single-node: n_peers=1, threshold=0 (same behavior, clear semantics) - ha_elect_ctx_t.n_peers unchanged (separate field for vote array sizing) - Tests: 3-node n_peers=2->3, single-node 0->1, loop bounds updated E2E test 6.7: 3-node cluster lifecycle verified - Initial: ctrl-1 PRIMARY via majority convergence, no degraded mode - Kill primary: RDHUP detected on both standbys, ctrl-2 elected at term=4 - No data loss: config tag preserved across failover - Full ASAN build green
This commit is contained in:
parent
361397ac02
commit
f236d320a2
4 changed files with 71 additions and 31 deletions
|
|
@ -383,8 +383,9 @@ static void test_process_standby_state_multiple_peers(void)
|
|||
* count the number of converged standbys and promote to CTRL_PRIMARY when the
|
||||
* majority threshold is met and the current role is CTRL_PRIMARY_COMMITTING.
|
||||
*
|
||||
* Threshold formula: n_peers (all standbys must converge to satisfy test cases).
|
||||
* Single-node (n_peers=0): threshold=0 → satisfied immediately.
|
||||
* Threshold formula: n_peers - 1 (all standbys must converge).
|
||||
* Single-node (n_peers=1): threshold=0 → satisfied immediately (matches raft convention).
|
||||
* n_peers = total cluster size including self.
|
||||
*
|
||||
* Requirements: 2.3, 2.4, 6.1, 6.3, 6.5 (ha-repl-hardening)
|
||||
*/
|
||||
|
|
@ -411,7 +412,7 @@ static void test_majority_convergence_3node_one_standby_stays_committing(void)
|
|||
.committing_timeout_ms = HA_DEFAULT_COMMITTING_TIMEOUT_MS,
|
||||
};
|
||||
ha_init(&c.ha, &cfg, 0);
|
||||
c.ha.n_peers = 2; /* 3-node cluster: primary + 2 standbys */
|
||||
c.ha.n_peers = 3; /* 3-node cluster: primary + 2 standbys */
|
||||
atomic_store_explicit(&c.ha.role, (int32_t)CTRL_PRIMARY_COMMITTING,
|
||||
memory_order_release);
|
||||
|
||||
|
|
@ -451,7 +452,7 @@ static void test_majority_convergence_3node_all_standbys_promotes(void)
|
|||
.committing_timeout_ms = HA_DEFAULT_COMMITTING_TIMEOUT_MS,
|
||||
};
|
||||
ha_init(&c.ha, &cfg, 0);
|
||||
c.ha.n_peers = 2; /* 3-node cluster */
|
||||
c.ha.n_peers = 3; /* 3-node cluster */
|
||||
atomic_store_explicit(&c.ha.role, (int32_t)CTRL_PRIMARY_COMMITTING,
|
||||
memory_order_release);
|
||||
|
||||
|
|
@ -491,7 +492,7 @@ static void test_majority_convergence_single_node_immediate(void)
|
|||
.committing_timeout_ms = HA_DEFAULT_COMMITTING_TIMEOUT_MS,
|
||||
};
|
||||
ha_init(&c.ha, &cfg, 0);
|
||||
c.ha.n_peers = 0; /* single-node: no standbys */
|
||||
c.ha.n_peers = 1; /* single-node: just self */
|
||||
atomic_store_explicit(&c.ha.role, (int32_t)CTRL_PRIMARY_COMMITTING,
|
||||
memory_order_release);
|
||||
|
||||
|
|
@ -500,7 +501,7 @@ static void test_majority_convergence_single_node_immediate(void)
|
|||
|
||||
int role = (int)atomic_load_explicit(&c.ha.role, memory_order_acquire);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE((int)CTRL_PRIMARY, role,
|
||||
"single-node: n_peers=0 → threshold=0 satisfied → must promote to CTRL_PRIMARY (Req 6.5)");
|
||||
"single-node: n_peers=1 → threshold=0 satisfied → must promote to CTRL_PRIMARY (Req 6.5)");
|
||||
|
||||
ha_fini(&c.ha);
|
||||
printf("test_majority_convergence_single_node_immediate: PASS\n");
|
||||
|
|
@ -839,7 +840,7 @@ static void test_committing_timeout_promotes_degraded_with_partial_convergence(v
|
|||
.committing_timeout_ms = HA_DEFAULT_COMMITTING_TIMEOUT_MS,
|
||||
};
|
||||
ha_init(&c.ha, &cfg, 0);
|
||||
c.ha.n_peers = 2; /* 3-node cluster; 2 standbys */
|
||||
c.ha.n_peers = 3; /* 3-node cluster; 2 standbys */
|
||||
atomic_store_explicit(&c.ha.role, (int32_t)CTRL_PRIMARY_COMMITTING,
|
||||
memory_order_release);
|
||||
|
||||
|
|
@ -853,7 +854,7 @@ static void test_committing_timeout_promotes_degraded_with_partial_convergence(v
|
|||
*/
|
||||
int n_converged = 0;
|
||||
int n_pending = 0;
|
||||
for (int i = 0; i < c.ha.n_peers; i++) {
|
||||
for (int i = 0; i < c.ha.n_peers - 1; i++) {
|
||||
if (c.ha.standby_converged[i])
|
||||
n_converged++;
|
||||
else
|
||||
|
|
@ -898,7 +899,7 @@ static void test_committing_timeout_promotes_degraded_zero_converged(void)
|
|||
.committing_timeout_ms = HA_DEFAULT_COMMITTING_TIMEOUT_MS,
|
||||
};
|
||||
ha_init(&c.ha, &cfg, 0);
|
||||
c.ha.n_peers = 2; /* 3-node cluster; all standbys unreachable */
|
||||
c.ha.n_peers = 3; /* 3-node cluster; all standbys unreachable */
|
||||
atomic_store_explicit(&c.ha.role, (int32_t)CTRL_PRIMARY_COMMITTING,
|
||||
memory_order_release);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue