mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
repmgrd: avoid additional connection to local instance in do_master_failover()
This commit is contained in:
42
repmgrd.c
42
repmgrd.c
@@ -1412,9 +1412,6 @@ do_master_failover(void)
|
||||
PQfinish(node_conn);
|
||||
}
|
||||
|
||||
/* Close the connection to this server */
|
||||
PQfinish(my_local_conn);
|
||||
my_local_conn = NULL;
|
||||
|
||||
/*
|
||||
* determine which one is the best candidate to promote to master
|
||||
@@ -1469,6 +1466,10 @@ do_master_failover(void)
|
||||
{
|
||||
PQExpBufferData event_details;
|
||||
|
||||
/* Close the connection to this server */
|
||||
PQfinish(my_local_conn);
|
||||
my_local_conn = NULL;
|
||||
|
||||
initPQExpBuffer(&event_details);
|
||||
/* wait */
|
||||
sleep(5);
|
||||
@@ -1544,6 +1545,7 @@ do_master_failover(void)
|
||||
{
|
||||
PGconn *new_master_conn;
|
||||
PQExpBufferData event_details;
|
||||
int master_node_id;
|
||||
|
||||
initPQExpBuffer(&event_details);
|
||||
|
||||
@@ -1554,28 +1556,23 @@ do_master_failover(void)
|
||||
* Check whether the primary reappeared while we were waiting, so we
|
||||
* don't end up following the promotion candidate
|
||||
*/
|
||||
my_local_conn = establish_db_connection(local_options.conninfo, false);
|
||||
if (my_local_conn != NULL)
|
||||
|
||||
master_conn = get_master_connection(my_local_conn,
|
||||
local_options.cluster_name,
|
||||
&master_node_id, NULL);
|
||||
|
||||
if (master_conn != NULL && master_node_id == failed_master.node_id)
|
||||
{
|
||||
int master_node_id;
|
||||
log_notice(_("Original master reappeared - no action taken\n"));
|
||||
|
||||
master_conn = get_master_connection(my_local_conn,
|
||||
local_options.cluster_name,
|
||||
&master_node_id, NULL);
|
||||
|
||||
if (master_conn != NULL && master_node_id == failed_master.node_id)
|
||||
{
|
||||
log_notice(_("Original master reappeared - no action taken\n"));
|
||||
|
||||
PQfinish(master_conn);
|
||||
/* no failover occurred but we'll want to restart connections */
|
||||
failover_done = true;
|
||||
return;
|
||||
}
|
||||
|
||||
PQfinish(my_local_conn);
|
||||
PQfinish(master_conn);
|
||||
/* no failover occurred but we'll want to restart connections */
|
||||
failover_done = true;
|
||||
return;
|
||||
}
|
||||
|
||||
PQfinish(my_local_conn);
|
||||
|
||||
/* XXX double-check the promotion candidate did become the new primary */
|
||||
|
||||
log_notice(_("node %d is the best candidate for new master, attempting to follow...\n"),
|
||||
@@ -1590,6 +1587,9 @@ do_master_failover(void)
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
/* Close the connection to this server */
|
||||
PQfinish(my_local_conn);
|
||||
my_local_conn = NULL;
|
||||
|
||||
log_debug(_("executing follow command: \"%s\"\n"), local_options.follow_command);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user