MXS-1703 Miscellaneous cleanup

1. Move some remaining class data private.
2. Linebreak long lines.
3. Move current master autoselection inside class method.
4. Remove single-use constant #defines.
5. Monitor status is only written inside loop.
This commit is contained in:
Esa Korhonen
2018-03-15 18:36:47 +02:00
parent 4a6fc6b1c8
commit 1bef791572
4 changed files with 95 additions and 97 deletions

View File

@ -82,7 +82,7 @@ MXS_MONITORED_SERVER* MariaDBMonitor::build_mysql51_replication_tree()
/* Set the Slave Role */ /* Set the Slave Role */
if (ismaster) if (ismaster)
{ {
master = database; m_master = database;
MXS_DEBUG("Master server found at [%s]:%d with %d slaves", MXS_DEBUG("Master server found at [%s]:%d with %d slaves",
database->server->name, database->server->name,
@ -123,7 +123,7 @@ MXS_MONITORED_SERVER* MariaDBMonitor::build_mysql51_replication_tree()
} }
if (SERVER_IS_SLAVE(database->server) && if (SERVER_IS_SLAVE(database->server) &&
(database->server->master_id <= 0 || (database->server->master_id <= 0 ||
database->server->master_id != master->server->node_id)) database->server->master_id != m_master->server->node_id))
{ {
monitor_set_pending_status(database, SERVER_SLAVE); monitor_set_pending_status(database, SERVER_SLAVE);
@ -200,7 +200,7 @@ MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree(int num_servers)
if (current->depth > -1 && current->depth < root_level) if (current->depth > -1 && current->depth < root_level)
{ {
root_level = current->depth; root_level = current->depth;
master = ptr; m_master = ptr;
} }
backend = getServerByNodeId(m_monitor_base->monitored_servers, node_id); backend = getServerByNodeId(m_monitor_base->monitored_servers, node_id);
@ -231,12 +231,12 @@ MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree(int num_servers)
current->node_id); current->node_id);
master_cand->server->depth = current->depth - 1; master_cand->server->depth = current->depth - 1;
if (master && master_cand->server->depth < master->server->depth) if (m_master && master_cand->server->depth < m_master->server->depth)
{ {
/** A master with a lower depth was found, remove /** A master with a lower depth was found, remove
the master status from the previous master. */ the master status from the previous master. */
monitor_clear_pending_status(master, SERVER_MASTER); monitor_clear_pending_status(m_master, SERVER_MASTER);
master = master_cand; m_master = master_cand;
} }
MySqlServerInfo* info = get_server_info(master_cand); MySqlServerInfo* info = get_server_info(master_cand);
@ -267,16 +267,16 @@ MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree(int num_servers)
* Return the root master * Return the root master
*/ */
if (master != NULL) if (m_master != NULL)
{ {
/* If the root master is in MAINT, return NULL */ /* If the root master is in MAINT, return NULL */
if (SERVER_IN_MAINT(master->server)) if (SERVER_IN_MAINT(m_master->server))
{ {
return NULL; return NULL;
} }
else else
{ {
return master; return m_master;
} }
} }
else else

View File

@ -18,8 +18,25 @@
#include <maxscale/hk_heartbeat.h> #include <maxscale/hk_heartbeat.h>
#include <maxscale/mysql_utils.h> #include <maxscale/mysql_utils.h>
bool MariaDBMonitor::manual_switchover(MXS_MONITORED_SERVER* new_master, MXS_MONITORED_SERVER* current_master, json_t** error_out) bool MariaDBMonitor::manual_switchover(MXS_MONITORED_SERVER* new_master, MXS_MONITORED_SERVER* current_master,
json_t** error_out)
{ {
// Autoselect current master if not given as parameter.
MXS_MONITORED_SERVER* selected_current_master;
if (current_master == NULL)
{
if (m_master)
{
selected_current_master = m_master;
}
else
{
const char NO_MASTER[] = "Monitor '%s' has no master server.";
PRINT_MXS_JSON_ERROR(error_out, NO_MASTER, m_monitor_base->name);
return false;
}
}
bool stopped = stop(); bool stopped = stop();
if (stopped) if (stopped)
{ {
@ -30,8 +47,7 @@ bool MariaDBMonitor::manual_switchover(MXS_MONITORED_SERVER* new_master, MXS_MON
MXS_NOTICE("Monitor %s already stopped, switchover can proceed.", m_monitor_base->name); MXS_NOTICE("Monitor %s already stopped, switchover can proceed.", m_monitor_base->name);
} }
bool rval = false; bool current_ok = switchover_check_current(selected_current_master, error_out);
bool current_ok = switchover_check_current(current_master, error_out);
bool new_ok = switchover_check_new(new_master, error_out); bool new_ok = switchover_check_new(new_master, error_out);
// Check that all slaves are using gtid-replication // Check that all slaves are using gtid-replication
bool gtid_ok = true; bool gtid_ok = true;
@ -46,11 +62,12 @@ bool MariaDBMonitor::manual_switchover(MXS_MONITORED_SERVER* new_master, MXS_MON
} }
} }
bool rval = false;
if (current_ok && new_ok && gtid_ok) if (current_ok && new_ok && gtid_ok)
{ {
bool switched = do_switchover(current_master, new_master, error_out); bool switched = do_switchover(selected_current_master, new_master, error_out);
const char* curr_master_name = current_master->server->unique_name; const char* curr_master_name = selected_current_master->server->unique_name;
const char* new_master_name = new_master->server->unique_name; const char* new_master_name = new_master->server->unique_name;
if (switched) if (switched)
@ -132,13 +149,13 @@ bool MariaDBMonitor::manual_rejoin(SERVER* rejoin_server, json_t** output)
MXS_MONITORED_SERVER* mon_server = mon_get_monitored_server(m_monitor_base, rejoin_server); MXS_MONITORED_SERVER* mon_server = mon_get_monitored_server(m_monitor_base, rejoin_server);
if (mon_server) if (mon_server)
{ {
const char* master_name = master->server->unique_name; const char* master_name = m_master->server->unique_name;
MySqlServerInfo* master_info = get_server_info(master); MySqlServerInfo* master_info = get_server_info(m_master);
MySqlServerInfo* server_info = get_server_info(mon_server); MySqlServerInfo* server_info = get_server_info(mon_server);
if (server_is_rejoin_suspect(mon_server, master_info, output)) if (server_is_rejoin_suspect(mon_server, master_info, output))
{ {
if (update_gtids(master, master_info)) if (update_gtids(m_master, master_info))
{ {
if (can_replicate_from(mon_server, server_info, master_info)) if (can_replicate_from(mon_server, server_info, master_info))
{ {
@ -327,7 +344,7 @@ bool MariaDBMonitor::redirect_one_slave(MXS_MONITORED_SERVER* slave, const char*
*/ */
uint32_t MariaDBMonitor::do_rejoin(const ServerVector& joinable_servers) uint32_t MariaDBMonitor::do_rejoin(const ServerVector& joinable_servers)
{ {
SERVER* master_server = master->server; SERVER* master_server = m_master->server;
uint32_t servers_joined = 0; uint32_t servers_joined = 0;
if (!joinable_servers.empty()) if (!joinable_servers.empty())
{ {
@ -370,7 +387,7 @@ uint32_t MariaDBMonitor::do_rejoin(const ServerVector& joinable_servers)
*/ */
bool MariaDBMonitor::cluster_can_be_joined() bool MariaDBMonitor::cluster_can_be_joined()
{ {
return (master != NULL && SERVER_IS_MASTER(master->server) && m_master_gtid_domain >= 0); return (m_master != NULL && SERVER_IS_MASTER(m_master->server) && m_master_gtid_domain >= 0);
} }
/** /**
@ -385,7 +402,7 @@ bool MariaDBMonitor::cluster_can_be_joined()
bool MariaDBMonitor::get_joinable_servers(ServerVector* output) bool MariaDBMonitor::get_joinable_servers(ServerVector* output)
{ {
ss_dassert(output); ss_dassert(output);
MySqlServerInfo *master_info = get_server_info(master); MySqlServerInfo *master_info = get_server_info(m_master);
// Whether a join operation should be attempted or not depends on several criteria. Start with the ones // Whether a join operation should be attempted or not depends on several criteria. Start with the ones
// easiest to test. Go though all slaves and construct a preliminary list. // easiest to test. Go though all slaves and construct a preliminary list.
@ -404,7 +421,7 @@ bool MariaDBMonitor::get_joinable_servers(ServerVector* output)
bool comm_ok = true; bool comm_ok = true;
if (!suspects.empty()) if (!suspects.empty())
{ {
if (update_gtids(master, master_info)) if (update_gtids(m_master, master_info))
{ {
for (size_t i = 0; i < suspects.size(); i++) for (size_t i = 0; i < suspects.size(); i++)
{ {
@ -482,8 +499,8 @@ bool MariaDBMonitor::server_is_rejoin_suspect(MXS_MONITORED_SERVER* rejoin_serve
} }
// or is disconnected but master host or port is wrong. // or is disconnected but master host or port is wrong.
else if (!slave_status->slave_io_running && slave_status->slave_sql_running && else if (!slave_status->slave_io_running && slave_status->slave_sql_running &&
(slave_status->master_host != master->server->name || (slave_status->master_host != m_master->server->name ||
slave_status->master_port != master->server->port)) slave_status->master_port != m_master->server->port))
{ {
is_suspect = true; is_suspect = true;
} }
@ -508,7 +525,7 @@ bool MariaDBMonitor::server_is_rejoin_suspect(MXS_MONITORED_SERVER* rejoin_serve
bool MariaDBMonitor::do_switchover(MXS_MONITORED_SERVER* current_master, MXS_MONITORED_SERVER* new_master, bool MariaDBMonitor::do_switchover(MXS_MONITORED_SERVER* current_master, MXS_MONITORED_SERVER* new_master,
json_t** err_out) json_t** err_out)
{ {
MXS_MONITORED_SERVER* demotion_target = current_master ? current_master : master; MXS_MONITORED_SERVER* demotion_target = current_master ? current_master : m_master;
if (demotion_target == NULL) if (demotion_target == NULL)
{ {
PRINT_MXS_JSON_ERROR(err_out, "Cluster does not have a running master. Run failover instead."); PRINT_MXS_JSON_ERROR(err_out, "Cluster does not have a running master. Run failover instead.");
@ -1166,7 +1183,7 @@ MXS_MONITORED_SERVER* MariaDBMonitor::select_new_master(ServerVector* slaves_out
// Do not worry about the exclusion list yet, querying the excluded servers is ok. // Do not worry about the exclusion list yet, querying the excluded servers is ok.
MySqlServerInfo* cand_info = update_slave_info(cand); MySqlServerInfo* cand_info = update_slave_info(cand);
// If master is replicating from external master, it is updated but not added to array. // If master is replicating from external master, it is updated but not added to array.
if (cand_info && cand != master) if (cand_info && cand != m_master)
{ {
slaves_out->push_back(cand); slaves_out->push_back(cand);
// Check that server is not in the exclusion list while still being a valid choice. // Check that server is not in the exclusion list while still being a valid choice.
@ -1259,7 +1276,8 @@ bool MariaDBMonitor::server_is_excluded(const MXS_MONITORED_SERVER* server)
* @param candidate_info Server info of new candidate * @param candidate_info Server info of new candidate
* @return True if candidate is better * @return True if candidate is better
*/ */
bool MariaDBMonitor::is_candidate_better(const MySqlServerInfo* current_best_info, const MySqlServerInfo* candidate_info) bool MariaDBMonitor::is_candidate_better(const MySqlServerInfo* current_best_info,
const MySqlServerInfo* candidate_info)
{ {
uint64_t cand_io = candidate_info->slave_status.gtid_io_pos.sequence; uint64_t cand_io = candidate_info->slave_status.gtid_io_pos.sequence;
uint64_t cand_processed = candidate_info->gtid_current_pos.sequence; uint64_t cand_processed = candidate_info->gtid_current_pos.sequence;
@ -1300,6 +1318,7 @@ bool MariaDBMonitor::is_candidate_better(const MySqlServerInfo* current_best_inf
bool MariaDBMonitor::switchover_check_current(const MXS_MONITORED_SERVER* suggested_curr_master, bool MariaDBMonitor::switchover_check_current(const MXS_MONITORED_SERVER* suggested_curr_master,
json_t** error_out) const json_t** error_out) const
{ {
ss_dassert(suggested_curr_master);
bool server_is_master = false; bool server_is_master = false;
MXS_MONITORED_SERVER* extra_master = NULL; // A master server which is not the suggested one MXS_MONITORED_SERVER* extra_master = NULL; // A master server which is not the suggested one
for (MXS_MONITORED_SERVER* mon_serv = m_monitor_base->monitored_servers; for (MXS_MONITORED_SERVER* mon_serv = m_monitor_base->monitored_servers;
@ -1503,7 +1522,7 @@ bool MariaDBMonitor::mon_process_failover(bool* cluster_modified_out)
{ {
ss_dassert(*cluster_modified_out == false); ss_dassert(*cluster_modified_out == false);
if (config_get_global_options()->passive || if (config_get_global_options()->passive ||
(master && SERVER_IS_MASTER(master->server))) (m_master && SERVER_IS_MASTER(m_master->server)))
{ {
return true; return true;
} }
@ -1645,9 +1664,9 @@ bool MariaDBMonitor::failover_not_possible()
*/ */
bool MariaDBMonitor::slave_receiving_events() bool MariaDBMonitor::slave_receiving_events()
{ {
ss_dassert(master); ss_dassert(m_master);
bool received_event = false; bool received_event = false;
int64_t master_id = master->server->node_id; int64_t master_id = m_master->server->node_id;
for (MXS_MONITORED_SERVER* server = m_monitor_base->monitored_servers; server; server = server->next) for (MXS_MONITORED_SERVER* server = m_monitor_base->monitored_servers; server; server = server->next)
{ {
MySqlServerInfo* info = get_server_info(server); MySqlServerInfo* info = get_server_info(server);

View File

@ -39,30 +39,20 @@ void check_maxscale_schema_replication(MXS_MONITOR *monitor);
static const char* hb_table_name = "maxscale_schema.replication_heartbeat"; static const char* hb_table_name = "maxscale_schema.replication_heartbeat";
// Config parameter names
const char * const CN_AUTO_FAILOVER = "auto_failover"; const char * const CN_AUTO_FAILOVER = "auto_failover";
static const char CN_FAILOVER_TIMEOUT[] = "failover_timeout";
static const char CN_SWITCHOVER_TIMEOUT[] = "switchover_timeout";
static const char CN_AUTO_REJOIN[] = "auto_rejoin"; static const char CN_AUTO_REJOIN[] = "auto_rejoin";
static const char CN_FAILCOUNT[] = "failcount"; static const char CN_FAILCOUNT[] = "failcount";
static const char CN_NO_PROMOTE_SERVERS[] = "servers_no_promotion"; static const char CN_NO_PROMOTE_SERVERS[] = "servers_no_promotion";
static const char CN_FAILOVER_TIMEOUT[] = "failover_timeout";
static const char CN_SWITCHOVER_TIMEOUT[] = "switchover_timeout";
// Parameters for master failure verification and timeout // Parameters for master failure verification and timeout
static const char CN_VERIFY_MASTER_FAILURE[] = "verify_master_failure"; static const char CN_VERIFY_MASTER_FAILURE[] = "verify_master_failure";
static const char CN_MASTER_FAILURE_TIMEOUT[] = "master_failure_timeout"; static const char CN_MASTER_FAILURE_TIMEOUT[] = "master_failure_timeout";
// Replication credentials parameters for failover/switchover/join // Replication credentials parameters for failover/switchover/join
static const char CN_REPLICATION_USER[] = "replication_user"; static const char CN_REPLICATION_USER[] = "replication_user";
static const char CN_REPLICATION_PASSWORD[] = "replication_password"; static const char CN_REPLICATION_PASSWORD[] = "replication_password";
/** Default failover timeout */
#define DEFAULT_FAILOVER_TIMEOUT "90"
/** Default switchover timeout */
#define DEFAULT_SWITCHOVER_TIMEOUT "90"
/** Default master failure verification timeout */
#define DEFAULT_MASTER_FAILURE_TIMEOUT "10"
/** Default port */ /** Default port */
const int PORT_UNKNOWN = 0; const int PORT_UNKNOWN = 0;
@ -138,7 +128,7 @@ MariaDBMonitor* MariaDBMonitor::start(MXS_MONITOR *monitor, const MXS_CONFIG_PAR
/* Always reset these values. The server dependent values must be reset as servers could have been /* Always reset these values. The server dependent values must be reset as servers could have been
* added and removed. */ * added and removed. */
handle->m_shutdown = 0; handle->m_shutdown = 0;
handle->master = NULL; handle->m_master = NULL;
handle->init_server_info(); handle->init_server_info();
if (!handle->load_config_params(params)) if (!handle->load_config_params(params))
@ -158,10 +148,6 @@ MariaDBMonitor* MariaDBMonitor::start(MXS_MONITOR *monitor, const MXS_CONFIG_PAR
MXS_ERROR("Failed to start monitor thread for monitor '%s'.", monitor->name); MXS_ERROR("Failed to start monitor thread for monitor '%s'.", monitor->name);
error = true; error = true;
} }
else
{
handle->status = MXS_MONITOR_RUNNING;
}
} }
if (error) if (error)
@ -227,7 +213,7 @@ bool MariaDBMonitor::stop()
// There should be no race here as long as admin operations are performed // There should be no race here as long as admin operations are performed
// with the single admin lock locked. // with the single admin lock locked.
bool actually_stopped = false; bool actually_stopped = false;
if (status == MXS_MONITOR_RUNNING) if (m_status == MXS_MONITOR_RUNNING)
{ {
m_shutdown = 1; m_shutdown = 1;
thread_wait(m_thread); thread_wait(m_thread);
@ -263,11 +249,16 @@ void MariaDBMonitor::diagnostics(DCB *dcb) const
dcb_printf(dcb, "Slave configured: %s\n", serv_info->slave_configured ? "YES" : "NO"); dcb_printf(dcb, "Slave configured: %s\n", serv_info->slave_configured ? "YES" : "NO");
if (serv_info->slave_configured) if (serv_info->slave_configured)
{ {
dcb_printf(dcb, "Slave IO running: %s\n", serv_info->slave_status.slave_io_running ? "YES" : "NO"); dcb_printf(dcb, "Slave IO running: %s\n",
dcb_printf(dcb, "Slave SQL running: %s\n", serv_info->slave_status.slave_sql_running ? "YES" : "NO"); serv_info->slave_status.slave_io_running ? "YES" : "NO");
dcb_printf(dcb, "Master ID: %" PRId64 "\n", serv_info->slave_status.master_server_id); dcb_printf(dcb, "Slave SQL running: %s\n",
dcb_printf(dcb, "Master binlog file: %s\n", serv_info->slave_status.master_log_file.c_str()); serv_info->slave_status.slave_sql_running ? "YES" : "NO");
dcb_printf(dcb, "Master binlog position: %lu\n", serv_info->slave_status.read_master_log_pos); dcb_printf(dcb, "Master ID: %" PRId64 "\n",
serv_info->slave_status.master_server_id);
dcb_printf(dcb, "Master binlog file: %s\n",
serv_info->slave_status.master_log_file.c_str());
dcb_printf(dcb, "Master binlog position: %lu\n",
serv_info->slave_status.read_master_log_pos);
} }
if (serv_info->gtid_current_pos.server_id != SERVER_ID_UNKNOWN) if (serv_info->gtid_current_pos.server_id != SERVER_ID_UNKNOWN)
{ {
@ -429,7 +420,7 @@ bool MariaDBMonitor::set_standalone_master(MXS_MONITORED_SERVER *db)
server_clear_set_status(db->server, SERVER_SLAVE, SERVER_MASTER | SERVER_STALE_STATUS); server_clear_set_status(db->server, SERVER_SLAVE, SERVER_MASTER | SERVER_STALE_STATUS);
monitor_set_pending_status(db, SERVER_MASTER | SERVER_STALE_STATUS); monitor_set_pending_status(db, SERVER_MASTER | SERVER_STALE_STATUS);
monitor_clear_pending_status(db, SERVER_SLAVE); monitor_clear_pending_status(db, SERVER_SLAVE);
master = db; m_master = db;
rval = true; rval = true;
} }
else if (!m_allow_cluster_recovery) else if (!m_allow_cluster_recovery)
@ -445,6 +436,7 @@ bool MariaDBMonitor::set_standalone_master(MXS_MONITORED_SERVER *db)
void MariaDBMonitor::main_loop() void MariaDBMonitor::main_loop()
{ {
m_status = MXS_MONITOR_RUNNING;
MXS_MONITORED_SERVER *ptr; MXS_MONITORED_SERVER *ptr;
bool replication_heartbeat; bool replication_heartbeat;
bool detect_stale_master; bool detect_stale_master;
@ -460,19 +452,19 @@ void MariaDBMonitor::main_loop()
if (mysql_thread_init()) if (mysql_thread_init())
{ {
MXS_ERROR("mysql_thread_init failed in monitor module. Exiting."); MXS_ERROR("mysql_thread_init failed in monitor module. Exiting.");
status = MXS_MONITOR_STOPPED; m_status = MXS_MONITOR_STOPPED;
return; return;
} }
load_server_journal(m_monitor_base, &master); load_server_journal(m_monitor_base, &m_master);
while (1) while (1)
{ {
if (m_shutdown) if (m_shutdown)
{ {
status = MXS_MONITOR_STOPPING; m_status = MXS_MONITOR_STOPPING;
mysql_thread_end(); mysql_thread_end();
status = MXS_MONITOR_STOPPED; m_status = MXS_MONITOR_STOPPED;
return; return;
} }
/** Wait base interval */ /** Wait base interval */
@ -576,7 +568,7 @@ void MariaDBMonitor::main_loop()
monitor_set_pending_status(ptr, SERVER_MASTER); monitor_set_pending_status(ptr, SERVER_MASTER);
ptr->server->depth = 0; ptr->server->depth = 0;
master = ptr; m_master = ptr;
root_master = ptr; root_master = ptr;
} }
} }
@ -601,9 +593,9 @@ void MariaDBMonitor::main_loop()
find_graph_cycles(this, m_monitor_base->monitored_servers, num_servers); find_graph_cycles(this, m_monitor_base->monitored_servers, num_servers);
} }
if (master != NULL && SERVER_IS_MASTER(master->server)) if (m_master != NULL && SERVER_IS_MASTER(m_master->server))
{ {
MySqlServerInfo* master_info = get_server_info(master); MySqlServerInfo* master_info = get_server_info(m_master);
// Update cluster gtid domain // Update cluster gtid domain
int64_t domain = master_info->gtid_domain_id; int64_t domain = master_info->gtid_domain_id;
if (m_master_gtid_domain >= 0 && domain != m_master_gtid_domain) if (m_master_gtid_domain >= 0 && domain != m_master_gtid_domain)
@ -614,7 +606,7 @@ void MariaDBMonitor::main_loop()
m_master_gtid_domain = domain; m_master_gtid_domain = domain;
// Update cluster external master // Update cluster external master
if (SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(master->server)) if (SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(m_master->server))
{ {
if (master_info->slave_status.master_host != m_external_master_host || if (master_info->slave_status.master_host != m_external_master_host ||
master_info->slave_status.master_port != m_external_master_port) master_info->slave_status.master_port != m_external_master_port)
@ -767,7 +759,7 @@ void MariaDBMonitor::main_loop()
if (set_standalone_master(m_monitor_base->monitored_servers)) if (set_standalone_master(m_monitor_base->monitored_servers))
{ {
// Update the root_master to point to the standalone master // Update the root_master to point to the standalone master
root_master = master; root_master = m_master;
} }
} }
else else
@ -794,7 +786,7 @@ void MariaDBMonitor::main_loop()
} }
} }
ss_dassert(root_master == NULL || master == root_master); ss_dassert(root_master == NULL || m_master == root_master);
ss_dassert(!root_master || ss_dassert(!root_master ||
((root_master->server->status & (SERVER_SLAVE | SERVER_MASTER)) ((root_master->server->status & (SERVER_SLAVE | SERVER_MASTER))
!= (SERVER_SLAVE | SERVER_MASTER))); != (SERVER_SLAVE | SERVER_MASTER)));
@ -821,8 +813,8 @@ void MariaDBMonitor::main_loop()
disable_setting(CN_AUTO_FAILOVER); disable_setting(CN_AUTO_FAILOVER);
} }
// If master seems to be down, check if slaves are receiving events. // If master seems to be down, check if slaves are receiving events.
else if (m_verify_master_failure && master && else if (m_verify_master_failure && m_master &&
SERVER_IS_DOWN(master->server) && slave_receiving_events()) SERVER_IS_DOWN(m_master->server) && slave_receiving_events())
{ {
MXS_INFO("Master failure not yet confirmed by slaves, delaying failover."); MXS_INFO("Master failure not yet confirmed by slaves, delaying failover.");
} }
@ -920,13 +912,13 @@ void MariaDBMonitor::main_loop()
else else
{ {
MXS_ERROR("Query error to master '%s' prevented a possible rejoin operation.", MXS_ERROR("Query error to master '%s' prevented a possible rejoin operation.",
master->server->unique_name); m_master->server->unique_name);
} }
} }
mon_hangup_failed_servers(m_monitor_base); mon_hangup_failed_servers(m_monitor_base);
servers_status_current_to_pending(m_monitor_base); servers_status_current_to_pending(m_monitor_base);
store_server_journal(m_monitor_base, master); store_server_journal(m_monitor_base, m_master);
release_monitor_servers(m_monitor_base); release_monitor_servers(m_monitor_base);
} /*< while (1) */ } /*< while (1) */
} }
@ -981,7 +973,7 @@ void MariaDBMonitor::set_master_heartbeat(MXS_MONITORED_SERVER *database)
char heartbeat_insert_query[512] = ""; char heartbeat_insert_query[512] = "";
char heartbeat_purge_query[512] = ""; char heartbeat_purge_query[512] = "";
if (master == NULL) if (m_master == NULL)
{ {
MXS_ERROR("set_master_heartbeat called without an available Master server"); MXS_ERROR("set_master_heartbeat called without an available Master server");
return; return;
@ -1030,7 +1022,7 @@ void MariaDBMonitor::set_master_heartbeat(MXS_MONITORED_SERVER *database)
sprintf(heartbeat_insert_query, sprintf(heartbeat_insert_query,
"UPDATE maxscale_schema.replication_heartbeat " "UPDATE maxscale_schema.replication_heartbeat "
"SET master_timestamp = %lu WHERE master_server_id = %li AND maxscale_id = %lu", "SET master_timestamp = %lu WHERE master_server_id = %li AND maxscale_id = %lu",
heartbeat, master->server->node_id, m_id); heartbeat, m_master->server->node_id, m_id);
/* Try to insert MaxScale timestamp into master */ /* Try to insert MaxScale timestamp into master */
if (mxs_mysql_query(database->con, heartbeat_insert_query)) if (mxs_mysql_query(database->con, heartbeat_insert_query))
@ -1050,7 +1042,7 @@ void MariaDBMonitor::set_master_heartbeat(MXS_MONITORED_SERVER *database)
sprintf(heartbeat_insert_query, sprintf(heartbeat_insert_query,
"REPLACE INTO maxscale_schema.replication_heartbeat " "REPLACE INTO maxscale_schema.replication_heartbeat "
"(master_server_id, maxscale_id, master_timestamp ) VALUES ( %li, %lu, %lu)", "(master_server_id, maxscale_id, master_timestamp ) VALUES ( %li, %lu, %lu)",
master->server->node_id, m_id, heartbeat); m_master->server->node_id, m_id, heartbeat);
if (mxs_mysql_query(database->con, heartbeat_insert_query)) if (mxs_mysql_query(database->con, heartbeat_insert_query))
{ {
@ -1095,7 +1087,7 @@ void MariaDBMonitor::set_slave_heartbeat(MXS_MONITORED_SERVER *database)
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *result; MYSQL_RES *result;
if (master == NULL) if (m_master == NULL)
{ {
MXS_ERROR("set_slave_heartbeat called without an available Master server"); MXS_ERROR("set_slave_heartbeat called without an available Master server");
return; return;
@ -1106,10 +1098,10 @@ void MariaDBMonitor::set_slave_heartbeat(MXS_MONITORED_SERVER *database)
sprintf(select_heartbeat_query, "SELECT master_timestamp " sprintf(select_heartbeat_query, "SELECT master_timestamp "
"FROM maxscale_schema.replication_heartbeat " "FROM maxscale_schema.replication_heartbeat "
"WHERE maxscale_id = %lu AND master_server_id = %li", "WHERE maxscale_id = %lu AND master_server_id = %li",
m_id, master->server->node_id); m_id, m_master->server->node_id);
/* if there is a master then send the query to the slave with master_id */ /* if there is a master then send the query to the slave with master_id */
if (master != NULL && (mxs_mysql_query(database->con, select_heartbeat_query) == 0 if (m_master != NULL && (mxs_mysql_query(database->con, select_heartbeat_query) == 0
&& (result = mysql_store_result(database->con)) != NULL)) && (result = mysql_store_result(database->con)) != NULL))
{ {
int rows_found = 0; int rows_found = 0;
@ -1167,7 +1159,7 @@ void MariaDBMonitor::set_slave_heartbeat(MXS_MONITORED_SERVER *database)
database->server->rlag = MAX_RLAG_NOT_AVAILABLE; database->server->rlag = MAX_RLAG_NOT_AVAILABLE;
database->server->node_ts = 0; database->server->node_ts = 0;
if (master->server->node_id < 0) if (m_master->server->node_id < 0)
{ {
MXS_ERROR("error: replication heartbeat: " MXS_ERROR("error: replication heartbeat: "
"master_server_id NOT available for %s:%i", "master_server_id NOT available for %s:%i",
@ -1503,7 +1495,7 @@ bool mysql_handle_switchover(const MODULECMD_ARG* args, json_t** error_out)
error = true; error = true;
} }
// Check given old master or autoselect. // Check given old master. If NULL, manual_switchover() will autoselect.
MXS_MONITORED_SERVER* mon_curr_master = NULL; MXS_MONITORED_SERVER* mon_curr_master = NULL;
if (current_master) if (current_master)
{ {
@ -1514,20 +1506,6 @@ bool mysql_handle_switchover(const MODULECMD_ARG* args, json_t** error_out)
error = true; error = true;
} }
} }
else
{
// Autoselect current master
if (handle->master)
{
mon_curr_master = handle->master;
}
else
{
const char NO_MASTER[] = "Monitor '%s' has no master server.";
PRINT_MXS_JSON_ERROR(error_out, NO_MASTER, mon->name);
error = true;
}
}
if (!error) if (!error)
{ {
@ -1685,12 +1663,12 @@ MXS_MODULE* MXS_CREATE_MODULE()
mxs_monitor_event_enum_values mxs_monitor_event_enum_values
}, },
{CN_AUTO_FAILOVER, MXS_MODULE_PARAM_BOOL, "false"}, {CN_AUTO_FAILOVER, MXS_MODULE_PARAM_BOOL, "false"},
{CN_FAILOVER_TIMEOUT, MXS_MODULE_PARAM_COUNT, DEFAULT_FAILOVER_TIMEOUT}, {CN_FAILOVER_TIMEOUT, MXS_MODULE_PARAM_COUNT, "90"},
{CN_SWITCHOVER_TIMEOUT, MXS_MODULE_PARAM_COUNT, DEFAULT_SWITCHOVER_TIMEOUT}, {CN_SWITCHOVER_TIMEOUT, MXS_MODULE_PARAM_COUNT, "90"},
{CN_REPLICATION_USER, MXS_MODULE_PARAM_STRING}, {CN_REPLICATION_USER, MXS_MODULE_PARAM_STRING},
{CN_REPLICATION_PASSWORD, MXS_MODULE_PARAM_STRING}, {CN_REPLICATION_PASSWORD, MXS_MODULE_PARAM_STRING},
{CN_VERIFY_MASTER_FAILURE, MXS_MODULE_PARAM_BOOL, "true"}, {CN_VERIFY_MASTER_FAILURE, MXS_MODULE_PARAM_BOOL, "true"},
{CN_MASTER_FAILURE_TIMEOUT, MXS_MODULE_PARAM_COUNT, DEFAULT_MASTER_FAILURE_TIMEOUT}, {CN_MASTER_FAILURE_TIMEOUT, MXS_MODULE_PARAM_COUNT, "10"},
{CN_AUTO_REJOIN, MXS_MODULE_PARAM_BOOL, "false"}, {CN_AUTO_REJOIN, MXS_MODULE_PARAM_BOOL, "false"},
{CN_NO_PROMOTE_SERVERS, MXS_MODULE_PARAM_SERVERLIST}, {CN_NO_PROMOTE_SERVERS, MXS_MODULE_PARAM_SERVERLIST},
{MXS_END_MODULE_PARAMS} {MXS_END_MODULE_PARAMS}

View File

@ -106,7 +106,8 @@ public:
* *
* @return True, if switchover was performed, false otherwise. * @return True, if switchover was performed, false otherwise.
*/ */
bool manual_switchover(MXS_MONITORED_SERVER* new_master, MXS_MONITORED_SERVER* current_master, json_t** error_out); bool manual_switchover(MXS_MONITORED_SERVER* new_master, MXS_MONITORED_SERVER* current_master,
json_t** error_out);
/** /**
* Perform user-activated failover. * Perform user-activated failover.
@ -149,8 +150,6 @@ public:
*/ */
const MySqlServerInfo* get_server_info(const MXS_MONITORED_SERVER* db) const; const MySqlServerInfo* get_server_info(const MXS_MONITORED_SERVER* db) const;
int status; /**< Monitor status. TODO: This should be in MXS_MONITOR */
MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
bool detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */ bool detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */
private: private:
@ -158,12 +157,14 @@ private:
THREAD m_thread; /**< Monitor thread */ THREAD m_thread; /**< Monitor thread */
unsigned long m_id; /**< Monitor ID */ unsigned long m_id; /**< Monitor ID */
volatile int m_shutdown; /**< Flag to shutdown the monitor thread. */ volatile int m_shutdown; /**< Flag to shutdown the monitor thread. */
ServerInfoMap m_server_info; /**< Contains server specific information */ volatile int m_status; /**< Monitor status. */
// Values updated by monitor // Values updated by monitor
int64_t m_master_gtid_domain; /**< Gtid domain currently used by the master */ int64_t m_master_gtid_domain; /**< Gtid domain currently used by the master */
string m_external_master_host; /**< External master host, for fail/switchover */ string m_external_master_host; /**< External master host, for fail/switchover */
int m_external_master_port; /**< External master port */ int m_external_master_port; /**< External master port */
MXS_MONITORED_SERVER *m_master; /**< Master server for MySQL Master/Slave replication */
ServerInfoMap m_server_info; /**< Contains server specific information */
// Replication topology detection settings // Replication topology detection settings
bool m_mysql51_replication; /**< Use MySQL 5.1 replication */ bool m_mysql51_replication; /**< Use MySQL 5.1 replication */