mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Don't follow the promotion candidate standby if the primary reappears
This commit is contained in:
33
repmgrd.c
33
repmgrd.c
@@ -1486,8 +1486,6 @@ do_master_failover(void)
|
||||
r = system(local_options.promote_command);
|
||||
if (r != 0)
|
||||
{
|
||||
int master_node_id;
|
||||
|
||||
/*
|
||||
* Check whether the primary reappeared, which will have caused the
|
||||
* promote command to fail
|
||||
@@ -1496,6 +1494,8 @@ do_master_failover(void)
|
||||
|
||||
if (my_local_conn != NULL)
|
||||
{
|
||||
int master_node_id;
|
||||
|
||||
master_conn = get_master_connection(my_local_conn,
|
||||
local_options.cluster_name,
|
||||
&master_node_id, NULL);
|
||||
@@ -1546,9 +1546,38 @@ do_master_failover(void)
|
||||
PQExpBufferData event_details;
|
||||
|
||||
initPQExpBuffer(&event_details);
|
||||
|
||||
/* wait */
|
||||
sleep(10);
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
int master_node_id;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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"),
|
||||
best_candidate.node_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user