feat(ha-repl-hardening): wire OPCode_walCatchupEntry standby handler (task 2.1)

Replace stub with ha_apply_wal_catchup_entry() calling apply_wal_entry().
CAS-advance applied_lsn on success; log ERROR and skip on failure.
Standby stays in CTRL_STANDBY throughout. 3 new unit tests.
This commit is contained in:
Rongsong Shen 2026-06-04 15:05:52 +00:00
parent e3ca775f0d
commit 647b88ce57
5 changed files with 251 additions and 1 deletions

View file

@ -1,6 +1,7 @@
#include "config.h"
#include <errno.h>
#include <inttypes.h>
#include <rtti.h>
#include <stdatomic.h>
#include <string.h>
@ -154,6 +155,23 @@ static int do_notify(cluster_t* c, endpoint_t* ep, xce_request_t* req)
}
return 0;
}
/* handle_wal_catchup_entry: dispatch handler for OPCode_walCatchupEntry.
* Delegates to ha_apply_wal_catchup_entry (ha.c); on error logs and returns 0
* (skip, no crash). Standby remains in CTRL_STANDBY throughout (Req 3.4). */
static int handle_wal_catchup_entry(cluster_t *c, xce_request_t *req)
{
wal_catchup_entry_t *entry =
(wal_catchup_entry_t *)req->body.walcatchupentrymsg;
/* body may be NULL if the sender used Request_body_nomsg; skip gracefully */
if (!entry)
return 0;
ha_apply_wal_catchup_entry(&c->ha, &c->persist, entry);
/* Return 0 regardless of per-entry errors — Req 3.3: skip, don't crash */
return 0;
}
static int myreq_handler(vtask_t* task)
{
vtask_data_t* data = (vtask_data_t*)task->data;
@ -351,6 +369,13 @@ static int myreq_handler(vtask_t* task)
/* Primary pushes config to this standby — save and reload */
rc = handle_repl_config_push(c, ep, &request);
break;
case OPCode_walCatchupEntry:
/* Task 2.1: standby applies a single WAL catch-up entry from the
* primary. applied_lsn advances on success; errors are logged and
* skipped (Req 3.1, 3.3, 3.4, 3.5). No reply is sent — primary
* learns of progress via the next heartbeat reply's stateReport. */
rc = handle_wal_catchup_entry(c, &request);
break;
case OPCode_upgradeConfig:
#if CONF_ENABLE_UPGRADE_CONFIG
/* OPCode_upgradeConfig is sent BY the primary TO standbys to push config.