mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
monitoring: ensure that invalid replication_lag value is not inserted.
Per Github #189.
This commit is contained in:
32
repmgrd.c
32
repmgrd.c
@@ -706,6 +706,9 @@ standby_monitor(void)
|
|||||||
XLogRecPtr lsn_last_xlog_receive_location;
|
XLogRecPtr lsn_last_xlog_receive_location;
|
||||||
XLogRecPtr lsn_last_xlog_replay_location;
|
XLogRecPtr lsn_last_xlog_replay_location;
|
||||||
|
|
||||||
|
long long unsigned int replication_lag;
|
||||||
|
long long unsigned int apply_lag;
|
||||||
|
|
||||||
int connection_retries,
|
int connection_retries,
|
||||||
ret;
|
ret;
|
||||||
bool did_retry = false;
|
bool did_retry = false;
|
||||||
@@ -1051,24 +1054,39 @@ standby_monitor(void)
|
|||||||
strncpy(last_wal_primary_location, PQgetvalue(res, 0, 0), MAXLEN);
|
strncpy(last_wal_primary_location, PQgetvalue(res, 0, 0), MAXLEN);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
/* Calculate the lag */
|
|
||||||
lsn_master_current_xlog_location = lsn_to_xlogrecptr(last_wal_primary_location, NULL);
|
lsn_master_current_xlog_location = lsn_to_xlogrecptr(last_wal_primary_location, NULL);
|
||||||
|
|
||||||
lsn_last_xlog_replay_location = lsn_to_xlogrecptr(last_xlog_replay_location, NULL);
|
lsn_last_xlog_replay_location = lsn_to_xlogrecptr(last_xlog_replay_location, NULL);
|
||||||
|
lsn_last_xlog_receive_location = lsn_to_xlogrecptr(last_xlog_receive_location, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/* Calculate apply lag */
|
||||||
if (last_xlog_receive_location_gte_replayed == false)
|
if (last_xlog_receive_location_gte_replayed == false)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We're not receiving streaming WAL - in this case the receive location
|
* We're not receiving streaming WAL - in this case the receive location
|
||||||
* equals the last replayed location
|
* equals the last replayed location
|
||||||
*/
|
*/
|
||||||
|
apply_lag = 0;
|
||||||
lsn_last_xlog_receive_location = lsn_last_xlog_replay_location;
|
|
||||||
strncpy(last_xlog_receive_location, last_xlog_replay_location, MAXLEN);
|
strncpy(last_xlog_receive_location, last_xlog_replay_location, MAXLEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lsn_last_xlog_receive_location = lsn_to_xlogrecptr(last_xlog_receive_location, NULL);
|
apply_lag = (long long unsigned int)lsn_last_xlog_receive_location - lsn_last_xlog_replay_location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate replication lag */
|
||||||
|
if (lsn_master_current_xlog_location >= lsn_last_xlog_receive_location)
|
||||||
|
{
|
||||||
|
replication_lag = (long long unsigned int)(lsn_master_current_xlog_location - lsn_last_xlog_receive_location);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* This should never happen, but in case it does set lag to zero */
|
||||||
|
log_warning("Master xlog (%s) location appears less than standby receive location (%s)\n",
|
||||||
|
last_wal_primary_location,
|
||||||
|
last_xlog_receive_location);
|
||||||
|
replication_lag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1099,8 +1117,8 @@ standby_monitor(void)
|
|||||||
last_xact_replay_timestamp,
|
last_xact_replay_timestamp,
|
||||||
last_wal_primary_location,
|
last_wal_primary_location,
|
||||||
last_xlog_receive_location,
|
last_xlog_receive_location,
|
||||||
(long long unsigned int)(lsn_master_current_xlog_location - lsn_last_xlog_receive_location),
|
replication_lag,
|
||||||
(long long unsigned int)(lsn_last_xlog_receive_location - lsn_last_xlog_replay_location));
|
apply_lag);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Execute the query asynchronously, but don't check for a result. We will
|
* Execute the query asynchronously, but don't check for a result. We will
|
||||||
|
|||||||
Reference in New Issue
Block a user