feat(ha-heartbeat-liveness): role-based liveness reset in opcode dispatch (task 3.1)

Replace fd-based guard in OPCode_nop with role==CTRL_STANDBY check.
Add ha_on_heartbeat_received call to OPCode_hello ctrlhello path when standby.
Satisfies Req 1.3 (any message resets deadline) and Req 4.1 (ctrlhello counts).
3 new dispatch guard tests added to test_ha_liveness.c.
This commit is contained in:
Rongsong Shen 2026-06-01 15:31:15 +00:00
parent 622302a55c
commit d937c1c1bb
3 changed files with 104 additions and 3 deletions

View file

@ -196,6 +196,10 @@ static int myreq_handler(vtask_t* task)
if (request.body_which == Request_body_ctrlhellomsg) {
/* Extended OP_ctrlHello with CtrlHelloRequest body — state sync (Req 6.5–6.7) */
rc = handle_ctrlhello(c, ep, &request);
/* Req 4.1: ctrlhello counts as primary activity — reset liveness deadline. */
if ((ctrl_role_t)atomic_load_explicit(&c->ha.role, memory_order_acquire)
== CTRL_STANDBY)
ha_on_heartbeat_received(&c->ha);
} else if (request.body_which == Request_body_replymsg
&& request.body.replymsg
&& request.body.replymsg->data_which
@ -222,8 +226,10 @@ static int myreq_handler(vtask_t* task)
reply.status = 0;
reply.data_which = RequestReply_data_nodata;
xce_reply(ep, c->myhost, &reply);
/* Reset heartbeat watchdog when nop arrives on the primary channel */
if (ep->fd == c->ha.primary_ctrl_fd)
/* Req 1.3: any NOP from primary resets liveness deadline on standby.
* Role check is safe from any primary-connected ep — no fd comparison needed. */
if ((ctrl_role_t)atomic_load_explicit(&c->ha.role, memory_order_acquire)
== CTRL_STANDBY)
ha_on_heartbeat_received(&c->ha);
break;
case OPCode_join: