mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Ensure witness node sets last upstream seen time
This commit is contained in:
20
dbutils.c
20
dbutils.c
@@ -5195,7 +5195,7 @@ set_upstream_last_seen(PGconn *conn)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
get_upstream_last_seen(PGconn *conn)
|
get_upstream_last_seen(PGconn *conn, t_server_type node_type)
|
||||||
{
|
{
|
||||||
PQExpBufferData query;
|
PQExpBufferData query;
|
||||||
PGresult *res = NULL;
|
PGresult *res = NULL;
|
||||||
@@ -5203,11 +5203,19 @@ get_upstream_last_seen(PGconn *conn)
|
|||||||
|
|
||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
appendPQExpBufferStr(&query,
|
if (node_type == WITNESS)
|
||||||
"SELECT CASE WHEN pg_catalog.pg_is_in_recovery() IS FALSE "
|
{
|
||||||
" THEN -1 "
|
appendPQExpBufferStr(&query,
|
||||||
" ELSE repmgr.get_upstream_last_seen() "
|
"SELECT repmgr.get_upstream_last_seen()");
|
||||||
" END AS upstream_last_seen ");
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
appendPQExpBufferStr(&query,
|
||||||
|
"SELECT CASE WHEN pg_catalog.pg_is_in_recovery() IS FALSE "
|
||||||
|
" THEN -1 "
|
||||||
|
" ELSE repmgr.get_upstream_last_seen() "
|
||||||
|
" END AS upstream_last_seen ");
|
||||||
|
}
|
||||||
|
|
||||||
res = PQexec(conn, query.data);
|
res = PQexec(conn, query.data);
|
||||||
|
|
||||||
|
|||||||
@@ -559,7 +559,7 @@ int get_replication_lag_seconds(PGconn *conn);
|
|||||||
void get_node_replication_stats(PGconn *conn, t_node_info *node_info);
|
void get_node_replication_stats(PGconn *conn, t_node_info *node_info);
|
||||||
bool is_downstream_node_attached(PGconn *conn, char *node_name);
|
bool is_downstream_node_attached(PGconn *conn, char *node_name);
|
||||||
void set_upstream_last_seen(PGconn *conn);
|
void set_upstream_last_seen(PGconn *conn);
|
||||||
int get_upstream_last_seen(PGconn *conn);
|
int get_upstream_last_seen(PGconn *conn, t_server_type node_type);
|
||||||
bool is_wal_replay_paused(PGconn *conn, bool check_pending_wal);
|
bool is_wal_replay_paused(PGconn *conn, bool check_pending_wal);
|
||||||
|
|
||||||
/* BDR functions */
|
/* BDR functions */
|
||||||
|
|||||||
@@ -201,8 +201,7 @@ do_daemon_status(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repmgrd_info[i]->upstream_last_seen = get_upstream_last_seen(cell->node_info->conn);
|
repmgrd_info[i]->upstream_last_seen = get_upstream_last_seen(cell->node_info->conn, cell->node_info->type);
|
||||||
|
|
||||||
if (repmgrd_info[i]->upstream_last_seen < 0)
|
if (repmgrd_info[i]->upstream_last_seen < 0)
|
||||||
{
|
{
|
||||||
maxlen_snprintf(repmgrd_info[i]->upstream_last_seen_text, "%s", _("n/a"));
|
maxlen_snprintf(repmgrd_info[i]->upstream_last_seen_text, "%s", _("n/a"));
|
||||||
|
|||||||
4
repmgr.c
4
repmgr.c
@@ -391,10 +391,6 @@ get_upstream_last_seen(PG_FUNCTION_ARGS)
|
|||||||
if (!shared_state)
|
if (!shared_state)
|
||||||
PG_RETURN_INT32(-1);
|
PG_RETURN_INT32(-1);
|
||||||
|
|
||||||
/* A primary is always visible */
|
|
||||||
if (!RecoveryInProgress())
|
|
||||||
PG_RETURN_INT32(0);
|
|
||||||
|
|
||||||
LWLockAcquire(shared_state->lock, LW_SHARED);
|
LWLockAcquire(shared_state->lock, LW_SHARED);
|
||||||
|
|
||||||
last_seen = shared_state->upstream_last_seen;
|
last_seen = shared_state->upstream_last_seen;
|
||||||
|
|||||||
@@ -1612,7 +1612,11 @@ monitor_streaming_witness(void)
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (check_upstream_connection(&upstream_conn, upstream_node_info.conninfo) == false)
|
if (check_upstream_connection(&primary_conn, upstream_node_info.conninfo) == true)
|
||||||
|
{
|
||||||
|
set_upstream_last_seen(local_conn);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (upstream_node_info.node_status == NODE_STATUS_UP)
|
if (upstream_node_info.node_status == NODE_STATUS_UP)
|
||||||
{
|
{
|
||||||
@@ -3440,6 +3444,7 @@ do_election(NodeInfoList *sibling_nodes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* don't interrogate a witness server */
|
/* don't interrogate a witness server */
|
||||||
if (cell->node_info->type == WITNESS)
|
if (cell->node_info->type == WITNESS)
|
||||||
{
|
{
|
||||||
@@ -3503,12 +3508,12 @@ do_election(NodeInfoList *sibling_nodes)
|
|||||||
* configurable.
|
* configurable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
if (sibling_replication_info.upstream_last_seen >= 0 && sibling_replication_info.upstream_last_seen < (config_file_options.monitor_interval_secs * 2))
|
if (sibling_replication_info.upstream_last_seen >= 0 && sibling_replication_info.upstream_last_seen < (config_file_options.monitor_interval_secs * 2))
|
||||||
{
|
{
|
||||||
nodes_with_primary_still_visible++;
|
nodes_with_primary_still_visible++;
|
||||||
log_notice(_("node %i last saw primary node %i second(s) ago, considering primary still visible"),
|
log_notice(_("node %i last saw primary node %i second(s) ago, considering primary still visible"),
|
||||||
cell->node_info->node_id, sibling_replication_info.upstream_last_seen);
|
cell->node_info->node_id,
|
||||||
|
sibling_replication_info.upstream_last_seen);
|
||||||
appendPQExpBuffer(&nodes_with_primary_visible,
|
appendPQExpBuffer(&nodes_with_primary_visible,
|
||||||
" - node \"%s\" (ID: %i): %i second(s) ago\n",
|
" - node \"%s\" (ID: %i): %i second(s) ago\n",
|
||||||
cell->node_info->node_name,
|
cell->node_info->node_name,
|
||||||
@@ -3518,8 +3523,10 @@ do_election(NodeInfoList *sibling_nodes)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_info(_("node %i last saw primary node %i second(s) ago"),
|
log_info(_("node %i last saw primary node %i second(s) ago"),
|
||||||
cell->node_info->node_id, sibling_replication_info.upstream_last_seen);
|
cell->node_info->node_id,
|
||||||
|
sibling_replication_info.upstream_last_seen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get node's last receive LSN - if "higher" than current winner, current node is candidate */
|
/* get node's last receive LSN - if "higher" than current winner, current node is candidate */
|
||||||
cell->node_info->last_wal_receive_lsn = sibling_replication_info.last_wal_receive_lsn;
|
cell->node_info->last_wal_receive_lsn = sibling_replication_info.last_wal_receive_lsn;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user