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:
parent
fcfb82f7c7
commit
80950ffbba
4 changed files with 20 additions and 9 deletions
|
|
@ -152,7 +152,8 @@ int myapp_run(myconf_t* myconf)
|
|||
uint64_t my_lsn = (uint64_t)atomic_load_explicit(&c.ha.applied_lsn,
|
||||
memory_order_acquire);
|
||||
ctrl_role_t elected = am_i_primary_quorum(
|
||||
&c.ha, n_peers, (n_other > 0) ? peer_ptrs : NULL, my_tag, my_lsn);
|
||||
&c.ha, n_peers, (n_other > 0) ? peer_ptrs : NULL,
|
||||
my_tag, my_lsn, myconf->name);
|
||||
|
||||
if (elected == CTRL_PRIMARY) {
|
||||
final_role = CTRL_PRIMARY;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue