File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -114,21 +114,28 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
114114 /* Reset the latch before adding ourselves to the queue. */
115115 ResetLatch (& MyProc -> waitLatch );
116116
117- /*
118- * Set our waitLSN so WALSender will know when to wake us, and add
119- * ourselves to the queue.
120- */
121117 LWLockAcquire (SyncRepLock , LW_EXCLUSIVE );
122118 Assert (MyProc -> syncRepState == SYNC_REP_NOT_WAITING );
123- if (!WalSndCtl -> sync_standbys_defined )
119+
120+ /*
121+ * We don't wait for sync rep if WalSndCtl->sync_standbys_defined is
122+ * not set. See SyncRepUpdateSyncStandbysDefined.
123+ *
124+ * Also check that the standby hasn't already replied. Unlikely
125+ * race condition but we'll be fetching that cache line anyway
126+ * so its likely to be a low cost check.
127+ */
128+ if (!WalSndCtl -> sync_standbys_defined ||
129+ XLByteLE (XactCommitLSN , WalSndCtl -> lsn ))
124130 {
125- /*
126- * We don't wait for sync rep if WalSndCtl->sync_standbys_defined is
127- * not set. See SyncRepUpdateSyncStandbysDefined.
128- */
129131 LWLockRelease (SyncRepLock );
130132 return ;
131133 }
134+
135+ /*
136+ * Set our waitLSN so WALSender will know when to wake us, and add
137+ * ourselves to the queue.
138+ */
132139 MyProc -> waitLSN = XactCommitLSN ;
133140 MyProc -> syncRepState = SYNC_REP_WAITING ;
134141 SyncRepQueueInsert ();
You can’t perform that action at this time.
0 commit comments