mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
repmgrd: handle manual failover mode correctly
This commit is contained in:
@@ -1995,7 +1995,8 @@ clear_node_info_list(NodeInfoList *nodes)
|
|||||||
/* close any open connections */
|
/* close any open connections */
|
||||||
for (cell = nodes->head; cell; cell = cell->next)
|
for (cell = nodes->head; cell; cell = cell->next)
|
||||||
{
|
{
|
||||||
if (cell->node_info->conn != NULL)
|
|
||||||
|
if (PQstatus(cell->node_info->conn) == CONNECTION_OK)
|
||||||
{
|
{
|
||||||
PQfinish(cell->node_info->conn);
|
PQfinish(cell->node_info->conn);
|
||||||
cell->node_info->conn = NULL;
|
cell->node_info->conn = NULL;
|
||||||
|
|||||||
@@ -682,12 +682,14 @@ monitor_streaming_standby(void)
|
|||||||
{
|
{
|
||||||
follow_node_id = cell->node_info->node_id;
|
follow_node_id = cell->node_info->node_id;
|
||||||
PQfinish(cell->node_info->conn);
|
PQfinish(cell->node_info->conn);
|
||||||
|
cell->node_info->conn = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PQfinish(cell->node_info->conn);
|
PQfinish(cell->node_info->conn);
|
||||||
|
cell->node_info->conn = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (follow_node_id != UNKNOWN_NODE_ID)
|
if (follow_node_id != UNKNOWN_NODE_ID && config_file_options.failover_mode == FAILOVER_AUTOMATIC)
|
||||||
{
|
{
|
||||||
follow_new_primary(follow_node_id);
|
follow_new_primary(follow_node_id);
|
||||||
}
|
}
|
||||||
@@ -705,13 +707,27 @@ monitor_streaming_standby(void)
|
|||||||
|
|
||||||
if (log_status_interval_elapsed >= config_file_options.log_status_interval)
|
if (log_status_interval_elapsed >= config_file_options.log_status_interval)
|
||||||
{
|
{
|
||||||
log_info(_("node \"%s\" (node ID: %i) monitoring upstream node \"%s\" (node ID: %i) in %s state"),
|
PQExpBufferData monitoring_summary;
|
||||||
|
initPQExpBuffer(&monitoring_summary);
|
||||||
|
|
||||||
|
appendPQExpBuffer(
|
||||||
|
&monitoring_summary,
|
||||||
|
_("node \"%s\" (node ID: %i) monitoring upstream node \"%s\" (node ID: %i) in %s state"),
|
||||||
local_node_info.node_name,
|
local_node_info.node_name,
|
||||||
local_node_info.node_id,
|
local_node_info.node_id,
|
||||||
upstream_node_info.node_name,
|
upstream_node_info.node_name,
|
||||||
upstream_node_info.node_id,
|
upstream_node_info.node_id,
|
||||||
print_monitoring_state(monitoring_state));
|
print_monitoring_state(monitoring_state));
|
||||||
|
|
||||||
|
if (config_file_options.failover_mode == FAILOVER_MANUAL)
|
||||||
|
{
|
||||||
|
appendPQExpBuffer(
|
||||||
|
&monitoring_summary,
|
||||||
|
_(" (automatic failover disabled)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info("%s", monitoring_summary.data);
|
||||||
|
termPQExpBuffer(&monitoring_summary);
|
||||||
if (monitoring_state == MS_DEGRADED)
|
if (monitoring_state == MS_DEGRADED)
|
||||||
{
|
{
|
||||||
log_detail(_("waiting for upstream or another primary to reappear"));
|
log_detail(_("waiting for upstream or another primary to reappear"));
|
||||||
@@ -835,7 +851,7 @@ do_primary_failover(void)
|
|||||||
*/
|
*/
|
||||||
if (standby_nodes.node_count == 0)
|
if (standby_nodes.node_count == 0)
|
||||||
{
|
{
|
||||||
log_notice(_("no other nodes are available as promotion candidated"));
|
log_notice(_("no other nodes are available as promotion candidate"));
|
||||||
log_hint(_("use \"repmgr standby promote\" to manually promote this node"));
|
log_hint(_("use \"repmgr standby promote\" to manually promote this node"));
|
||||||
|
|
||||||
monitoring_state = MS_DEGRADED;
|
monitoring_state = MS_DEGRADED;
|
||||||
@@ -1382,9 +1398,12 @@ wait_primary_notification(int *new_primary_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log_warning(_("no notifcation received from new primary after %i seconds"),
|
log_warning(_("no notification received from new primary after %i seconds"),
|
||||||
wait_primary_timeout);
|
wait_primary_timeout);
|
||||||
|
|
||||||
|
monitoring_state = MS_DEGRADED;
|
||||||
|
INSTR_TIME_SET_CURRENT(degraded_monitoring_start);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1584,7 +1603,10 @@ _print_election_result(ElectionResult result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NB: this function sets standby_nodes; caller (do_primary_failover)
|
||||||
|
* expects to be able to read this list
|
||||||
|
*/
|
||||||
static ElectionResult
|
static ElectionResult
|
||||||
do_election(void)
|
do_election(void)
|
||||||
{
|
{
|
||||||
@@ -1630,6 +1652,13 @@ do_election(void)
|
|||||||
upstream_node_info.node_id,
|
upstream_node_info.node_id,
|
||||||
&standby_nodes);
|
&standby_nodes);
|
||||||
|
|
||||||
|
if (config_file_options.failover_mode == FAILOVER_MANUAL)
|
||||||
|
{
|
||||||
|
log_notice(_("this node is not configured for automatic failure so will not be considered as promotion candidate"));
|
||||||
|
|
||||||
|
return ELECTION_NOT_CANDIDATE;
|
||||||
|
}
|
||||||
|
|
||||||
/* node priority is set to zero - don't ever become a candidate */
|
/* node priority is set to zero - don't ever become a candidate */
|
||||||
if (local_node_info.priority <= 0)
|
if (local_node_info.priority <= 0)
|
||||||
{
|
{
|
||||||
@@ -1736,8 +1765,6 @@ do_election(void)
|
|||||||
|
|
||||||
if (other_node_is_candidate == true)
|
if (other_node_is_candidate == true)
|
||||||
{
|
{
|
||||||
clear_node_info_list(&standby_nodes);
|
|
||||||
|
|
||||||
reset_node_voting_status();
|
reset_node_voting_status();
|
||||||
log_debug("other node is candidate, returning NOT CANDIDATE");
|
log_debug("other node is candidate, returning NOT CANDIDATE");
|
||||||
return ELECTION_NOT_CANDIDATE;
|
return ELECTION_NOT_CANDIDATE;
|
||||||
@@ -1790,14 +1817,13 @@ do_election(void)
|
|||||||
cell->node_info->node_id);
|
cell->node_info->node_id);
|
||||||
PQfinish(cell->node_info->conn);
|
PQfinish(cell->node_info->conn);
|
||||||
cell->node_info->conn = NULL;
|
cell->node_info->conn = NULL;
|
||||||
clear_node_info_list(&standby_nodes);
|
|
||||||
|
|
||||||
reset_node_voting_status();
|
reset_node_voting_status();
|
||||||
log_debug("other node is candidate, returning NOT CANDIDATE");
|
log_debug("other node is candidate, returning NOT CANDIDATE");
|
||||||
return ELECTION_NOT_CANDIDATE;
|
return ELECTION_NOT_CANDIDATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug(_("no vote recevied from %i, our ID is lower, not yielding"),
|
log_debug(_("no vote received from %i, our ID is lower, not yielding"),
|
||||||
cell->node_info->node_id);
|
cell->node_info->node_id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user