mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Change return type of is_downstream_node_attached() from bool to NodeAttached
This enables us to better determine whether a node is definitively attached, definitively not attached, or if it was not possible to determine the attached state.
This commit is contained in:
13
dbutils.c
13
dbutils.c
@@ -5287,7 +5287,7 @@ get_node_replication_stats(PGconn *conn, t_node_info *node_info)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
NodeAttached
|
||||
is_downstream_node_attached(PGconn *conn, char *node_name)
|
||||
{
|
||||
PQExpBufferData query;
|
||||
@@ -5297,7 +5297,8 @@ is_downstream_node_attached(PGconn *conn, char *node_name)
|
||||
initPQExpBuffer(&query);
|
||||
|
||||
appendPQExpBuffer(&query,
|
||||
" SELECT pg_catalog.count(*) FROM pg_catalog.pg_stat_replication "
|
||||
" SELECT pg_catalog.count(*) "
|
||||
" FROM pg_catalog.pg_stat_replication "
|
||||
" WHERE application_name = '%s'",
|
||||
node_name);
|
||||
|
||||
@@ -5312,7 +5313,7 @@ is_downstream_node_attached(PGconn *conn, char *node_name)
|
||||
termPQExpBuffer(&query);
|
||||
PQclear(res);
|
||||
|
||||
return false;
|
||||
return NODE_ATTACHED_UNKNOWN;
|
||||
}
|
||||
|
||||
if (PQntuples(res) != 1)
|
||||
@@ -5322,7 +5323,7 @@ is_downstream_node_attached(PGconn *conn, char *node_name)
|
||||
termPQExpBuffer(&query);
|
||||
PQclear(res);
|
||||
|
||||
return false;
|
||||
return NODE_ATTACHED_UNKNOWN;
|
||||
}
|
||||
|
||||
c = atoi(PQgetvalue(res, 0, 0));
|
||||
@@ -5334,14 +5335,14 @@ is_downstream_node_attached(PGconn *conn, char *node_name)
|
||||
{
|
||||
log_verbose(LOG_WARNING, _("node \"%s\" not found in \"pg_stat_replication\""), node_name);
|
||||
|
||||
return false;
|
||||
return NODE_DETACHED;
|
||||
}
|
||||
|
||||
if (c > 1)
|
||||
log_verbose(LOG_WARNING, _("multiple entries with \"application_name\" set to \"%s\" found in \"pg_stat_replication\""),
|
||||
node_name);
|
||||
|
||||
return true;
|
||||
return NODE_ATTACHED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ typedef enum
|
||||
} BackupState;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Struct to store extension version information
|
||||
*/
|
||||
@@ -574,7 +575,7 @@ void init_replication_info(ReplInfo *replication_info);
|
||||
bool get_replication_info(PGconn *conn, t_server_type node_type, ReplInfo *replication_info);
|
||||
int get_replication_lag_seconds(PGconn *conn);
|
||||
void get_node_replication_stats(PGconn *conn, t_node_info *node_info);
|
||||
bool is_downstream_node_attached(PGconn *conn, char *node_name);
|
||||
NodeAttached is_downstream_node_attached(PGconn *conn, char *node_name);
|
||||
void set_upstream_last_seen(PGconn *conn, int upstream_node_id);
|
||||
int get_upstream_last_seen(PGconn *conn, t_server_type node_type);
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ do_node_status(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_downstream_node_attached(conn, node_cell->node_info->node_name) == false)
|
||||
if (is_downstream_node_attached(conn, node_cell->node_info->node_name) != NODE_ATTACHED)
|
||||
{
|
||||
missing_nodes_count++;
|
||||
item_list_append_format(&missing_nodes,
|
||||
@@ -1166,7 +1166,7 @@ do_node_check_downstream(PGconn *conn, OutputMode mode, CheckStatusList *list_ou
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_downstream_node_attached(conn, cell->node_info->node_name) == false)
|
||||
if (is_downstream_node_attached(conn, cell->node_info->node_name) != NODE_ATTACHED)
|
||||
{
|
||||
missing_nodes_count++;
|
||||
item_list_append_format(&missing_nodes,
|
||||
@@ -2562,9 +2562,10 @@ do_node_rejoin(void)
|
||||
|
||||
for (; i < config_file_options.node_rejoin_timeout; i++)
|
||||
{
|
||||
success = is_downstream_node_attached(primary_conn, config_file_options.node_name);
|
||||
NodeStatus node_attached = is_downstream_node_attached(primary_conn,
|
||||
config_file_options.node_name);
|
||||
|
||||
if (success == true)
|
||||
if (node_attached == NODE_ATTACHED)
|
||||
{
|
||||
log_verbose(LOG_INFO, _("node %i has attached to its upstream node"),
|
||||
config_file_options.node_id);
|
||||
@@ -2612,7 +2613,9 @@ do_node_rejoin(void)
|
||||
else
|
||||
{
|
||||
/* -W/--no-wait provided - check once */
|
||||
success = is_downstream_node_attached(primary_conn, config_file_options.node_name);
|
||||
NodeStatus node_attached = is_downstream_node_attached(primary_conn, config_file_options.node_name);
|
||||
if (node_attached == NODE_ATTACHED)
|
||||
success = true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1620,7 +1620,7 @@ do_standby_register(void)
|
||||
else
|
||||
{
|
||||
/* check our standby is connected */
|
||||
if (is_downstream_node_attached(upstream_conn, config_file_options.node_name) == true)
|
||||
if (is_downstream_node_attached(upstream_conn, config_file_options.node_name) == NODE_ATTACHED)
|
||||
{
|
||||
log_verbose(LOG_INFO, _("local node is attached to specified upstream node %i"), runtime_options.upstream_node_id);
|
||||
}
|
||||
@@ -1679,7 +1679,7 @@ do_standby_register(void)
|
||||
primary_node_id);
|
||||
|
||||
/* check our standby is connected */
|
||||
if (is_downstream_node_attached(primary_conn, config_file_options.node_name) == true)
|
||||
if (is_downstream_node_attached(primary_conn, config_file_options.node_name) == NODE_ATTACHED)
|
||||
{
|
||||
log_verbose(LOG_INFO, _("local node is attached to primary"));
|
||||
}
|
||||
@@ -2858,9 +2858,13 @@ do_standby_follow(void)
|
||||
|
||||
for (timer = 0; timer < config_file_options.standby_follow_timeout; timer++)
|
||||
{
|
||||
success = is_downstream_node_attached(follow_target_conn, config_file_options.node_name);
|
||||
if (success == true)
|
||||
NodeAttached node_attached = is_downstream_node_attached(follow_target_conn, config_file_options.node_name);
|
||||
|
||||
if (node_attached == NODE_ATTACHED)
|
||||
{
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
log_verbose(LOG_DEBUG, "sleeping %i of max %i seconds waiting for standby to attach to primary",
|
||||
timer + 1,
|
||||
@@ -3411,7 +3415,7 @@ do_standby_switchover(void)
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
if (is_downstream_node_attached(remote_conn, local_node_record.node_name) == false)
|
||||
if (is_downstream_node_attached(remote_conn, local_node_record.node_name) != NODE_ATTACHED)
|
||||
{
|
||||
log_error(_("local node \"%s\" (ID: %i) is not attached to demotion candidate \"%s\" (ID: %i)"),
|
||||
local_node_record.node_name,
|
||||
|
||||
Reference in New Issue
Block a user