diff --git a/src/common/backend/utils/adt/timestamp.cpp b/src/common/backend/utils/adt/timestamp.cpp index 626a6a0ff..11c011282 100755 --- a/src/common/backend/utils/adt/timestamp.cpp +++ b/src/common/backend/utils/adt/timestamp.cpp @@ -5773,3 +5773,11 @@ void timestamp_CalculateFields(TimestampTz* dt1, TimestampTz* dt2, fsec_t* fsec, timestamp_FilpSign(tm); } } + +void WalReplicationTimestampToString(WalReplicationTimestampInfo *timeStampInfo) +{ + COPY_AND_CHECK_TIMESTAMP(timeStampInfo->nowTimeStamp, MAXTIMESTAMPLEN + 1, timeStampInfo->nowtime); + COPY_AND_CHECK_TIMESTAMP(timeStampInfo->timeoutStamp, MAXTIMESTAMPLEN + 1, timeStampInfo->timeout); + COPY_AND_CHECK_TIMESTAMP(timeStampInfo->lastRecStamp, MAXTIMESTAMPLEN + 1, timeStampInfo->last_timestamp); + COPY_AND_CHECK_TIMESTAMP(timeStampInfo->heartbeatStamp, MAXTIMESTAMPLEN + 1, timeStampInfo->heartbeat); +} \ No newline at end of file diff --git a/src/gausskernel/storage/replication/walreceiver.cpp b/src/gausskernel/storage/replication/walreceiver.cpp index dc474a199..712436ef4 100755 --- a/src/gausskernel/storage/replication/walreceiver.cpp +++ b/src/gausskernel/storage/replication/walreceiver.cpp @@ -705,19 +705,17 @@ static bool WalRecCheckTimeOut(TimestampTz nowtime, TimestampTz last_recv_timest * replication timeout. Ping the server. */ if (nowtime >= timeout) { + WalReplicationTimestampInfo timeStampInfo; + timeStampInfo.timeout = timeout; + timeStampInfo.nowtime = nowtime; + timeStampInfo.last_timestamp = last_reply_time; + timeStampInfo.heartbeat = heartbeat; if (log_min_messages <= DEBUG2 || client_min_messages <= DEBUG2) { - size_t size = MAXDATELEN + 1; - char nowTimeStamp[size]; - COPY_AND_CHECK_TIMESTAMP(nowTimeStamp, size, nowtime); - char timeoutStamp[size]; - COPY_AND_CHECK_TIMESTAMP(timeoutStamp, size, timeout); - char lastRecStamp[size]; - COPY_AND_CHECK_TIMESTAMP(lastRecStamp, size, last_recv_timestamp); - char heartbeatStamp[size]; - COPY_AND_CHECK_TIMESTAMP(heartbeatStamp, size, heartbeat); + WalReplicationTimestampToString(&timeStampInfo); ereport(DEBUG2, (errmsg("now time(%s) timeout time(%s) last recv time(%s), heartbeat time(%s), ping_sent(%d)", - nowTimeStamp, timeoutStamp, lastRecStamp, heartbeatStamp, ping_sent))); + timeStampInfo.nowTimeStamp, timeStampInfo.timeoutStamp, timeStampInfo.lastRecStamp, + timeStampInfo.heartbeatStamp, ping_sent))); } if (!ping_sent) { requestReply = true; @@ -725,19 +723,13 @@ static bool WalRecCheckTimeOut(TimestampTz nowtime, TimestampTz last_recv_timest knl_g_set_redo_finish_status(0); ereport(LOG, (errmsg("set knl_g_set_redo_finish_status to false in WalRecCheckTimeOut"))); if (log_min_messages <= ERROR || client_min_messages <= ERROR) { - size_t size = MAXDATELEN + 1; - char nowTimeStamp[size]; - COPY_AND_CHECK_TIMESTAMP(nowTimeStamp, size, nowtime); - char timeoutStamp[size]; - COPY_AND_CHECK_TIMESTAMP(timeoutStamp, size, timeout); - char lastRecStamp[size]; - COPY_AND_CHECK_TIMESTAMP(lastRecStamp, size, last_recv_timestamp); - char heartbeatStamp[size]; - COPY_AND_CHECK_TIMESTAMP(heartbeatStamp, size, heartbeat); + timeStampInfo.last_timestamp = last_recv_timestamp; + WalReplicationTimestampToString(&timeStampInfo); ereport(ERROR, (errcode(ERRCODE_CONNECTION_TIMED_OUT), errmsg("terminating walreceiver due to timeout " "now time(%s) timeout time(%s) last recv time(%s) heartbeat time(%s)", - nowTimeStamp, timeoutStamp, lastRecStamp, heartbeatStamp))); + timeStampInfo.nowTimeStamp, timeStampInfo.timeoutStamp, timeStampInfo.lastRecStamp, + timeStampInfo.heartbeatStamp))); } } } diff --git a/src/gausskernel/storage/replication/walsender.cpp b/src/gausskernel/storage/replication/walsender.cpp index 66b3bb1eb..c4ec23c7f 100755 --- a/src/gausskernel/storage/replication/walsender.cpp +++ b/src/gausskernel/storage/replication/walsender.cpp @@ -3336,17 +3336,16 @@ static void WalSndCheckTimeOut(TimestampTz now) * standby. */ if (log_min_messages <= ERROR || client_min_messages <= ERROR) { - char nowTimeStamp[MAXDATELEN + 1]; - COPY_AND_CHECK_TIMESTAMP(nowTimeStamp, MAXDATELEN + 1, now); - char timeoutStamp[MAXDATELEN + 1]; - COPY_AND_CHECK_TIMESTAMP(timeoutStamp, MAXDATELEN + 1, timeout); - char lastRecStamp[MAXDATELEN + 1]; - COPY_AND_CHECK_TIMESTAMP(lastRecStamp, MAXDATELEN + 1, last_reply_time); - char heartbeatStamp[MAXDATELEN + 1]; - COPY_AND_CHECK_TIMESTAMP(heartbeatStamp, MAXDATELEN + 1, heartbeat); + WalReplicationTimestampInfo timeStampInfo; + timeStampInfo.timeout = timeout; + timeStampInfo.nowtime = now; + timeStampInfo.last_timestamp = last_reply_time; + timeStampInfo.heartbeat = heartbeat; + WalReplicationTimestampToString(&timeStampInfo); ereport(ERROR, (errmsg("terminating Walsender process due to replication timeout." - "now time(%s) timeout time(%s) last recv time(%s) heartbeat time(%s)", nowTimeStamp, - timeoutStamp, lastRecStamp, heartbeatStamp))); + "now time(%s) timeout time(%s) last recv time(%s) heartbeat time(%s)", + timeStampInfo.nowTimeStamp, timeStampInfo.timeoutStamp, + timeStampInfo.lastRecStamp, timeStampInfo.heartbeatStamp))); } WalSndShutdown(); } diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index 3b080b09b..e760209c3 100755 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -94,6 +94,24 @@ do { #define MAX_INT32 2147483600 #endif +#define MAXTIMESTAMPLEN 128 + +/* + * HA wal replication timestamp info + */ +typedef struct WalReplicationTimestampInfo { + char nowTimeStamp[MAXTIMESTAMPLEN + 1]; + char timeoutStamp[MAXTIMESTAMPLEN + 1]; + char lastRecStamp[MAXTIMESTAMPLEN + 1]; + char heartbeatStamp[MAXTIMESTAMPLEN + 1]; + TimestampTz timeout; + TimestampTz nowtime; + TimestampTz last_timestamp; + TimestampTz heartbeat; +} WalReplicationTimestampInfo; + +void WalReplicationTimestampToString(WalReplicationTimestampInfo *timeStampInfo); + /* * timestamp.c prototypes */