repmgrd: avoid additional connection to local instance in do_master_failover()

This commit is contained in:
Ian Barwick
2016-05-11 09:52:02 +09:00
parent 7fd44a3d74
commit 54d3c7a4ca

View File

@@ -1423,9 +1423,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
@@ -1480,6 +1477,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);
@@ -1555,6 +1556,7 @@ do_master_failover(void)
{
PGconn *new_master_conn;
PQExpBufferData event_details;
int master_node_id;
initPQExpBuffer(&event_details);
@@ -1565,28 +1567,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"),
@@ -1601,6 +1598,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);