feat(raft-ha-core-safety): establish snapshot (term,lsn) boundary on install (task 3.2)

Adds checkpointTerm (@6, append-only) to the SnapshotTransfer wire
message. The leader stamps it via persist_entry_term(p, checkpoint_lsn)
when sending a snapshot; the standby reconciles it into its own
per-LSN term index (persist_reconcile_checkpoint_term) right after
persist_load_snapshot succeeds, before applied_lsn advances. This
authoritatively overwrites any stale local term a divergent
pre-snapshot entry left at the checkpoint LSN, closing the gap task
3.1's RED test proved (Expected 7 Was 3 -> now passes). Transport
stays persist_t-free; the reconcile lives in persist.c per the
existing dependency direction. Decode is auto-generated via capnp
mapname; only the hand-rolled encode path (request.c/typemap.h, needed
for the raw snapshot payload) required a matching manual update.

test_ha_core_safety 25/0, test_config_repl 66/0, no ASAN reports.
This commit is contained in:
Rongsong Shen 2026-07-01 13:08:10 +00:00
parent 21858faba4
commit a53b9a7b6c
11 changed files with 132 additions and 23 deletions

View file

@ -878,6 +878,16 @@ struct SnapshotTransfer $C.mapname("snapshot_transfer_t") {
chunkOffset @3 :UInt64 $C.mapname("chunk_offset"); # byte offset in the full snapshot
totalSize @4 :UInt64 $C.mapname("total_size"); # total snapshot size in bytes
isLast @5 :Bool $C.mapname("is_last"); # true for the final chunk
# raft-ha-core-safety task 3.2 (Req 3.1/5.1): the leader's term for the
# checkpoint LSN (persist_entry_term(p, snapshotLsn) at send time). The
# receiver reconciles this into its own per-LSN term index after install so
# the snapshot boundary establishes a verifiable (term, lsn) pair and any
# divergent stale-term pre-snapshot entry at this LSN is authoritatively
# overwritten. Append-only field number (@6) — no collision with @0-@5
# above. 0 = unset (legacy sender that never stamped this field) — the
# receiver treats 0 as WAL_LEGACY_TERM, the same convention persist's
# existing legacy-0 term mapping already uses.
checkpointTerm @6 :UInt64 $C.mapname("checkpoint_term");
}
struct WalCatchupEntry $C.mapname("wal_catchup_entry_t") {