Commit e05f6f75 authored by Simon Riggs's avatar Simon Riggs

Code cleanup in SyncRepWaitForLSN()

Commit 14e8803f 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.
parent 6e75559e
...@@ -189,24 +189,16 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit) ...@@ -189,24 +189,16 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
*/ */
for (;;) for (;;)
{ {
int syncRepState;
/* Must reset the latch before testing state. */ /* Must reset the latch before testing state. */
ResetLatch(MyLatch); ResetLatch(MyLatch);
/* /*
* Try checking the state without the lock first. There's no * Acquiring the lock is not needed, the latch ensures proper barriers.
* guarantee that we'll read the most up-to-date value, so if it looks * If it looks like we're done, we must really be done, because once
* like we're still waiting, recheck while holding the lock. But if * walsender changes the state to SYNC_REP_WAIT_COMPLETE, it will never
* it looks like we're done, we must really be done, because once * update it again, so we can't be seeing a stale value in that case.
* walsender changes the state to SYNC_REP_WAIT_COMPLETE, it will
* never update it again, so we can't be seeing a stale value in that
* case.
*/ */
syncRepState = MyProc->syncRepState; if (MyProc->syncRepState == SYNC_REP_WAIT_COMPLETE)
if (syncRepState == SYNC_REP_WAITING)
syncRepState = MyProc->syncRepState;
if (syncRepState == SYNC_REP_WAIT_COMPLETE)
break; break;
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment