From 87d8bd7c9fdc63d892968e1248e639c8078af615 Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Thu, 9 Aug 2012 17:03:59 +0100 Subject: [PATCH] Ensure all replication message info is available and correct via WalRcv --- src/backend/replication/walreceiver.c | 5 ++++- src/backend/replication/walreceiverfuncs.c | 2 +- src/include/replication/walreceiver.h | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index b0a8b19760..869457003a 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -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); diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index b31e964fec..9eba180f04 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -260,7 +260,7 @@ GetReplicationApplyDelay(void) replayPtr = GetXLogReplayRecPtr(NULL); - if (XLByteLE(receivePtr, replayPtr)) + if (XLByteEQ(receivePtr, replayPtr)) return 0; TimestampDifference(GetCurrentChunkReplayStartTime(), diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h index 8ef67f8a86..62b6d2d93f 100644 --- a/src/include/replication/walreceiver.h +++ b/src/include/replication/walreceiver.h @@ -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. */