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

Commit e05f6f7

Browse files
Code cleanup in SyncRepWaitForLSN()
Commit 14e8803 removed LWLocks when accessing MyProc->syncRepState but didn't clean up the surrounding code and comments. Cleanup and backpatch to 9.5, to keep code similar. Julien Rouhaud, improved by suggestion from Michael Paquier, implemented trivially by myself.
1 parent 6e75559 commit e05f6f7

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/backend/replication/syncrep.c

+5-13
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,16 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
189189
*/
190190
for (;;)
191191
{
192-
int syncRepState;
193-
194192
/* Must reset the latch before testing state. */
195193
ResetLatch(MyLatch);
196194

197195
/*
198-
* Try checking the state without the lock first. There's no
199-
* guarantee that we'll read the most up-to-date value, so if it looks
200-
* like we're still waiting, recheck while holding the lock. But if
201-
* it looks like we're done, we must really be done, because once
202-
* walsender changes the state to SYNC_REP_WAIT_COMPLETE, it will
203-
* never update it again, so we can't be seeing a stale value in that
204-
* case.
196+
* Acquiring the lock is not needed, the latch ensures proper barriers.
197+
* If it looks like we're done, we must really be done, because once
198+
* walsender changes the state to SYNC_REP_WAIT_COMPLETE, it will never
199+
* update it again, so we can't be seeing a stale value in that case.
205200
*/
206-
syncRepState = MyProc->syncRepState;
207-
if (syncRepState == SYNC_REP_WAITING)
208-
syncRepState = MyProc->syncRepState;
209-
if (syncRepState == SYNC_REP_WAIT_COMPLETE)
201+
if (MyProc->syncRepState == SYNC_REP_WAIT_COMPLETE)
210202
break;
211203

212204
/*

0 commit comments

Comments
 (0)