Don't persist synced slots before a consistent snapshot is built. update_local_synced_slot() tries to advance the local slot only when the remote slot's LSN or catalog_xmin is ahead of it. If no consistent snapshot can be built from restart_lsn, SS_SKIP_NO_CONSISTENT_SNAPSHOT is set so the slot stays temporary. But the advance attempt has already moved the local confirmed_flush to the remote value.
In the next cycle, if the remote slot has not advanced, the advance check is skipped and the skip reason is reset to SS_SKIP_NONE. Since 788ec96d59, update_and_persist_local_synced_slot() decides on persistence from slotsync_skip_reason, so it persists the slot and marks it sync-ready before a consistent snapshot exists. After promotion, such a slot can start decoding at a consistent point later than its confirmed_flush, silently skipping transactions that committed in between and were never sent to the subscriber. It can also trigger an assertion failure in later sync cycles. Fix this by tracking, across update_local_synced_slot(), whether the current cycle reached a consistent snapshot, and setting SS_SKIP_NO_CONSISTENT_SNAPSHOT whenever a temporary slot has not reached one. Reported-by: Masahiko Sawada <[email protected]> Author: Zhijie Hou <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]> Reviewed-by: Bertrand Drouvot <[email protected]> Reviewed-by: João Rito <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Discussion: https://postgr.es/m/cad21aoddn9qj2q5dnkw9daazvoh-9yef7jw64qphjgqi3yj...@mail.gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/ba11c48390004ed49b889cbd718c9e5f691fe493 Modified Files -------------- src/backend/replication/logical/slotsync.c | 53 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-)
