mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16:29 +00:00
Consolidate connection closure calls
This commit is contained in:
@@ -142,7 +142,7 @@ do_physical_node_check(void)
|
||||
case FAILOVER_AUTOMATIC:
|
||||
log_error(_("this node is marked as inactive and cannot be used as a failover target"));
|
||||
log_hint(_("%s"), hint);
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
|
||||
create_event_notification(NULL,
|
||||
&config_file_options,
|
||||
@@ -193,7 +193,7 @@ do_physical_node_check(void)
|
||||
if (required_param_missing == true)
|
||||
{
|
||||
log_hint(_("add the missing configuration parameter(s) and start repmgrd again"));
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
}
|
||||
@@ -275,7 +275,7 @@ monitor_streaming_primary(void)
|
||||
|
||||
local_node_info.node_status = NODE_STATUS_UNKNOWN;
|
||||
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
|
||||
/*
|
||||
* as we're monitoring the primary, no point in trying to
|
||||
@@ -358,7 +358,7 @@ monitor_streaming_primary(void)
|
||||
if (PQstatus(local_conn) != CONNECTION_OK)
|
||||
{
|
||||
log_warning(_("node appears to be up but no connection could be made"));
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -384,7 +384,7 @@ monitor_streaming_primary(void)
|
||||
|
||||
if (PQstatus(new_primary_conn) != CONNECTION_OK)
|
||||
{
|
||||
PQfinish(new_primary_conn);
|
||||
close_connection(&new_primary_conn);
|
||||
log_warning(_("unable to connect to new primary node %i"), primary_node_id);
|
||||
}
|
||||
else
|
||||
@@ -444,7 +444,7 @@ monitor_streaming_primary(void)
|
||||
log_notice("%s", event_details.data);
|
||||
termPQExpBuffer(&event_details);
|
||||
|
||||
PQfinish(new_primary_conn);
|
||||
close_connection(&new_primary_conn);
|
||||
|
||||
/* restart monitoring as standby */
|
||||
return;
|
||||
@@ -462,7 +462,7 @@ monitor_streaming_primary(void)
|
||||
log_error("%s", event_details.data);
|
||||
log_hint(_("check that 'repmgr (primary|standby) register' was executed for this node"));
|
||||
|
||||
PQfinish(new_primary_conn);
|
||||
close_connection(&new_primary_conn);
|
||||
|
||||
create_event_notification(NULL,
|
||||
&config_file_options,
|
||||
@@ -533,7 +533,7 @@ loop:
|
||||
|
||||
if (reload_config(&config_file_options))
|
||||
{
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
local_conn = establish_db_connection(config_file_options.conninfo, true);
|
||||
|
||||
if (*config_file_options.log_file)
|
||||
@@ -588,7 +588,7 @@ monitor_streaming_standby(void)
|
||||
if (local_node_info.upstream_node_id == NODE_NOT_FOUND)
|
||||
{
|
||||
log_error(_("unable to determine an active primary for this cluster, terminating"));
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
}
|
||||
@@ -605,14 +605,14 @@ monitor_streaming_standby(void)
|
||||
log_error(_("no record found for upstream node (ID: %i), terminating"),
|
||||
local_node_info.upstream_node_id);
|
||||
log_hint(_("ensure the upstream node is registered correctly"));
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
exit(ERR_DB_CONN);
|
||||
}
|
||||
else if (record_status == RECORD_ERROR)
|
||||
{
|
||||
log_error(_("unable to retrieve record for upstream node (ID: %i), terminating"),
|
||||
local_node_info.upstream_node_id);
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
exit(ERR_DB_CONN);
|
||||
}
|
||||
|
||||
@@ -632,7 +632,7 @@ monitor_streaming_standby(void)
|
||||
local_node_info.upstream_node_id);
|
||||
log_hint(_("upstream node must be running before repmgrd can start"));
|
||||
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
exit(ERR_DB_CONN);
|
||||
}
|
||||
|
||||
@@ -742,7 +742,7 @@ monitor_streaming_standby(void)
|
||||
log_warning("%s", event_details.data);
|
||||
termPQExpBuffer(&event_details);
|
||||
|
||||
PQfinish(upstream_conn);
|
||||
close_connection(&upstream_conn);
|
||||
upstream_conn = try_reconnect(&upstream_node_info);
|
||||
|
||||
/* Node has recovered - log and continue */
|
||||
@@ -923,12 +923,10 @@ monitor_streaming_standby(void)
|
||||
if (get_recovery_type(cell->node_info->conn) == RECTYPE_PRIMARY)
|
||||
{
|
||||
follow_node_id = cell->node_info->node_id;
|
||||
PQfinish(cell->node_info->conn);
|
||||
cell->node_info->conn = NULL;
|
||||
close_connection(&cell->node_info->conn);
|
||||
break;
|
||||
}
|
||||
PQfinish(cell->node_info->conn);
|
||||
cell->node_info->conn = NULL;
|
||||
close_connection(&cell->node_info->conn);
|
||||
}
|
||||
|
||||
if (follow_node_id != UNKNOWN_NODE_ID)
|
||||
@@ -1068,7 +1066,7 @@ loop:
|
||||
|
||||
if (reload_config(&config_file_options))
|
||||
{
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
local_conn = establish_db_connection(config_file_options.conninfo, true);
|
||||
|
||||
if (*config_file_options.log_file)
|
||||
@@ -1118,7 +1116,7 @@ monitor_streaming_witness(void)
|
||||
|
||||
log_error("%s", event_details.data);
|
||||
log_hint(_("execute \"repmgr witness register --force\" to update the witness node "));
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
|
||||
create_event_notification(NULL,
|
||||
&config_file_options,
|
||||
@@ -1146,7 +1144,7 @@ monitor_streaming_witness(void)
|
||||
upstream_node_info.node_id);
|
||||
log_hint(_("primary node must be running before repmgrd can start"));
|
||||
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
exit(ERR_DB_CONN);
|
||||
}
|
||||
|
||||
@@ -1229,7 +1227,7 @@ monitor_streaming_witness(void)
|
||||
true,
|
||||
event_details.data);
|
||||
|
||||
PQfinish(primary_conn);
|
||||
close_connection(&primary_conn);
|
||||
primary_conn = try_reconnect(&upstream_node_info);
|
||||
|
||||
/* Node has recovered - log and continue */
|
||||
@@ -1351,12 +1349,10 @@ monitor_streaming_witness(void)
|
||||
if (get_recovery_type(cell->node_info->conn) == RECTYPE_PRIMARY)
|
||||
{
|
||||
follow_node_id = cell->node_info->node_id;
|
||||
PQfinish(cell->node_info->conn);
|
||||
cell->node_info->conn = NULL;
|
||||
close_connection(&cell->node_info->conn);
|
||||
break;
|
||||
}
|
||||
PQfinish(cell->node_info->conn);
|
||||
cell->node_info->conn = NULL;
|
||||
close_connection(&cell->node_info->conn);
|
||||
}
|
||||
|
||||
if (follow_node_id != UNKNOWN_NODE_ID)
|
||||
@@ -1418,7 +1414,7 @@ loop:
|
||||
|
||||
if (reload_config(&config_file_options))
|
||||
{
|
||||
PQfinish(local_conn);
|
||||
close_connection(&local_conn);
|
||||
local_conn = establish_db_connection(config_file_options.conninfo, true);
|
||||
|
||||
if (*config_file_options.log_file)
|
||||
@@ -1548,7 +1544,7 @@ do_primary_failover(void)
|
||||
*/
|
||||
true,
|
||||
event_details.data);
|
||||
PQfinish(new_primary_conn);
|
||||
close_connection(&new_primary_conn);
|
||||
termPQExpBuffer(&event_details);
|
||||
|
||||
}
|
||||
@@ -1767,8 +1763,7 @@ do_upstream_standby_failover(void)
|
||||
int i, r;
|
||||
char parsed_follow_command[MAXPGPATH] = "";
|
||||
|
||||
PQfinish(upstream_conn);
|
||||
upstream_conn = NULL;
|
||||
close_connection(&upstream_conn);
|
||||
|
||||
if (get_primary_node_record(local_conn, &primary_node_info) == false)
|
||||
{
|
||||
@@ -1789,7 +1784,7 @@ do_upstream_standby_failover(void)
|
||||
primary_node_info.node_name,
|
||||
primary_node_info.node_id);
|
||||
|
||||
PQfinish(primary_conn);
|
||||
close_connection(&primary_conn);
|
||||
monitoring_state = MS_DEGRADED;
|
||||
INSTR_TIME_SET_CURRENT(degraded_monitoring_start);
|
||||
return false;
|
||||
@@ -1803,15 +1798,14 @@ do_upstream_standby_failover(void)
|
||||
primary_node_info.node_name,
|
||||
primary_node_info.node_id);
|
||||
|
||||
PQfinish(primary_conn);
|
||||
close_connection(&primary_conn);
|
||||
monitoring_state = MS_DEGRADED;
|
||||
INSTR_TIME_SET_CURRENT(degraded_monitoring_start);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Close the connection to this server */
|
||||
PQfinish(local_conn);
|
||||
local_conn = NULL;
|
||||
close_connection(&local_conn);
|
||||
|
||||
initPQExpBuffer(&event_details);
|
||||
|
||||
@@ -2199,7 +2193,7 @@ follow_new_primary(int new_primary_id)
|
||||
{
|
||||
new_primary_ok = false;
|
||||
log_warning(_("new primary is not in recovery"));
|
||||
PQfinish(upstream_conn);
|
||||
close_connection(&upstream_conn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2213,8 +2207,7 @@ follow_new_primary(int new_primary_id)
|
||||
* restart
|
||||
*/
|
||||
|
||||
PQfinish(local_conn);
|
||||
local_conn = NULL;
|
||||
close_connection(&local_conn);
|
||||
|
||||
/*
|
||||
* replace %n in "config_file_options.follow_command" with ID of primary
|
||||
@@ -2246,7 +2239,6 @@ follow_new_primary(int new_primary_id)
|
||||
|
||||
if (PQstatus(old_primary_conn) == CONNECTION_OK)
|
||||
{
|
||||
/* XXX add event notifications */
|
||||
RecoveryType upstream_recovery_type = get_recovery_type(old_primary_conn);
|
||||
|
||||
if (upstream_recovery_type == RECTYPE_PRIMARY)
|
||||
@@ -2266,14 +2258,14 @@ follow_new_primary(int new_primary_id)
|
||||
|
||||
termPQExpBuffer(&event_details);
|
||||
|
||||
PQfinish(old_primary_conn);
|
||||
close_connection(&old_primary_conn);
|
||||
|
||||
return FAILOVER_STATE_PRIMARY_REAPPEARED;
|
||||
}
|
||||
|
||||
log_notice(_("original primary reappeared as standby"));
|
||||
|
||||
PQfinish(old_primary_conn);
|
||||
close_connection(&old_primary_conn);
|
||||
}
|
||||
|
||||
return FAILOVER_STATE_FOLLOW_FAIL;
|
||||
@@ -2389,7 +2381,7 @@ witness_follow_new_primary(int new_primary_id)
|
||||
{
|
||||
new_primary_ok = false;
|
||||
log_warning(_("new primary is not in recovery"));
|
||||
PQfinish(upstream_conn);
|
||||
close_connection(&upstream_conn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2874,15 +2866,12 @@ close_connections_physical()
|
||||
{
|
||||
/* cancel any pending queries to the primary */
|
||||
if (PQisBusy(primary_conn) == 1)
|
||||
{
|
||||
log_debug("cancelling query on primary");
|
||||
cancel_query(primary_conn, config_file_options.async_query_timeout);
|
||||
PQfinish(primary_conn);
|
||||
primary_conn = NULL;
|
||||
}
|
||||
|
||||
if (upstream_conn != NULL && PQstatus(upstream_conn) == CONNECTION_OK)
|
||||
{
|
||||
PQfinish(upstream_conn);
|
||||
upstream_conn = NULL;
|
||||
}
|
||||
close_connection(&primary_conn);
|
||||
}
|
||||
|
||||
close_connection(&upstream_conn);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user