Skip to content
Snippets Groups Projects
Commit 4909cb59 authored by Tatsuo Ishii's avatar Tatsuo Ishii
Browse files

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).
parent 590fc5d9
No related branches found
No related tags found
No related merge requests found
......@@ -793,15 +793,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);
}
......
......@@ -241,7 +241,8 @@ GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart)
}
/*
* 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)
......@@ -255,6 +256,8 @@ GetReplicationApplyDelay(void)
long secs;
int usecs;
TimestampTz chunckReplayStartTime;
SpinLockAcquire(&walrcv->mutex);
receivePtr = walrcv->receivedUpto;
SpinLockRelease(&walrcv->mutex);
......@@ -264,7 +267,12 @@ GetReplicationApplyDelay(void)
if (XLByteEQ(receivePtr, replayPtr))
return 0;
TimestampDifference(GetCurrentChunkReplayStartTime(),
chunckReplayStartTime = GetCurrentChunkReplayStartTime();
if (chunckReplayStartTime == 0)
return -1;
TimestampDifference(chunckReplayStartTime,
GetCurrentTimestamp(),
&secs, &usecs);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment