From 707506feaec317618df71e81af95287edfe162c5 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Thu, 4 Oct 2018 16:31:45 +0300 Subject: [PATCH] A slave must have running slaves to be a relay master This prevents some questionable status assignments, but also means that the Relay Master status can be lost if a slave goes down. This is contrary to Master status which is not lost if slaves go down. Fixes mxs1961_standalone_rejoin. --- .../modules/monitor/mariadbmon/cluster_discovery.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/modules/monitor/mariadbmon/cluster_discovery.cc b/server/modules/monitor/mariadbmon/cluster_discovery.cc index 97d270933..dfec1d4a7 100644 --- a/server/modules/monitor/mariadbmon/cluster_discovery.cc +++ b/server/modules/monitor/mariadbmon/cluster_discovery.cc @@ -558,7 +558,7 @@ void MariaDBMonitor::assign_slave_and_relay_master(MariaDBServer* start_node) parent->m_node.index = next_index++; } - bool has_slaves = false; + bool has_running_slaves = false; for (MariaDBServer* slave : parent->m_node.children) { // If the slave has an index, it has already been visited and labelled master/slave. @@ -588,7 +588,11 @@ void MariaDBMonitor::assign_slave_and_relay_master(MariaDBServer* start_node) // yet visited. if (found_slave_conn && (conn_is_live || allow_stale_slaves)) { - has_slaves = true; + bool slave_is_running = slave->is_running(); + if (slave_is_running) + { + has_running_slaves = true; + } if (slave->m_node.index == NodeData::INDEX_NOT_VISITED) { // Add the slave server to the priority queue to a position depending on the master @@ -597,7 +601,7 @@ void MariaDBMonitor::assign_slave_and_relay_master(MariaDBServer* start_node) // The slave only gets the slave flags if it's running. // TODO: If slaves with broken links should be given different flags, add that here. - if (slave->is_running()) + if (slave_is_running) { slave->set_status(SERVER_SLAVE); // Write the replication lag for this slave. It may have multiple slave connections, @@ -617,7 +621,7 @@ void MariaDBMonitor::assign_slave_and_relay_master(MariaDBServer* start_node) // Finally, if the node itself is a running slave and has slaves of its own, label it as relay. if (parent != m_master && parent_has_live_link - && parent->has_status(SERVER_SLAVE | SERVER_RUNNING) && has_slaves) + && parent->has_status(SERVER_SLAVE | SERVER_RUNNING) && has_running_slaves) { parent->set_status(SERVER_RELAY); }