feat(ha-repl-hardening): unified replication decision loop (task 3.2)
ha_evaluate_repl_action() pure function: stale tag→PUSH_CONFIG, lsn<oldest_wal→SEND_SNAPSHOT, lsn<committed→STREAM_WAL, else CONVERGED. 5 tests. Fixed misleading stream_wal_from_zero test name per review.
This commit is contained in:
parent
aab41fa609
commit
a475ef621f
4 changed files with 176 additions and 1 deletions
|
|
@ -934,6 +934,41 @@ void ha_nop_reply_state_report(ha_state_t *ha, myconf_t *myconf,
|
|||
reply_out->data.state_report = sr;
|
||||
}
|
||||
|
||||
/*
|
||||
* ha_evaluate_repl_action — pure decision function for the unified heartbeat-
|
||||
* driven replication protocol.
|
||||
*
|
||||
* Implements the decision tree from the ha-repl-hardening design:
|
||||
*
|
||||
* if standby_tag < committed_tag → HA_REPL_PUSH_CONFIG
|
||||
* elif standby_lsn < oldest_wal_lsn → HA_REPL_SEND_SNAPSHOT
|
||||
* elif standby_lsn < committed_lsn → HA_REPL_STREAM_WAL
|
||||
* else (tag >= committed AND lsn >= committed) → HA_REPL_CONVERGED
|
||||
*
|
||||
* No side effects. All callers must use the returned action to drive the
|
||||
* replication send; they must not cache the result beyond the current cycle.
|
||||
*
|
||||
* Requirements: 2.2, 2.3, 2.4 (ha-repl-hardening spec)
|
||||
* Boundary: Primary Heartbeat Handler (ha.c)
|
||||
*/
|
||||
ha_repl_action_t ha_evaluate_repl_action(uint64_t standby_tag,
|
||||
uint64_t standby_lsn,
|
||||
uint64_t committed_tag,
|
||||
uint64_t committed_lsn,
|
||||
uint64_t oldest_wal_lsn)
|
||||
{
|
||||
if (standby_tag < committed_tag)
|
||||
return HA_REPL_PUSH_CONFIG;
|
||||
|
||||
if (standby_lsn < oldest_wal_lsn)
|
||||
return HA_REPL_SEND_SNAPSHOT;
|
||||
|
||||
if (standby_lsn < committed_lsn)
|
||||
return HA_REPL_STREAM_WAL;
|
||||
|
||||
return HA_REPL_CONVERGED;
|
||||
}
|
||||
|
||||
/*
|
||||
* ha_process_standby_state — update per-standby convergence tracking.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue