feat(ha-heartbeat-liveness): add last_activity and last_push_time state fields (task 1.1)
Add time_t last_activity to ha_state_t for standby liveness timestamp tracking. Add time_t last_push_time to standby_ep_ctx_t for primary idle NOP suppression. Zero-initialize last_activity in ha_init(); last_push_time zeroed by calloc. Add test_ha_init_last_activity_is_zero to test_ha_startup.c.
This commit is contained in:
parent
e85100d761
commit
bcb45e59d2
4 changed files with 141 additions and 2 deletions
|
|
@ -656,6 +656,10 @@ int ha_init(ha_state_t *ha, const ha_config_t *cfg, int my_priority)
|
|||
ha->n_peers = 0;
|
||||
atomic_store_explicit(&ha->repl_ack_count, 0, memory_order_relaxed);
|
||||
|
||||
/* ha-heartbeat-liveness Task 1.1: zero-init liveness timestamp.
|
||||
* Written by ha_on_heartbeat_received (task 2.1); read by liveness_poll_fn. */
|
||||
ha->last_activity = 0;
|
||||
|
||||
/* heartbeat_seen starts at 0: no heartbeat seen yet.
|
||||
* ha_wait_for_heartbeat_or_timeout() calls sem_timedwait on this. */
|
||||
sem_init(&ha->heartbeat_seen, 0, 0);
|
||||
|
|
@ -2856,8 +2860,12 @@ void ha_disarm_heartbeat_timeout_vtask(ha_state_t *ha)
|
|||
typedef struct {
|
||||
ha_state_t *ha;
|
||||
cluster_t *c;
|
||||
ha_elect_ctx_t *ctx; /* always NULL — not a vote endpoint */
|
||||
int peer_idx; /* index into c->myconf->peers_cfg.candidates[] */
|
||||
ha_elect_ctx_t *ctx; /* always NULL — not a vote endpoint */
|
||||
int peer_idx; /* index into c->myconf->peers_cfg.candidates[] */
|
||||
/* Task 1.1 (ha-heartbeat-liveness): last time a push/nop was sent to this
|
||||
* standby (CLOCK_MONOTONIC seconds). Initialized to 0 at allocation;
|
||||
* written by on_standby_connected and primary_heartbeat_fn (task 2.2). */
|
||||
time_t last_push_time;
|
||||
} standby_ep_ctx_t;
|
||||
|
||||
/*
|
||||
|
|
@ -2907,6 +2915,11 @@ static void on_standby_connected(endpoint_t *ep)
|
|||
INFO("HA: outbound standby connection to peer[%d] established, ctrlhello sent",
|
||||
sctx->peer_idx);
|
||||
|
||||
/* Send an immediate NOP so the standby's heartbeat watchdog deadline resets
|
||||
* now rather than waiting up to heartbeat_interval_ms for the first periodic
|
||||
* heartbeat — avoids a false timeout when committing_timeout_ms ≈ heartbeat_timeout_ms. */
|
||||
xce_nop_req(ep);
|
||||
|
||||
/* Set state-aware dispatcher for subsequent messages on this endpoint */
|
||||
ep->msg_handler = peer_ctrl_msg_handler;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue