mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
repmgrd: set primary last seen
This commit is contained in:
53
dbutils.c
53
dbutils.c
@@ -3168,6 +3168,59 @@ is_downstream_node_attached(PGconn *conn, char *node_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
set_primary_last_seen(PGconn *conn)
|
||||
{
|
||||
PQExpBufferData query;
|
||||
PGresult *res = NULL;
|
||||
|
||||
initPQExpBuffer(&query);
|
||||
|
||||
appendPQExpBufferStr(&query,
|
||||
"SELECT repmgr.set_primary_last_seen()");
|
||||
|
||||
res = PQexec(conn, query.data);
|
||||
|
||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
log_db_error(conn, query.data, _("unable to execute repmgr.set_primary_last_seen()"));
|
||||
}
|
||||
|
||||
termPQExpBuffer(&query);
|
||||
PQclear(res);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
get_primary_last_seen(PGconn *conn)
|
||||
{
|
||||
PQExpBufferData query;
|
||||
PGresult *res = NULL;
|
||||
int primary_last_seen = -1;
|
||||
|
||||
initPQExpBuffer(&query);
|
||||
|
||||
appendPQExpBufferStr(&query,
|
||||
"SELECT repmgr.get_primary_last_seen()");
|
||||
|
||||
res = PQexec(conn, query.data);
|
||||
|
||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
log_db_error(conn, query.data, _("unable to execute repmgr.get_primary_last_seen()"));
|
||||
}
|
||||
else
|
||||
{
|
||||
primary_last_seen = atoi(PQgetvalue(res, 0, 0));
|
||||
}
|
||||
|
||||
termPQExpBuffer(&query);
|
||||
PQclear(res);
|
||||
|
||||
return primary_last_seen;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
clear_node_info_list(NodeInfoList *nodes)
|
||||
{
|
||||
|
||||
@@ -545,6 +545,8 @@ bool get_replication_info(PGconn *conn, ReplInfo *replication_info);
|
||||
int get_replication_lag_seconds(PGconn *conn);
|
||||
void get_node_replication_stats(PGconn *conn, int server_version_num, t_node_info *node_info);
|
||||
bool is_downstream_node_attached(PGconn *conn, char *node_name);
|
||||
void set_primary_last_seen(PGconn *conn);
|
||||
int get_primary_last_seen(PGconn *conn);
|
||||
|
||||
/* BDR functions */
|
||||
int get_bdr_version_num(void);
|
||||
|
||||
@@ -805,7 +805,11 @@ monitor_streaming_standby(void)
|
||||
while (true)
|
||||
{
|
||||
log_verbose(LOG_DEBUG, "checking %s", upstream_node_info.conninfo);
|
||||
if (is_server_available(upstream_node_info.conninfo) == false)
|
||||
if (is_server_available(upstream_node_info.conninfo) == true)
|
||||
{
|
||||
set_primary_last_seen(local_conn);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* upstream node is down, we were expecting it to be up */
|
||||
if (upstream_node_info.node_status == NODE_STATUS_UP)
|
||||
@@ -1266,7 +1270,6 @@ loop:
|
||||
|
||||
check_connection(&local_node_info, &local_conn);
|
||||
|
||||
|
||||
if (PQstatus(local_conn) != CONNECTION_OK)
|
||||
{
|
||||
if (local_node_info.active == true)
|
||||
|
||||
Reference in New Issue
Block a user