!632 重构time stamp相关代码实现

Merge pull request !632 from 赵文浩/master
This commit is contained in:
opengauss-bot
2021-02-08 16:48:36 +08:00
committed by Gitee
4 changed files with 47 additions and 30 deletions

View File

@ -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);
}

View File

@ -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)));
}
}
}

View File

@ -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();
}

View File

@ -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
*/