mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16:29 +00:00
Merge pull request #133 from martinmarques/fix-standby-follows-other-node-repmgrd-fails
Fix standby follows other node repmgrd fails
This commit is contained in:
41
repmgrd.c
41
repmgrd.c
@@ -657,7 +657,6 @@ standby_monitor(void)
|
|||||||
char last_wal_standby_received[MAXLEN];
|
char last_wal_standby_received[MAXLEN];
|
||||||
char last_wal_standby_applied[MAXLEN];
|
char last_wal_standby_applied[MAXLEN];
|
||||||
char last_wal_standby_applied_timestamp[MAXLEN];
|
char last_wal_standby_applied_timestamp[MAXLEN];
|
||||||
bool last_wal_standby_received_gte_applied;
|
|
||||||
char sqlquery[QUERY_STR_LEN];
|
char sqlquery[QUERY_STR_LEN];
|
||||||
|
|
||||||
XLogRecPtr lsn_master;
|
XLogRecPtr lsn_master;
|
||||||
@@ -946,8 +945,7 @@ standby_monitor(void)
|
|||||||
/* Get local xlog info */
|
/* Get local xlog info */
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), "
|
"SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), "
|
||||||
"pg_last_xlog_replay_location(), pg_last_xact_replay_timestamp(), "
|
"pg_last_xlog_replay_location(), pg_last_xact_replay_timestamp()");
|
||||||
"pg_last_xlog_receive_location() >= pg_last_xlog_replay_location()");
|
|
||||||
|
|
||||||
res = PQexec(my_local_conn, sqlquery);
|
res = PQexec(my_local_conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
@@ -963,45 +961,8 @@ standby_monitor(void)
|
|||||||
strncpy(last_wal_standby_applied, PQgetvalue(res, 0, 2), MAXLEN);
|
strncpy(last_wal_standby_applied, PQgetvalue(res, 0, 2), MAXLEN);
|
||||||
strncpy(last_wal_standby_applied_timestamp, PQgetvalue(res, 0, 3), MAXLEN);
|
strncpy(last_wal_standby_applied_timestamp, PQgetvalue(res, 0, 3), MAXLEN);
|
||||||
|
|
||||||
last_wal_standby_received_gte_applied = (strcmp(PQgetvalue(res, 0, 4), "t") == 0)
|
|
||||||
? true
|
|
||||||
: false;
|
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
/*
|
|
||||||
* Check that last WAL received is greater or equal to last WAL applied
|
|
||||||
*
|
|
||||||
* This situation can occur when the standby is no longer connected to
|
|
||||||
* the upstream node; in this case repmgrd should terminate itself
|
|
||||||
* as the node may no longer be capable of being promoted or following
|
|
||||||
* a new upstream node
|
|
||||||
*
|
|
||||||
* XXX check if we should (optionally) adopt other strategies to handle
|
|
||||||
* this situation
|
|
||||||
*/
|
|
||||||
if(last_wal_standby_received_gte_applied == false)
|
|
||||||
{
|
|
||||||
PQExpBufferData errmsg;
|
|
||||||
initPQExpBuffer(&errmsg);
|
|
||||||
|
|
||||||
appendPQExpBuffer(&errmsg,
|
|
||||||
/* XXX improve message */
|
|
||||||
_("This node is no longer connected to its upstream node - terminating"));
|
|
||||||
|
|
||||||
log_crit("%s\n", errmsg.data);
|
|
||||||
|
|
||||||
create_event_record(master_conn,
|
|
||||||
&local_options,
|
|
||||||
local_options.node,
|
|
||||||
"repmgrd_monitor",
|
|
||||||
false,
|
|
||||||
errmsg.data);
|
|
||||||
|
|
||||||
// XXX use better code
|
|
||||||
terminate(ERR_MONITORING_FAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Get master xlog info */
|
/* Get master xlog info */
|
||||||
sqlquery_snprintf(sqlquery, "SELECT pg_catalog.pg_current_xlog_location()");
|
sqlquery_snprintf(sqlquery, "SELECT pg_catalog.pg_current_xlog_location()");
|
||||||
|
|||||||
Reference in New Issue
Block a user