fix(ha-repl-hardening): snapshot fallback off-by-one — empty standby must stream, not snapshot
After reserve-lsn-0 (oldest retained WAL entry = lsn 1 on a fresh cluster), a freshly-joined empty standby (applied_lsn=0) hit the snapshot-fallback branch 'standby_lsn < oldest_wal_lsn' (0 < 1) and was sent a non-existent snapshot instead of streaming — so the own-term NOOP (lsn 1) never replicated, committed_lsn stayed 0, the own-term gate (writable_lsn=1) stayed closed, and standbys kept empty WALs. Live evidence: ha_dispatch_repl_action_for_standby: standby[0] lsn=0 < oldest_wal_lsn=1 -> requesting snapshot transfer The snapshot fallback should fire only when the standby's NEXT-needed entry (standby_lsn+1) has been GC'd below the oldest retained entry. Fix the boundary to 'standby_lsn + 1 < oldest_wal_lsn' in ha_evaluate_repl_action (and the parallel dead repl_needs_snapshot predicate). An empty standby (next-needed=1, oldest=1) now STREAMs lsn 1 -> acks -> committed_lsn 0->1 -> own-term gate opens -> standbys receive the WAL. Snapshot still fires for genuinely GC'd-behind standbys (standby_lsn+1 < oldest). No underflow (oldest=0 -> 1<0 false). Pre-reserve-lsn-0 this off-by-one was masked by oldest_wal_lsn=0 (0<0 false). TDD: test_empty_standby_fresh_cluster_streams_not_snapshot (RED->GREEN); snapshot + heartbeat pins strengthened to assert SEND_SNAPSHOT only for genuinely GC'd standbys and STREAM_WAL at the empty/boundary case. Full controller suite green under ASAN; commit engine / streamer / apply path / wire untouched.
This commit is contained in:
parent
7519fa96dd
commit
007bf0c403
4 changed files with 120 additions and 29 deletions
|
|
@ -633,8 +633,13 @@ int repl_needs_snapshot(replicator_t *r, uint64_t standby_lsn,
|
|||
(void)r;
|
||||
/* No WAL at all: empty standby can start from LSN 0 without a snapshot */
|
||||
if (oldest_wal_lsn == 0) return 0;
|
||||
/* Standby LSN predates oldest surviving WAL segment — full snapshot required */
|
||||
return (standby_lsn < oldest_wal_lsn) ? 1 : 0;
|
||||
/* Snapshot only when the standby's NEXT-needed entry (standby_lsn + 1) has
|
||||
* been GC'd below the oldest surviving WAL segment — i.e. it can no longer be
|
||||
* served by streaming. An empty standby (standby_lsn=0) whose next-needed
|
||||
* entry IS the oldest retained entry (e.g. lsn 1 post reserve-lsn-0) is
|
||||
* streamable: 0 + 1 < 1 is false → no snapshot. Mirrors the boundary in
|
||||
* ha_evaluate_repl_action (ha.c). */
|
||||
return (standby_lsn + 1 < oldest_wal_lsn) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue