Code cleanup in SyncRepWaitForLSN()
authorSimon Riggs
Fri, 12 Aug 2016 11:49:38 +0000 (12:49 +0100)
committerSimon Riggs
Fri, 12 Aug 2016 11:49:38 +0000 (12:49 +0100)
Commit 14e8803f1 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.

src/backend/replication/syncrep.c

index 3fa08567e72facce88b56d6b6fce35a3deba2249..132212a451bbac05b346d6306e7d060c71646c35 100644 (file)
@@ -160,24 +160,16 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
     */
    for (;;)
    {
-       int         syncRepState;
-
        /* Must reset the latch before testing state. */
        ResetLatch(MyLatch);
 
        /*
-        * Try checking the state without the lock first.  There's no
-        * guarantee that we'll read the most up-to-date value, so if it looks
-        * like we're still waiting, recheck while holding the lock.  But if
-        * it looks like we're done, we must really be done, because once
-        * 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.
+        * Acquiring the lock is not needed, the latch ensures proper barriers.
+        * If it looks like we're done, we must really be done, because once
+        * 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 (syncRepState == SYNC_REP_WAITING)
-           syncRepState = MyProc->syncRepState;
-       if (syncRepState == SYNC_REP_WAIT_COMPLETE)
+       if (MyProc->syncRepState == SYNC_REP_WAIT_COMPLETE)
            break;
 
        /*