Fix assertion failure during decoding from synced slots. The slot synchronization skips updating the confirmed_flush LSN of the local slot if the local slot has a newer catalog_xmin or restart_lsn, but still allows updating the two_phase and two_phase_at fields of the slot. This opens up a window for the prepared transactions between old confirmed_flush LSN and two_phase_at to unexpectedly get decoded and sent to the downstream after promotion. Then, while decoding the commit prepared the assert will fail, which expects that the prepare hasn't been sent to the downstream.
The fix is to skip updating the other slot fields when we are skipping to update the confirmed_flush LSN of the slot. We didn't backpatch this commit as two_phase_at was not synced in back branches, which means prepared transactions won't be unexpectedly sent to downstream. We discovered this problem while analyzing BF failure reported in the discussion link. Reliably reproducing this issue without a debugger is difficult. Given its rarity, adding specific injection point to test it doesn't seem worthwhile, so we won't be adding a dedicated test case. Author: Zhijie Hou <houzj.f...@fujitsu.com> Reviewed-by: shveta malik <shveta.ma...@gmail.com> Reviewed-by: Masahiko Sawada <sawada.m...@gmail.com> Reviewed-by: Amit Kapila <amit.kapil...@gmail.com> Discussion: https://postgr.es/m/os0pr01mb5716b44052000eb91efae60e94...@os0pr01mb5716.jpnprd01.prod.outlook.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/3ff2a1f0c9e8d016f3288f4da3962eb1f1592cd8 Modified Files -------------- src/backend/replication/logical/slotsync.c | 39 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 12 deletions(-)