diff --git a/server/modules/monitor/mariadbmon/cluster_manipulation.cc b/server/modules/monitor/mariadbmon/cluster_manipulation.cc index 27376d3be..1aa7f621b 100644 --- a/server/modules/monitor/mariadbmon/cluster_manipulation.cc +++ b/server/modules/monitor/mariadbmon/cluster_manipulation.cc @@ -1505,7 +1505,7 @@ unique_ptr MariaDBMonitor::switchover_prepare(SERVER* promotio else { // Autoselect current master as demotion target. - if (m_master == NULL) + if (m_master == NULL || !m_master->is_master()) { const char msg[] = "Can not autoselect a demotion target for switchover: cluster does " "not have a master."; diff --git a/server/modules/monitor/mariadbmon/mariadbserver.cc b/server/modules/monitor/mariadbmon/mariadbserver.cc index 712a04953..3e85bca06 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.cc +++ b/server/modules/monitor/mariadbmon/mariadbserver.cc @@ -1058,10 +1058,9 @@ bool MariaDBServer::can_be_demoted_switchover(string* reason_out) string reason; string query_error; - // TODO: Add relay server support - if (!is_master()) + if (!is_usable()) { - reason = "it is not the current master or it is in maintenance."; + reason = "it is not running or it is in maintenance."; } else if (!update_replication_settings(&query_error)) { @@ -1071,6 +1070,12 @@ bool MariaDBServer::can_be_demoted_switchover(string* reason_out) { reason = "its binary log is disabled."; } + else if (!is_master() && !m_rpl_settings.log_slave_updates) + { + // This means that gtid_binlog_pos cannot be trusted. + // TODO: reduce dependency on gtid_binlog_pos to get rid of this requirement + reason = "it is not the master and log_slave_updates is disabled."; + } else if (m_gtid_binlog_pos.empty()) { reason = "it does not have a 'gtid_binlog_pos'.";