feat(ha-repl-hardening): committing timeout 60s degraded-mode safety net (task 5.3)

- Change HA_DEFAULT_COMMITTING_TIMEOUT_MS from 10000 to 60000
- committing_timeout_fn: count converged/pending standbys from
  standby_converged[], log WARN with counts, then promote (degraded mode)
- Replace hardcoded 10000 in test_ha_evaluate_committing.c with macro
- Three new tests: default=60000, degrade-promote with 1/2 and 0/2 converged
This commit is contained in:
Rongsong Shen 2026-06-05 05:03:40 +00:00
parent 534bfd68fe
commit 0762577bf7
5 changed files with 160 additions and 9 deletions

View file

@ -2853,10 +2853,16 @@ void raft_cb_become_follower_for_test(ha_state_t *ha, uint64_t term)
}
#endif /* XCE_TESTING */
/* ── Task 4.1: committing_timeout_fn — delaymgr callback ───────────────────
/* ── Task 4.1 / Task 5.3: committing_timeout_fn — delaymgr callback ─────────
*
* Fires ha_promote_to_primary (degraded mode) if majority convergence has not
* been reached within committing_timeout_ms. The majority-convergence path
* (ha_check_majority_convergence) is the PRIMARY promotion mechanism; this
* timeout is the safety-net fallback (Req 6.4, 8.4).
*
* WARN log includes the number of standbys that have converged and the number
* still pending, satisfying Req 7.5.
*
* Fires ha_promote_to_primary (degraded mode) if the majority ack threshold
* has not been reached within committing_timeout_ms. Req 8.4.
* Owns the committing_timeout_ctx_t — frees it on exit.
*/
static int committing_timeout_fn(void *arg)
@ -2869,8 +2875,20 @@ static int committing_timeout_fn(void *arg)
ctrl_role_t role = (ctrl_role_t)atomic_load_explicit(&t->ha->role,
memory_order_acquire);
if (role == CTRL_PRIMARY_COMMITTING) {
WARN("HA: committing timeout — majority ack not received within timeout; "
"promoting to PRIMARY (degraded mode, Req 8.4)");
/* Count converged vs pending standbys for the WARN log (Req 7.5). */
int n_converged = 0;
int n_pending = 0;
int n_peers = t->ha->n_peers;
for (int i = 0; i < n_peers; i++) {
if (t->ha->standby_converged[i])
n_converged++;
else
n_pending++;
}
WARN("HA: committing timeout — majority convergence not reached within timeout; "
"%d/%d standbys converged, %d still pending; "
"promoting to PRIMARY in degraded mode (Req 6.4, 7.5)",
n_converged, n_peers, n_pending);
if (t->c)
ha_promote_to_primary(t->c);
}