feat: wire ha_state_t into cluster_t + HA startup/shutdown lifecycle (P1-5)
This commit is contained in:
parent
652b015458
commit
c627f69d50
6 changed files with 241 additions and 13 deletions
|
|
@ -632,6 +632,32 @@ int cluster_init(cluster_t* c)
|
|||
}
|
||||
}
|
||||
|
||||
/* HA initialisation — P1-5 */
|
||||
{
|
||||
ha_config_t ha_cfg = {
|
||||
.heartbeat_interval_ms = 3000,
|
||||
.heartbeat_timeout_ms = 10000,
|
||||
.election_timeout_ms = 2000,
|
||||
.probe_connect_timeout_ms = 500,
|
||||
.max_promotion_retries = 5,
|
||||
};
|
||||
/* my_priority: single-node P1 always uses 0 (highest priority) */
|
||||
rc = ha_init(&c->ha, &ha_cfg, 0);
|
||||
if (rc != 0) {
|
||||
ERROR("ha_init failed: %d", rc);
|
||||
persist_fini(&c->persist);
|
||||
return rc;
|
||||
}
|
||||
ha_install_sigusr1(&c->ha);
|
||||
|
||||
/* Determine initial role: priority-0 node starts as primary */
|
||||
if (am_i_primary(c))
|
||||
ha_promote_to_primary(c);
|
||||
else
|
||||
atomic_store_explicit(&c->ha.role, (int32_t)CTRL_STANDBY,
|
||||
memory_order_release);
|
||||
}
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_CLUSTER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_CLUSTER_INIT, c);
|
||||
|
||||
|
|
@ -787,6 +813,13 @@ int cluster_start(cluster_t* c)
|
|||
return rc;
|
||||
}
|
||||
|
||||
/* Start HA heartbeat watchdog thread — P1-5 */
|
||||
rc = ha_start_watchdog(&c->ha);
|
||||
if (rc != 0) {
|
||||
ERROR("ha_start_watchdog failed: %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
delay_task(&(c->delaymgr), c->myconf->cluster_config->heartbeat_interval,
|
||||
-1, (delay_task_entry_fn_t)check_workers_timeout, (void*)c);
|
||||
|
||||
|
|
@ -819,6 +852,9 @@ int cluster_run(cluster_t* c)
|
|||
|
||||
void cluster_fini(cluster_t* c)
|
||||
{
|
||||
/* Stop HA watchdog thread before tearing down other subsystems — P1-5 */
|
||||
ha_fini(&c->ha);
|
||||
|
||||
/* Stop persistence before tearing down the rest */
|
||||
persist_stop(&c->persist);
|
||||
persist_fini(&c->persist);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue