postgres.git / summary / log / commit / refs
commit 089b371a3977bd3a7b71a79966e8ea86296ecda3
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Fri Mar 13 23:16:50 2015 +0000
First released in: 9.5.0, 9.2.11, 9.3.7, 9.4.2
Fix integer overflow in debug message of walreceiver
The message tries to tell the replication apply delay which fails if
the first WAL record is not applied yet. Fix is, instead of telling
overflowed minus numeric, showing "N/A" which indicates that the delay
data is not yet available. Problem reported by me and patch by
FabrÃzio de Royes Mello.
Back patched to 9.4, 9.3 and 9.2 stable branches (9.1 and 9.0 do not
have the debug message).
src/backend/replication/walreceiver.c | 21 ++++++++++++++++-----
src/backend/replication/walreceiverfuncs.c | 12 ++++++++++--
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 62d642ad5ec..96ac6a6a602 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -1199,15 +1199,26 @@ ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime)
{
char *sendtime;
char *receipttime;
+ int applyDelay;
/* Copy because timestamptz_to_str returns a static buffer */
sendtime = pstrdup(timestamptz_to_str(sendTime));
receipttime = pstrdup(timestamptz_to_str(lastMsgReceiptTime));
- elog(DEBUG2, "sendtime %s receipttime %s replication apply delay %d ms transfer latency %d ms",
- sendtime,
- receipttime,
- GetReplicationApplyDelay(),
- GetReplicationTransferLatency());
+ applyDelay = GetReplicationApplyDelay();
+
+ /* apply delay is not available */
+ if (applyDelay == -1)
+ elog(DEBUG2, "sendtime %s receipttime %s replication apply delay (N/A) transfer latency %d ms",
+ sendtime,
+ receipttime,
+ GetReplicationTransferLatency());
+ else
+ elog(DEBUG2, "sendtime %s receipttime %s replication apply delay %d ms transfer latency %d ms",
+ sendtime,
+ receipttime,
+ applyDelay,
+ GetReplicationTransferLatency());
+
pfree(sendtime);
pfree(receipttime);
}
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index 9870d9cf894..9e16c20dbb2 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -307,7 +307,8 @@ GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
}
/*
- * Returns the replication apply delay in ms
+ * Returns the replication apply delay in ms or -1
+ * if the apply delay info is not available
*/
int
GetReplicationApplyDelay(void)
@@ -321,6 +322,8 @@ GetReplicationApplyDelay(void)
long secs;
int usecs;
+ TimestampTz chunckReplayStartTime;
+
SpinLockAcquire(&walrcv->mutex);
receivePtr = walrcv->receivedUpto;
SpinLockRelease(&walrcv->mutex);
@@ -330,7 +333,12 @@ GetReplicationApplyDelay(void)
if (receivePtr == replayPtr)
return 0;
- TimestampDifference(GetCurrentChunkReplayStartTime(),
+ chunckReplayStartTime = GetCurrentChunkReplayStartTime();
+
+ if (chunckReplayStartTime == 0)
+ return -1;
+
+ TimestampDifference(chunckReplayStartTime,
GetCurrentTimestamp(),
&secs, &usecs);
[parent: 5bdf3cf5ad30]