From a2b91178d90969eb36b6ab4b16cc4afd5c1455d4 Mon Sep 17 00:00:00 2001 From: zhaowenhao <545612025@qq.com> Date: Fri, 15 Jan 2021 17:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84time=20stamp=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/timestamp.cpp | 8 +++++ .../storage/replication/walreceiver.cpp | 32 +++++++------------ .../storage/replication/walsender.cpp | 19 ++++++----- src/include/utils/timestamp.h | 18 +++++++++++ 4 files changed, 47 insertions(+), 30 deletions(-) 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 fe48771b8..c12ba9ee1 100755 --- a/src/gausskernel/storage/replication/walreceiver.cpp +++ b/src/gausskernel/storage/replication/walreceiver.cpp @@ -703,19 +703,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; @@ -723,19 +721,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 f5d05a876..6e8741c4d 100755 --- a/src/gausskernel/storage/replication/walsender.cpp +++ b/src/gausskernel/storage/replication/walsender.cpp @@ -3338,17 +3338,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 */