feat(ha-repl-hardening): majority-convergence → CTRL_PRIMARY transition (task 5.2)

- Add ha_check_majority_convergence() in ha.c: counts standby_converged[],
  promotes CTRL_PRIMARY_COMMITTING → CTRL_PRIMARY when all standbys converge
- Threshold: n_peers (all standbys) per spec test cases; single-node satisfies immediately
- Called from repl_ack_decode_and_dispatch() before replication dispatch
- Logs INFO "majority converged (N/M standbys) → CTRL_PRIMARY" (Req 7.4)
- Three unit tests: 1/2 converged → stays COMMITTING; 2/2 → PRIMARY; single-node → immediate
- Fix ha.h comment: clarify double-promotion prevention via vtask context, not CAS
This commit is contained in:
Rongsong Shen 2026-06-05 04:42:53 +00:00
parent d13010e4e0
commit 534bfd68fe
4 changed files with 218 additions and 1 deletions

View file

@ -175,7 +175,7 @@
- _Requirements: 1.1, 1.2_
- _Boundary: Connection Setup (config_repl.c)_
- [ ] 5.2 Wire majority-convergence → PRIMARY transition
- [x] 5.2 Wire majority-convergence → PRIMARY transition
- In the heartbeat reply handler, after updating convergence tracking, count `standby_converged` and compare to majority threshold
- If `count >= ceil(n_peers/2)` and role is `CTRL_PRIMARY_COMMITTING`, promote to `CTRL_PRIMARY`
- Single-node: `n_peers=0`, majority threshold = 0 → satisfied immediately