myxce/src/controller
Rongsong Shen ce8df99037 fix(ha): close permanent standby catch-up wedge after a WAL_CHECKPOINT boundary (bug-1475)
A restarted standby could get permanently stuck unable to catch up,
with the primary re-streaming the identical doomed AppendEntries range
every heartbeat with zero progress -- discovered via a live 3-node
config-upgrade-snapshot soak. Liveness-only; no safety invariant
(Election Safety, Leader Completeness, State Machine Safety, Commit
Durability) was ever violated.

Three-layer root cause, all now closed:

1. ha_stream_wal_to_standby (config_repl.c) used to skip advancing its
   prev_streamed_lsn/prev_streamed_term tracker across WAL_CHECKPOINT
   entries (a local-only, never-replicated marker that still consumes
   a real LSN slot). Now advances across them too, while still never
   shipping a catchup entry for the checkpoint itself.

2. ha_apply_term_entry_via_library (ha.c) now JIT-resyncs
   ha->raft.log_len from persist_durable_floor() before consuming an
   AE, to correct for persist_write_checkpoint_marker advancing
   current_lsn without going through raft_log_append/record_entry_term
   (pre-existing gap, bug-1466, not itself fixed here).

3. The actual root cause, found via real instrumentation after layers
   1-2 alone still left a regression test red: record_entry_term's
   array-growth realloc zero-filled new slots, silently reclassifying
   a checkpoint's deliberately-never-recorded gap slot from "absent"
   to "present, term=0/WAL_LEGACY_TERM" the instant any later LSN got
   recorded -- a time-dependent read where a permanent fact was
   assumed. Fixed with a TERM_INDEX_UNSET (UINT64_MAX) sentinel that
   growth now fills gap slots with instead of zero, so entry_term_locked
   can distinguish "never explicitly written" from "explicitly
   recorded as legacy term 0" regardless of later array growth.

The same determinism fix exposed a second, independent instance of the
identical wedge via the snapshot-install catch-up path instead of
WAL-streaming catch-up: persist_reconcile_checkpoint_term recorded a
wire checkpoint_term of 0 as a raw, explicit write (bypassing the
growth-fill sentinel entirely), so a snapshot-installed standby read
the checkpoint LSN back as WAL_LEGACY_TERM(1) forever while the leader
now correctly read its own checkpoint LSN as absent(0) -- the same
permanent logOk mismatch, a different code path. Fixed by substituting
TERM_INDEX_UNSET for a wire value of exactly 0 before recording; a
wire 0 is unambiguous (persist_entry_term's own contract never returns
raw 0 for a present entry, so 0 can only mean genuine absence).

