feat(ha-wal-replication): standby WAL ACK reply (tasks 3.1-3.3)
Standby sends WalAckReply via xce_reply after each successfully applied WAL entry. ha_apply_wal_catchup_entry signature extended with endpoint_t* and cluster_t* parameters. walackreplymsg union arm added to RequestReply capnp schema and xce_reply_t. Error entries skip ACK. Dispatch gate test confirms OPCode_walCatchupEntry allowed in CTRL_STANDBY/ELECTING/INIT. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
81dbc4d7b4
commit
566c91cd8b
8 changed files with 304 additions and 60 deletions
|
|
@ -281,13 +281,17 @@ int ha_dispatch_gate(ha_state_t *ha, int opcode);
|
|||
* persistent storage and advance ha->applied_lsn on success.
|
||||
*
|
||||
* Called from cluster.c OPCode_walCatchupEntry dispatch handler (Task 2.1).
|
||||
* On success (rc == 0): applied_lsn advances to entry->lsn+1.
|
||||
* On error (rc < 0): logs ERROR, returns error; caller skips (Req 3.3).
|
||||
* On success (rc == 0): applied_lsn advances to entry->lsn+1 and a
|
||||
* WalAckReply {term, lsn, success=1} is sent back to the primary via
|
||||
* xce_reply(ep, c->myhost, &reply) (Task 3.1, Req 3.1).
|
||||
* On error (rc < 0): logs ERROR, returns error; no ACK sent (Task 3.2).
|
||||
* applied_lsn is in-memory only — not persisted to disk.
|
||||
* ep and c may be NULL in unit-test builds (XCE_TESTING); ACK is skipped.
|
||||
* Requirements: 3.1, 3.2, 3.3, 3.4, 3.5
|
||||
*/
|
||||
int ha_apply_wal_catchup_entry(ha_state_t *ha, persist_t *p,
|
||||
wal_catchup_entry_t *entry);
|
||||
wal_catchup_entry_t *entry,
|
||||
struct endpoint_t *ep, cluster_t *c);
|
||||
|
||||
/* ha_nop_reply_state_report — populate a heartbeat reply with stateReport.
|
||||
* Fills *sr from ha->applied_lsn (atomic read) and myconf->config_version_tag,
|
||||
|
|
@ -479,7 +483,12 @@ int ha_restore_term(ha_state_t *ha, const char *workdir);
|
|||
* Applies term/voted_for/freshness gate; persists state via ha_persist_term().
|
||||
* Returns 1 = vote granted, 0 = vote denied, <0 = error.
|
||||
* Requirements: 2.2, 2.3, 2.4, 2.5, 2.6, 9.1
|
||||
*
|
||||
* TEST-ONLY (XCE_TESTING): production vote dispatch is cluster.c →
|
||||
* raft_on_vote_request. This is the legacy entry point for test-only
|
||||
* role-gate unit tests (test_ha_vote_gate.c, test_ha_election.c).
|
||||
*/
|
||||
#ifdef XCE_TESTING
|
||||
int handle_request_vote(ha_state_t *ha,
|
||||
uint64_t term,
|
||||
const char *candidate_id,
|
||||
|
|
@ -488,6 +497,7 @@ int handle_request_vote(ha_state_t *ha,
|
|||
uint64_t my_config_tag,
|
||||
uint64_t my_last_lsn,
|
||||
int in_catch_up_flag);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ha_elect_evaluate_and_signal: evaluate accumulated ha_elect_ctx_t votes.
|
||||
|
|
@ -566,6 +576,11 @@ void ha_on_primary_ctrl_fd_rdhup(ha_state_t *ha, cluster_t *c);
|
|||
*/
|
||||
void ha_arm_heartbeat_timeout_vtask(ha_state_t *ha, cluster_t *c);
|
||||
|
||||
/* ha_discover_primary: step down from CTRL_ELECTING to CTRL_STANDBY when a
|
||||
* live primary message (NOP, config push, ctrlhello, WAL, snapshot) arrives.
|
||||
* Safe to call from any state — no-ops unless role == CTRL_ELECTING. */
|
||||
void ha_discover_primary(ha_state_t *ha, cluster_t *c);
|
||||
|
||||
/* ha_on_heartbeat_received: reset the heartbeat deadline (Req 6.3). */
|
||||
void ha_on_heartbeat_received(ha_state_t *ha);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue