feat(election-iomgr-refactor): config/WAL replication push to standbys in COMMITTING path — task 4.2

This commit is contained in:
Rongsong Shen 2026-05-30 11:56:31 +00:00
parent f4a6726f1b
commit 757558bb33
6 changed files with 433 additions and 0 deletions

View file

@ -956,6 +956,15 @@ static int committing_timeout_fn(void *arg);
* unit-test binary). */
#ifndef XCE_TESTING
extern int cluster_init_phase2(cluster_t *c);
/* ha_send_ctrlhello_to_all_standbys: defined in cluster.c.
* Iterates ha->standby_endpoints, sends CtrlHelloRequest to each, triggering
* catch-up replication in handle_ctrlhello (Req 7.2). */
extern void ha_send_ctrlhello_to_all_standbys(cluster_t *c);
/* push_config_to_standbys: defined in config_repl.c (Req 7.1).
* Best-effort fan-out of config blob to all connected standbys.
* Called with (c, NULL, 0, NULL, 0) to push from the primary's saved config. */
extern int push_config_to_standbys(cluster_t *c, const uint8_t *bytes, size_t blen,
const uint8_t sha256[32], uint64_t new_tag);
#endif
#ifdef XCE_TESTING
@ -965,6 +974,20 @@ extern int cluster_init_phase2(cluster_t *c);
* cluster_init_phase2() so tests can count phase2 calls without a live cluster_t.
*/
int (*ha_phase2_hook)(void *c) = NULL;
/*
* ha_send_ctrlhello_hook: test-only seam for ha_send_ctrlhello_to_all_standbys.
* When non-NULL, the COMMITTING path calls this INSTEAD OF the real function
* (cluster.c is not linked in unit-test binary). Req 7.2.
*/
int (*ha_send_ctrlhello_hook)(void *c) = NULL;
/*
* ha_push_config_hook: test-only seam for push_config_to_standbys.
* When non-NULL, the COMMITTING path calls this INSTEAD OF the real function
* (config_repl.c's push_config_to_standbys needs a real cluster). Req 7.1.
*/
int (*ha_push_config_hook)(void *c) = NULL;
#endif /* XCE_TESTING */
/* ── Election Evaluation (Req 2.1, 2.7, 2.8) ───────────────────────────────
@ -1101,6 +1124,24 @@ apply_role:
/* Reset ack counter for this committing round (Req 5.2) */
atomic_store(&ha->repl_ack_count, 0);
/* Push config to standbys with lower config_tag (Req 7.1) */
#ifdef XCE_TESTING
if (ha_push_config_hook != NULL)
ha_push_config_hook(c);
#else
if (c != NULL)
push_config_to_standbys(c, NULL, 0, NULL, 0);
#endif
/* Send CtrlHelloRequest to all standbys to trigger WAL catch-up (Req 7.2) */
#ifdef XCE_TESTING
if (ha_send_ctrlhello_hook != NULL)
ha_send_ctrlhello_hook(c);
#else
if (c != NULL)
ha_send_ctrlhello_to_all_standbys(c);
#endif
/* Arm committing timeout watchdog (degraded-mode fallback, Req 8.4) */
if (c) {
committing_timeout_ctx_t *ct = calloc(1, sizeof(*ct));