fix(ha-bootstrap): priority staggering and candidate_id in election

Two Raft correctness fixes:

1. Priority staggering in ha_wait_for_heartbeat_or_timeout():
   Add my_priority × election_priority_step_ms to the timeout so
   ctrl-a (priority=0) times out first and starts election before
   ctrl-b (priority=1) and ctrl-c (priority=2). This gives the
   highest-priority node a head start and prevents simultaneous
   campaigning that causes perpetual split votes.

2. candidate_id in vote RPC:
   Pass the actual node name (myconf->name) as candidate_id instead
   of "". This fixes the voted_for deduplication gate (Req 2.6):
   a peer that already voted for ctrl-a will correctly deny a
   second vote request from ctrl-b in the same term.

   Thread context gets my_name field; am_i_primary_quorum() takes
   my_name parameter; all call sites updated (myapp.c, ha.c RDHUP,
   test_ha_election.c stubs).
This commit is contained in:
Rongsong Shen 2026-05-30 02:48:59 +00:00
parent fcfb82f7c7
commit 80950ffbba
4 changed files with 20 additions and 9 deletions

View file

@ -347,7 +347,8 @@ ctrl_role_t am_i_primary_quorum(ha_state_t *ha,
int n_peers,
xce_candidate_t **peers,
uint64_t my_config_tag,
uint64_t my_lsn);
uint64_t my_lsn,
const char *my_name);
/*
* handle_request_vote_reply: process an incoming reply to an OP_requestVote RPC.