feat(ha-term-safety): retire term-0 repl_broadcast live send; carry leader term on replication (task 3.4)

Closes bug-990: the live replicator repl_broadcast wire-encoded term=0
(entry.term was never set), so standbys persisted hdr.term=0 and took the
legacy direct-apply path instead of the library (term,lsn) intake. Now the
live broadcast and catch-up streamer carry the leader's real term + AE prev
tuple; ha_apply_wal_catchup_entry routes every term-carrying entry through
raft_on_append_entries_request -> on_persist_entry (leader term stamped),
retiring the term-0 direct-apply. Standbys now persist the leader's real term
and reconcile by (term,lsn); the live commit chain is end-to-end.

848/849/850 + persist-before-ACK + commit-barrier + bug-960 preserved.
Proven at integration level; the definitive live STRICT_TERM failover run is
env-blocked here (bug-924 overlayfs) and recommended on a real fs.
This commit is contained in:
Rongsong Shen 2026-06-22 15:45:14 +00:00
parent 87242aa8e9
commit efe621c124
11 changed files with 307 additions and 45 deletions

View file

@ -67,9 +67,19 @@ void repl_expire_disconnect_slots(replicator_t *r, time_t now_s, uint32_t snap_i
* NULL registry counts zero. Consumed by ha_has_write_quorum (ha.c). */
int repl_active_standby_count(replicator_t *r);
/* Replication send (stub in P2-1; wired in P2-4) */
/* Replication send (stub in P2-1; wired in P2-4).
*
* ha-term-safety task 3.4 (Req 1.3/1.4): the LIVE primary append replicator.
* Carries the leader's per-entry Raft term (`hdr->term`) and the AppendEntries
* prev tuple (`prev_log_index = hdr->lsn - 1`, `prev_log_term` supplied by the
* caller from its term index) on every broadcast, so the standby intake routes
* the entry through `raft_on_append_entries_request` and persists the LEADER's
* term (not a local substitute or 0). `prev_log_term` is the term recorded for
* `hdr->lsn - 1` (0 when `hdr->lsn == 1`, i.e. no predecessor). The term-0
* legacy direct-apply receive path is thereby retired for live entries. */
int repl_broadcast(replicator_t *r, const wal_entry_hdr_t *hdr,
const void *payload, uint32_t payload_len);
const void *payload, uint32_t payload_len,
uint64_t prev_log_term);
/* AppendEntries send (ha-term-safety task 2.3, Req 1.3/3.1).
*