Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 92f4786

Browse files
Additional test for each commit in sync rep path to plug minute
possibility of race condition that would effect performance only. Requested by Robert Haas. Re-arrange related comments.
1 parent bfa4440 commit 92f4786

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/backend/replication/syncrep.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)