0001-comments-changes.patch.txt

text/plain

Filename: 0001-comments-changes.patch.txt
Type: text/plain
Part: 0
Message: Re: Improve pg_sync_replication_slots() to wait for primary to advance
From 4f5634c33092e536b8662244dd7436f045195690 Mon Sep 17 00:00:00 2001
From: Shveta Malik <shveta.malik@gmail.com>
Date: Tue, 23 Sep 2025 10:24:19 +0530
Subject: [PATCH] comments changes.

---
 src/backend/replication/logical/slotsync.c | 28 +++++++++++-----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 19792a95635..f980c0f73c4 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -42,8 +42,8 @@
  * If the pg_sync_replication API is used to sync the slots, and if the slots
  * are not ready to be synced and are marked as RS_TEMPORARY because of any of
  * the reasons mentioned above, then the API also waits and retries until the
- * slots are ready to be synced. Refer to the comments in SyncReplicationSlots()
- * for more details.
+ * slots are marked as RS_PERSISTENT (which means sync-ready). Refer to the
+ * comments in SyncReplicationSlots() for more details.
  *
  * Any standby synchronized slots will be dropped if they no longer need
  * to be synchronized. See comment atop drop_local_obsolete_slots() for more
@@ -572,7 +572,7 @@ reserve_wal_for_local_slot(XLogRecPtr restart_lsn)
  * local ones, then update the LSNs and persist the local synced slot for
  * future synchronization; otherwise, do nothing.
  *
- * slot_persistence_pending is set to true if any of the slots fail to
+ * *slot_persistence_pending is set to true if any of the slots fail to
  * persist. It is utilized by the pg_sync_replication_slots() API.
  *
  * Return true if the slot is marked as RS_PERSISTENT (sync-ready), otherwise
@@ -604,7 +604,9 @@ update_and_persist_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid,
 		 * the next cycle. It may take more time to create such a
 		 * slot. Therefore, we keep this slot and attempt the
 		 * synchronization in the next cycle. Update the
-		 * slot_persistence_pending flag, so the API can retry.
+		 *
+		 * We also update the slot_persistence_pending parameter, so
+		 * the API can retry.
 		 */
 		if (slot_persistence_pending)
 			*slot_persistence_pending = true;
@@ -623,7 +625,7 @@ update_and_persist_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid,
 				errdetail("Synchronization could lead to data loss, because the standby could not build a consistent snapshot to decode WALs at LSN %X/%08X.",
 						  LSN_FORMAT_ARGS(slot->data.restart_lsn)));
 
-		/* set this, so that API can retry */
+		/* Set this, so that API can retry */
 		if (slot_persistence_pending)
 			*slot_persistence_pending = true;
 
@@ -650,7 +652,7 @@ update_and_persist_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid,
  * updated. The slot is then persisted and is considered as sync-ready for
  * periodic syncs.
  *
- * slot_persistence_pending is set to true if any of the slots fail to
+ * *slot_persistence_pending is set to true if any of the slots fail to
  * persist. It is utilized by the pg_sync_replication_slots() API.
  *
  * Returns TRUE if the local slot is updated.
@@ -1953,17 +1955,17 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
 
 		validate_remote_info(wrconn);
 
-		/* Retry until all slots are sync ready at least */
+		/* Retry until all the slots are sync-ready */
 		for (;;)
 		{
 			int		rc;
 			bool	started_tx = false;
 			bool	slot_persistence_pending = false;
 
-			/* reset flag before every iteration */
+			/* Reset flag before every iteration */
 			slot_persistence_pending = false;
 
-			/* check for interrupts and config changes */
+			/* Check for interrupts and config changes */
 			ProcessSlotSyncAPIChanges();
 
 			/*
@@ -1994,10 +1996,9 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
 			 * for future iterations (only needed if we haven't done it yet)
 			 */
 			if (slot_names == NIL && slot_persistence_pending)
-				/* Extract slot names from the remote slots */
 				slot_names = extract_slot_names(remote_slots);
 
-			/* update the failure structure so that it can be freed on error */
+			/* Update the failure structure so that it can be freed on error */
 			fparams.slot_names = slot_names;
 
 			/* Free the current remote_slots list */
@@ -2007,11 +2008,11 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
 			if (started_tx)
 				CommitTransactionCommand();
 
-			/* Done if all slots are at least sync ready */
+			/* Done if all slots are persisted i.e. are sync-ready */
 			if (!slot_persistence_pending)
 				break;
 
-			/* wait before retrying */
+			/* Wait before retrying */
 			rc = WaitLatch(MyLatch,
 					WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
 					SLOTSYNC_API_NAPTIME_MS,
@@ -2022,7 +2023,6 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
 
 		}
 
-		/* Clean up slot_names if allocated in TopMemoryContext */
 		if (slot_names)
 			list_free_deep(slot_names);
 
-- 
2.34.1