Independently reviewed across three rounds: sentinel mechanism
verified via real RED->GREEN revert-and-rebuild; a documentation
claim that config_repl.c/ha.c were "comment-only" corrected; the
snapshot-path gap independently traced, confirmed real via its own
RED->GREEN cycle, and fixed; two stale doc comments (persist.h's
public contract, ha.c's call-site rationale) still describing the
disproven pre-fix legacy-0 convention corrected. Suite: 1028 -> 1035
tests, 0 failures.
2026-07-28 04:48:53 +00:00
..
include feat(config-upgrade-snapshot): restore host admin-state frame safely (create-if-missing) 2026-07-24 12:48:28 +00:00
testsuite fix(ha): close permanent standby catch-up wedge after a WAL_CHECKPOINT boundary (bug-1475) 2026-07-28 04:48:53 +00:00
apiserver.c fix(schema): rename struct Data -> XceData to unshadow capnp builtin blob type 2026-07-22 09:22:04 +00:00
CLAUDE.md docs(steering): sync steering + xce-audit-invariants skill after Jul 13-18 work 2026-07-19 08:14:11 +00:00
cluster.c feat(config-upgrade-snapshot): live config-upgrade soak infra + fix bug-1468/bug-1469 (task 8.6) 2026-07-25 15:48:20 +00:00
commit.c feat(raft-apply-decoupling): ordered live apply pump activates apply_committed_entry (task 6.1) 2026-07-04 19:00:43 +00:00
config_repl.c fix(ha): close permanent standby catch-up wedge after a WAL_CHECKPOINT boundary (bug-1475) 2026-07-28 04:48:53 +00:00
config_repl.h feat(raft-ha-core-safety): establish snapshot (term,lsn) boundary on install (task 3.2) 2026-07-01 13:08:10 +00:00
ctrl_metrics.c feat: P3-7 ctrl_metrics — 7 atomic counters/gauges + descriptor table + persist wiring 2026-05-08 00:04:06 +00:00
ctrlstatus.c feat(ha-heartbeat-committed-propagation): migrate last_known_committed_config_tag to _Atomic (task 1.1) 2026-06-20 11:27:46 +00:00
dataex.c fix(persist): zero nresvals_to_sched after free_name_val_list 2026-05-20 09:39:07 +00:00
egress.c feat(ha-convergence-recovery): commit-gated scheduler egress — submit_lsn tagging + watermark gate (task 1.2) 2026-06-14 02:33:36 +00:00
ha.c fix(ha): close permanent standby catch-up wedge after a WAL_CHECKPOINT boundary (bug-1475) 2026-07-28 04:48:53 +00:00
ha.h feat(config-upgrade-snapshot): gate primary serving and promotion on the activation fence 2026-07-25 04:58:37 +00:00
ha_convergence.c fix(controller): bug-1450/1451 offload delaymgr-inline blocking work to the slow lane 2026-07-19 08:14:00 +00:00
job.c merge 2026-07-23 12:35:10 +08:00
join.c fix(controller): bug-1433 async-thread fdatasync block + bug-1434 committed_lsn CAS race 2026-07-11 12:16:28 +00:00
main.c feat(controller): clusterconfig-schema-split task 6.1 — CLI flags for hash-table tunables (optional, Req 6) 2026-07-21 07:33:32 +00:00
meson.build feat(config-upgrade-snapshot): add bug-857 regression test, correct design.md (task 8.5) 2026-07-25 10:44:14 +00:00
misc.c save works 2026-03-05 16:03:37 +08:00
myapp.c feat(config-upgrade-snapshot): gate primary serving and promotion on the activation fence 2026-07-25 04:58:37 +00:00
myconf.c feat(controller): clusterconfig-schema-split task 2.3 — remove dead port defaulting 2026-07-21 04:29:28 +00:00
opget.c fix(schema): rename struct Data -> XceData to unshadow capnp builtin blob type 2026-07-22 09:22:04 +00:00
opupd.c save works 2026-03-03 16:49:26 +08:00
persist.c fix(ha): close permanent standby catch-up wedge after a WAL_CHECKPOINT boundary (bug-1475) 2026-07-28 04:48:53 +00:00
queue.c feat(ha-commit-barrier-rollout): commit-first-then-reply in all four handlers (task 3.2) 2026-06-12 10:28:25 +00:00
repl.c fix(repl): harden standby slot allocation against WAL-retention guard clobber (bug-1474) 2026-07-26 04:11:27 +00:00
reply.c fix(persist): zero nresvals_to_sched after free_name_val_list 2026-05-20 09:39:07 +00:00
resources.c update controller code 2025-11-05 16:58:57 +08:00
sched.c feat(controller): wire real limits.yaml config through cluster_config 2026-07-23 04:24:01 +00:00
slowlane.c feat(raft-drive-async): SlowLane bounded executor for long blocking I/O (task 1.2) 2026-06-26 05:24:00 +00:00
startup_validation.c feat(ha-heartbeat-liveness): add validate_heartbeat_config startup check (task 1.2) 2026-06-01 12:26:29 +00:00
task.c save works 2026-03-04 18:18:53 +08:00
worker.c fix(worker): replicate admin host-control status updates to standbys (bug-1472) 2026-07-26 04:06:42 +00:00