fix(election-iomgr-refactor): Raft election, config decode, and RDHUP chain
- ha.c: self-vote in ha_start_election_async (Raft invariant) - ha.c: heartbeat_timeout_ms for hb_timeout_thread (not election_timeout_ms) - ha.c: clear voted_for before RDHUP jitter (stale vote from dead primary) - ha.c: same-term voted_for check in RDHUP jitter - config_repl.c/h: use xce_decode for upgradeConfig (capnp extraction before capn_free) - cluster.c: fix upgradeConfig handler direction (standbys apply, primaries skip) - cluster.c: remove raw_pkt_copy hack; use req directly - join.c: push config to newly-joined standbys - typemap.h/request.h/request.c: raw_sha256/raw_bytes fields for decoded upgradeConfig - test_ha_failover.c: update heartbeat timeout test to use g_fast_cfg
This commit is contained in:
parent
1ded1022fb
commit
dbb750ebd3
8 changed files with 198 additions and 102 deletions
|
|
@ -80,6 +80,17 @@ static ha_config_t g_cfg = {
|
|||
.election_priority_step_ms = 500,
|
||||
};
|
||||
|
||||
/* Config with short heartbeat_timeout_ms for watchdog-fires tests */
|
||||
static ha_config_t g_fast_cfg = {
|
||||
.heartbeat_interval_ms = 2000,
|
||||
.heartbeat_timeout_ms = 2000, /* minimum valid: == heartbeat_interval_ms */
|
||||
.election_timeout_ms = 500,
|
||||
.probe_connect_timeout_ms = 50,
|
||||
.max_promotion_retries = 3,
|
||||
.election_jitter_max_ms = 0,
|
||||
.election_priority_step_ms = 500,
|
||||
};
|
||||
|
||||
/* ── Test 1: RDHUP closes fd and sets primary_ctrl_fd = -1 ─────────────── */
|
||||
|
||||
static void test_rdhup_closes_and_nulls_fd(void)
|
||||
|
|
@ -172,18 +183,19 @@ static void test_heartbeat_received_resets_timeout(void)
|
|||
static void test_heartbeat_timeout_fires_failover(void)
|
||||
{
|
||||
ha_state_t ha;
|
||||
TEST_ASSERT_EQUAL_INT(0, ha_init(&ha, &g_cfg, 1));
|
||||
/* Use fast config: heartbeat_timeout_ms=2000ms so watchdog fires in ~2s */
|
||||
TEST_ASSERT_EQUAL_INT(0, ha_init(&ha, &g_fast_cfg, 1));
|
||||
ha_do_demote(&ha);
|
||||
|
||||
int sv[2];
|
||||
TEST_ASSERT_EQUAL_INT(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sv));
|
||||
ha.primary_ctrl_fd = sv[0];
|
||||
|
||||
/* Arm with 200ms timeout, NO heartbeat received */
|
||||
/* Arm watchdog — no heartbeat will arrive */
|
||||
ha_arm_heartbeat_timeout_vtask(&ha, NULL);
|
||||
|
||||
/* Wait 800ms — well past the 500ms election_timeout_ms */
|
||||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 800 * 1000000L };
|
||||
/* Wait 2500ms — past the 2000ms heartbeat_timeout_ms */
|
||||
struct timespec ts = { .tv_sec = 2, .tv_nsec = 500 * 1000000L };
|
||||
nanosleep(&ts, NULL);
|
||||
|
||||
/* Failover must have fired: role = CTRL_ELECTING, fd = -1 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue