Ensure all replication message info is available and correct via WalRcv
authorSimon Riggs <simon@2ndQuadrant.com>
Thu, 9 Aug 2012 16:03:59 +0000 (17:03 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Thu, 9 Aug 2012 16:03:59 +0000 (17:03 +0100)
src/backend/replication/walreceiver.c
src/backend/replication/walreceiverfuncs.c
src/include/replication/walreceiver.h

index b0a8b197603906d8c876e084fd3674a8f5d1b280..869457003aa403b33eb8a0eba5c948d1bcd9932e 100644 (file)
@@ -218,7 +218,7 @@ WalReceiverMain(void)
        startpoint = walrcv->receiveStart;
 
        /* Initialise to a sanish value */
-       walrcv->lastMsgSendTime = walrcv->lastMsgReceiptTime = GetCurrentTimestamp();
+       walrcv->lastMsgSendTime = walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = GetCurrentTimestamp();
 
        SpinLockRelease(&walrcv->mutex);
 
@@ -749,6 +749,9 @@ ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime)
 
        /* Update shared-memory status */
        SpinLockAcquire(&walrcv->mutex);
+       if (XLByteLT(walrcv->latestWalEnd, walEnd))
+               walrcv->latestWalEndTime = sendTime;
+       walrcv->latestWalEnd = walEnd;
        walrcv->lastMsgSendTime = sendTime;
        walrcv->lastMsgReceiptTime = lastMsgReceiptTime;
        SpinLockRelease(&walrcv->mutex);
index b31e964fecd6276567ce8065810b17ded89d51d9..9eba180f04973df6c4f0bc5a73686f0aca5dcb14 100644 (file)
@@ -260,7 +260,7 @@ GetReplicationApplyDelay(void)
 
        replayPtr = GetXLogReplayRecPtr(NULL);
 
-       if (XLByteLE(receivePtr, replayPtr))
+       if (XLByteEQ(receivePtr, replayPtr))
                return 0;
 
        TimestampDifference(GetCurrentChunkReplayStartTime(),
index 8ef67f8a867a9c0cf64dfefda294134453aff4e5..62b6d2d93f0466d2a2488b70ddde84844e01d5a3 100644 (file)
@@ -83,6 +83,12 @@ typedef struct
        TimestampTz lastMsgSendTime;
        TimestampTz lastMsgReceiptTime;
 
+       /*
+        * Latest reported end of WAL on the sender
+        */
+       XLogRecPtr      latestWalEnd;
+       TimestampTz latestWalEndTime;
+
        /*
         * connection string; is used for walreceiver to connect with the primary.
         */