Code cleanup

Removed unused code.
This commit is contained in:
Esa Korhonen
2018-06-27 12:55:34 +03:00
parent 0afcd4b468
commit 960d08a36a
2 changed files with 0 additions and 375 deletions

View File

@ -62,202 +62,6 @@ static bool server_config_compare(const MariaDBServer* lhs, const MariaDBServer*
return lhs->m_config_index < rhs->m_config_index;
}
/**
* This function computes the replication tree from a set of monitored servers and returns the root server
* with SERVER_MASTER bit. The tree is computed even for servers in 'maintenance' mode.
*
* @return The server at root level with SERVER_MASTER bit
*/
MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree()
{
const int num_servers = m_servers.size();
MXS_MONITORED_SERVER *ptr;
MXS_MONITORED_SERVER *backend;
SERVER *current;
int depth = 0;
long node_id;
int root_level;
ptr = m_monitor->monitored_servers;
root_level = num_servers;
while (ptr)
{
/* The server could be in SERVER_IN_MAINT
* that means SERVER_IS_RUNNING returns 0
* Let's check only for SERVER_IS_DOWN: server is not running
*/
if (get_server_info(ptr)->is_down())
{
ptr = ptr->next;
continue;
}
depth = 0;
current = ptr->server;
node_id = current->master_id;
/** Either this node doesn't replicate from a master or the master
* where it replicates from is not configured to this monitor. */
if (node_id < 1 ||
getServerByNodeId(node_id) == NULL)
{
MXS_MONITORED_SERVER *find_slave;
find_slave = getSlaveOfNodeId(current->node_id, ACCEPT_DOWN);
if (find_slave == NULL)
{
current->depth = -1;
ptr = ptr->next;
continue;
}
else
{
current->depth = 0;
}
}
else
{
depth++;
}
while (depth <= num_servers)
{
/* set the root master at lowest depth level */
if (current->depth > -1 && current->depth < root_level)
{
root_level = current->depth;
m_master = get_server_info(ptr);
}
backend = getServerByNodeId(node_id);
if (backend)
{
node_id = backend->server->master_id;
}
else
{
node_id = -1;
}
if (node_id > 0)
{
current->depth = depth + 1;
depth++;
}
else
{
MXS_MONITORED_SERVER *master_cand;
current->depth = depth;
master_cand = getServerByNodeId(current->master_id);
if (master_cand && master_cand->server && master_cand->server->node_id > 0)
{
master_cand->server->depth = current->depth - 1;
if (m_master && master_cand->server->depth < m_master->m_server_base->server->depth)
{
/** A master with a lower depth was found, remove
the master status from the previous master. */
monitor_clear_pending_status(m_master->m_server_base, SERVER_MASTER);
m_master = get_server_info(master_cand);
}
MariaDBServer* info = get_server_info(master_cand);
if (info->is_running())
{
/** Only set the Master status if read_only is disabled */
monitor_set_pending_status(master_cand,
info->m_read_only ? SERVER_SLAVE : SERVER_MASTER);
}
}
else
{
if (current->master_id > 0)
{
monitor_set_pending_status(ptr, SERVER_SLAVE);
monitor_set_pending_status(ptr, SERVER_SLAVE_OF_EXT_MASTER);
}
}
break;
}
}
ptr = ptr->next;
}
/*
* Return the root master
*/
if (m_master != NULL)
{
/* If the root master is in MAINT, return NULL */
if (m_master->is_in_maintenance())
{
return NULL;
}
else
{
return m_master->m_server_base;
}
}
else
{
return NULL;
}
}
/**
* Fetch a node by node_id
*
* @param node_id The server_id to fetch
*
* @return The server with the required server_id
*/
MXS_MONITORED_SERVER* MariaDBMonitor::getServerByNodeId(long node_id)
{
SERVER *current;
MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers;
while (ptr)
{
current = ptr->server;
if (current->node_id == node_id)
{
return ptr;
}
ptr = ptr->next;
}
return NULL;
}
/**
* Fetch a slave node from a node_id
*
* @param node_id The server_id to fetch
* @param slave_down_setting Whether to accept or reject slaves which are down
* @return The slave server of this node_id
*/
MXS_MONITORED_SERVER* MariaDBMonitor::getSlaveOfNodeId(long node_id, slave_down_setting_t slave_down_setting)
{
MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers;
SERVER *current;
while (ptr)
{
current = ptr->server;
if (current->master_id == node_id &&
(slave_down_setting == ACCEPT_DOWN || !get_server_info(ptr)->is_down()))
{
return ptr;
}
ptr = ptr->next;
}
return NULL;
}
/**
* @brief Visit a node in the graph
*
@ -782,148 +586,6 @@ bool MariaDBMonitor::set_standalone_master()
return rval;
}
/**
* Compute replication tree, find root master.
*
* @return Found master server or NULL
*/
MariaDBServer* MariaDBMonitor::find_root_master()
{
MXS_MONITORED_SERVER* found_root_master = NULL;
const int num_servers = m_servers.size();
/* if only one server is configured, that's is Master */
if (num_servers == 1)
{
auto mon_server = m_servers[0]->m_server_base;
if (m_servers[0]->is_running())
{
mon_server->server->depth = 0;
/* status cleanup */
monitor_clear_pending_status(mon_server, SERVER_SLAVE);
/* master status set */
monitor_set_pending_status(mon_server, SERVER_MASTER);
mon_server->server->depth = 0;
m_master = m_servers[0];
found_root_master = mon_server;
}
}
else
{
/* Compute the replication tree */
found_root_master = get_replication_tree();
}
if (m_detect_multimaster && num_servers > 0)
{
/** Find all the master server cycles in the cluster graph. If
multiple masters are found, the servers with the read_only
variable set to ON will be assigned the slave status. */
find_graph_cycles();
}
return found_root_master ? get_server_info(found_root_master) : NULL;
}
/**
* Test if server is a relay master and assign status if yes.
*
* @param candidate The server to assign
*/
void MariaDBMonitor::assign_relay_master(MariaDBServer& candidate)
{
MXS_MONITORED_SERVER* ptr = candidate.m_server_base;
if (ptr->server->node_id > 0 && ptr->server->master_id > 0 &&
getSlaveOfNodeId(ptr->server->node_id, REJECT_DOWN) &&
getServerByNodeId(ptr->server->master_id) &&
(!m_detect_multimaster || candidate.m_node.cycle == NodeData::CYCLE_NONE))
{
/** This server is both a slave and a master i.e. a relay master */
monitor_set_pending_status(ptr, SERVER_RELAY_MASTER);
monitor_clear_pending_status(ptr, SERVER_MASTER);
}
}
/**
* Update serve states of a single server
*
* @param db_server Server to update
* @param root_master_server The current best master
*/
void MariaDBMonitor::update_server_states(MariaDBServer& db_server, MariaDBServer* root_master_server)
{
MXS_MONITORED_SERVER* root_master = root_master_server ? root_master_server->m_server_base : NULL;
if (!db_server.is_in_maintenance())
{
/** If "detect_stale_master" option is On, let's use the previous master.
*
* Multi-master mode detects the stale masters in find_graph_cycles().
*
* TODO: If a stale master goes down and comes back up, it loses
* the master status. An adequate solution would be to promote
* the stale master as a real master if it is the last running server.
*/
MXS_MONITORED_SERVER* ptr = db_server.m_server_base;
if (m_detect_stale_master && root_master && !m_detect_multimaster &&
// This server is still the root master and ...
(strcmp(ptr->server->address, root_master->server->address) == 0 &&
ptr->server->port == root_master->server->port) &&
// had master status but is now losing it.
(ptr->mon_prev_status & SERVER_MASTER) && !(ptr->pending_status & SERVER_MASTER) &&
!db_server.m_read_only)
{
db_server.set_status(SERVER_WAS_MASTER | SERVER_MASTER);
/** Log the message only if the master server didn't have
* the stale master bit set */
if ((ptr->mon_prev_status & SERVER_WAS_MASTER) == 0)
{
MXS_WARNING("All slave servers under the current master server have been lost. "
"Assigning Stale Master status to the old master server '%s' (%s:%i).",
ptr->server->name, ptr->server->address,
ptr->server->port);
}
}
if (m_detect_stale_slave)
{
uint64_t bits = SERVER_SLAVE | SERVER_RUNNING;
if ((ptr->mon_prev_status & bits) == bits &&
root_master && SRV_MASTER_STATUS(root_master->pending_status))
{
/** Slave with a running master, assign stale slave candidacy */
if ((ptr->pending_status & bits) == bits)
{
monitor_set_pending_status(ptr, SERVER_WAS_SLAVE);
}
/** Server lost slave when a master is available, remove
* stale slave candidacy */
else if ((ptr->pending_status & bits) == SERVER_RUNNING)
{
monitor_clear_pending_status(ptr, SERVER_WAS_SLAVE);
}
}
/** If this server was a stale slave candidate, assign
* slave status to it */
else if (ptr->mon_prev_status & SERVER_WAS_SLAVE &&
ptr->pending_status & SERVER_RUNNING &&
// Master is down
(!root_master || !SRV_MASTER_STATUS(root_master->pending_status) ||
// Master just came up
(SRV_MASTER_STATUS(root_master->pending_status) &&
(root_master->mon_prev_status & SERVER_MASTER) == 0)))
{
monitor_set_pending_status(ptr, SERVER_SLAVE);
}
else if (root_master == NULL && !db_server.m_slave_status.empty())
{
monitor_set_pending_status(ptr, SERVER_SLAVE);
}
}
}
}
/**
* Find the server with the best reach in the candidates-array. Running state or 'read_only' is ignored by
* this method.
@ -1069,29 +731,6 @@ void MariaDBMonitor::calculate_node_reach(MariaDBServer* node)
node->m_node.reach = reach;
}
/**
* Handle a node for the "reach" calculation.
*
* @param node Node to visit
* @return Total number of children without counting already visited nodes.
*/
int MariaDBMonitor::calc_reach_visit_node(MariaDBServer* node)
{
node->m_node.index = NodeData::INDEX_FIRST; // Indexing is not required other than preventing extra visits
int reachables = 1;
for (auto iter = node->m_node.children.begin(); iter != node->m_node.children.end(); iter++)
{
MariaDBServer* slave = *iter;
if (slave->m_node.index == NodeData::INDEX_NOT_VISITED)
{
reachables += calc_reach_visit_node(slave);
}
}
return reachables;
}
/**
* Check which node in a cycle should be the master. The node must be running without read_only.
*

View File

@ -180,12 +180,6 @@ private:
bool m_warn_failover_precond; /**< Print failover preconditions error message? */
bool m_warn_cannot_rejoin; /**< Print warning if auto_rejoin fails because of invalid gtid:s? */
enum slave_down_setting_t
{
ACCEPT_DOWN,
REJECT_DOWN
};
// Base methods
MariaDBMonitor(MXS_MONITOR* monitor_base);
void reset_server_info();
@ -199,14 +193,9 @@ private:
// Cluster discovery and status assignment methods
void update_server(MariaDBServer& server);
MariaDBServer* find_root_master();
MXS_MONITORED_SERVER* get_replication_tree();
MXS_MONITORED_SERVER* build_mysql51_replication_tree();
void find_graph_cycles();
void update_server_states(MariaDBServer& db_server, MariaDBServer* root_master);
bool standalone_master_required();
bool set_standalone_master();
void assign_relay_master(MariaDBServer& serv_info);
void log_master_changes();
void update_gtid_domain();
void update_external_master();
@ -214,15 +203,12 @@ private:
void set_slave_heartbeat(MariaDBServer*);
void measure_replication_lag();
void check_maxscale_schema_replication();
MXS_MONITORED_SERVER* getServerByNodeId(long);
MXS_MONITORED_SERVER* getSlaveOfNodeId(long, slave_down_setting_t);
void build_replication_graph();
void tarjan_scc_visit_node(MariaDBServer *node, ServerArray* stack, int *index, int *cycle);
void assign_cycle_roles(int cycle);
MariaDBServer* find_topology_master_server(std::string* msg_out);
MariaDBServer* find_best_reach_server(const ServerArray& candidates);
void calculate_node_reach(MariaDBServer* node);
int calc_reach_visit_node(MariaDBServer* node);
MariaDBServer* find_master_inside_cycle(ServerArray& cycle_servers);
void assign_master_and_slave();
void assign_slave_and_relay_master(MariaDBServer* node);