Fix the review comments and a bug in the slot sync code. Ensure that when updating the catalog_xmin of the synced slots, it is first written to disk before changing the in-memory value (effective_catalog_xmin). This is to prevent a scenario where the in-memory value change triggers a vacuum to remove catalog tuples before the catalog_xmin is written to disk. In the event of a crash before the catalog_xmin is persisted, we would not know that some required catalog tuples have been removed and the synced slot would be invalidated.
Change the sanity check to ensure that remote_slot's confirmed_flush LSN can't precede the local/synced slot during slot sync. Note that the restart_lsn of the synced/local slot can be ahead of remote_slot. This can happen when slot advancing machinery finds a running xacts record after reaching the consistent state at a later point than the primary where it serializes the snapshot and updates the restart_lsn. Make the check to sync slots robust by allowing to sync only when the confirmed_lsn, restart_lsn, or catalog_xmin of the remote slot is ahead of the synced/local slot. Reported-by: Amit Kapila and Shveta Malik Author: Hou Zhijie, Shveta Malik Reviewed-by: Amit Kapila, Bertrand Drouvot Discussion: https://postgr.es/m/os0pr01mb57162b67d3cb01b2756fba6d94...@os0pr01mb5716.jpnprd01.prod.outlook.com Discussion: https://postgr.es/m/cajpy0ucss5zmdyuxhvw41hsdtbrqx1hbyqkofhnj7qq+2zn...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/3741f2a09d5205ec32bd8af5d1f397e08995932b Modified Files -------------- src/backend/replication/logical/slotsync.c | 163 +++++++++++++++++++++-------- 1 file changed, 119 insertions(+), 44 deletions(-)