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)
114
114
/* Reset the latch before adding ourselves to the queue. */
115
115
ResetLatch (& MyProc -> waitLatch );
116
116
117
- /*
118
- * Set our waitLSN so WALSender will know when to wake us, and add
119
- * ourselves to the queue.
120
- */
121
117
LWLockAcquire (SyncRepLock , LW_EXCLUSIVE );
122
118
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 ))
124
130
{
125
- /*
126
- * We don't wait for sync rep if WalSndCtl->sync_standbys_defined is
127
- * not set. See SyncRepUpdateSyncStandbysDefined.
128
- */
129
131
LWLockRelease (SyncRepLock );
130
132
return ;
131
133
}
134
+
135
+ /*
136
+ * Set our waitLSN so WALSender will know when to wake us, and add
137
+ * ourselves to the queue.
138
+ */
132
139
MyProc -> waitLSN = XactCommitLSN ;
133
140
MyProc -> syncRepState = SYNC_REP_WAITING ;
134
141
SyncRepQueueInsert ();
You can’t perform that action at this time.
0 commit comments