feat(ha-config-bootstrap): complete quorum election with mutex safety (task 4.3)
- am_i_primary_quorum(): per-peer pthreads, connect_ssl_raw + OP_requestVote - pthread_mutex_t lock on ha_elect_ctx_t guards votes_granted/n_replied/max_resp - done_posted guard in ha_elect_evaluate_and_signal prevents double sem_post - Replace am_i_primary() with am_i_primary_quorum() in myapp.c - Delete ha_check_priority_stepdown and ha_check_heartbeat_nocluster - INFO logs: election outcome (Req 10.1), FSM transitions (Req 10.5) - 24 election tests + 24 startup tests, 0 failures
This commit is contained in:
parent
0f88d5d32a
commit
0c9c720b03
4 changed files with 390 additions and 98 deletions
|
|
@ -88,6 +88,8 @@ typedef struct {
|
|||
uint64_t max_resp_tag; /* Highest config_tag seen in any reply */
|
||||
uint64_t max_resp_lsn; /* Highest WAL LSN seen among max_resp_tag peers */
|
||||
int result; /* 1=primary, 0=standby, <0=error */
|
||||
int done_posted; /* Guard: non-zero once sem_post(&done) has been called */
|
||||
pthread_mutex_t lock; /* Protects votes_granted/n_replied/max_resp_tag/max_resp_lsn/result */
|
||||
sem_t done; /* Startup thread blocks; dispatch posts when done */
|
||||
ha_vote_entry_t votes[]; /* C99 flexible array: n_peers-1 entries */
|
||||
} ha_elect_ctx_t;
|
||||
|
|
@ -226,11 +228,12 @@ int ha_start_watchdog(ha_state_t *ha);
|
|||
void ha_stop_watchdog(ha_state_t *ha);
|
||||
|
||||
/*
|
||||
* ha_check_heartbeat_nocluster: check whether the primary heartbeat has
|
||||
* timed out. Sets failover_requested if timeout exceeded and primary_host
|
||||
* is non-empty. Test-only entry point — does not need cluster_t.
|
||||
* ha_check_heartbeat_nocluster: test-only entry point — logic is inlined in
|
||||
* ha_watchdog_thread() in production. Only compiled under XCE_TESTING.
|
||||
*/
|
||||
#ifdef XCE_TESTING
|
||||
void ha_check_heartbeat_nocluster(ha_state_t *ha);
|
||||
#endif
|
||||
|
||||
/* ── Redirect helpers used by join.c ──────────────────────── */
|
||||
|
||||
|
|
@ -255,14 +258,7 @@ int ha_no_primary_known(const ha_state_t *ha);
|
|||
*/
|
||||
int ha_is_primary(const ha_state_t *ha);
|
||||
|
||||
/*
|
||||
* ha_check_priority_stepdown: called from the heartbeat handler when
|
||||
* term == 0 (simultaneous boot). If sender_priority < ha->my_priority
|
||||
* (higher priority), steps down the local node from PRIMARY to STANDBY.
|
||||
* No-op if term > 0 or sender is not higher priority.
|
||||
*/
|
||||
void ha_check_priority_stepdown(ha_state_t *ha, int sender_priority,
|
||||
uint64_t sender_term);
|
||||
/* ha_check_priority_stepdown() deleted — replaced by quorum election (Req 2.1) */
|
||||
|
||||
/*
|
||||
* start_heartbeat_listener: start a minimal pre-Phase-2 SSL listener
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue