MXS-1703 Rename fields in SlaveStatus
Althought the fields are still public, having the 'm_' is clearer.
This commit is contained in:
@ -128,7 +128,7 @@ MXS_MONITORED_SERVER* MariaDBMonitor::build_mysql51_replication_tree()
|
||||
}
|
||||
if (SERVER_IS_SLAVE(database->server) &&
|
||||
(database->server->master_id <= 0 ||
|
||||
database->server->master_id != m_master->server_base->server->node_id))
|
||||
database->server->master_id != m_master->m_server_base->server->node_id))
|
||||
{
|
||||
|
||||
monitor_set_pending_status(database, SERVER_SLAVE);
|
||||
@ -236,11 +236,11 @@ MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree()
|
||||
current->node_id);
|
||||
master_cand->server->depth = current->depth - 1;
|
||||
|
||||
if (m_master && master_cand->server->depth < m_master->server_base->server->depth)
|
||||
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->server_base, SERVER_MASTER);
|
||||
monitor_clear_pending_status(m_master->m_server_base, SERVER_MASTER);
|
||||
m_master = get_server_info(master_cand);
|
||||
}
|
||||
|
||||
@ -249,7 +249,8 @@ MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree()
|
||||
if (SERVER_IS_RUNNING(master_cand->server))
|
||||
{
|
||||
/** Only set the Master status if read_only is disabled */
|
||||
monitor_set_pending_status(master_cand, info->read_only ? SERVER_SLAVE : SERVER_MASTER);
|
||||
monitor_set_pending_status(master_cand,
|
||||
info->m_read_only ? SERVER_SLAVE : SERVER_MASTER);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -275,13 +276,13 @@ MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree()
|
||||
if (m_master != NULL)
|
||||
{
|
||||
/* If the root master is in MAINT, return NULL */
|
||||
if (SERVER_IN_MAINT(m_master->server_base->server))
|
||||
if (SERVER_IN_MAINT(m_master->m_server_base->server))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_master->server_base;
|
||||
return m_master->m_server_base;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -503,12 +504,12 @@ void MariaDBMonitor::find_graph_cycles()
|
||||
/** Build the graph */
|
||||
for (int i = 0; i < nservers; i++)
|
||||
{
|
||||
if (graph[i].info->slave_status.master_server_id > 0)
|
||||
if (graph[i].info->m_slave_status.master_server_id > 0)
|
||||
{
|
||||
/** Found a connected node */
|
||||
for (int k = 0; k < nservers; k++)
|
||||
{
|
||||
if (graph[k].info->server_id == graph[i].info->slave_status.master_server_id)
|
||||
if (graph[k].info->m_server_id == graph[i].info->m_slave_status.master_server_id)
|
||||
{
|
||||
graph[i].parent = &graph[k];
|
||||
break;
|
||||
@ -532,12 +533,12 @@ void MariaDBMonitor::find_graph_cycles()
|
||||
|
||||
for (int i = 0; i < nservers; i++)
|
||||
{
|
||||
graph[i].info->group = graph[i].cycle;
|
||||
graph[i].info->m_group = graph[i].cycle;
|
||||
|
||||
if (graph[i].cycle > 0)
|
||||
{
|
||||
/** We have at least one cycle in the graph */
|
||||
if (graph[i].info->read_only)
|
||||
if (graph[i].info->m_read_only)
|
||||
{
|
||||
monitor_set_pending_status(graph[i].db, SERVER_SLAVE | SERVER_STALE_SLAVE);
|
||||
monitor_clear_pending_status(graph[i].db, SERVER_MASTER);
|
||||
@ -562,7 +563,7 @@ void MariaDBMonitor::find_graph_cycles()
|
||||
* slave in this case can be either a normal slave or another
|
||||
* master.
|
||||
*/
|
||||
if (graph[i].info->read_only)
|
||||
if (graph[i].info->m_read_only)
|
||||
{
|
||||
/** The master is in read-only mode, set it into Slave state */
|
||||
monitor_set_pending_status(graph[i].db, SERVER_SLAVE | SERVER_STALE_SLAVE);
|
||||
@ -584,7 +585,7 @@ void MariaDBMonitor::find_graph_cycles()
|
||||
*/
|
||||
void MariaDBMonitor::monitor_database(MariaDBServer* serv_info)
|
||||
{
|
||||
MXS_MONITORED_SERVER* database = serv_info->server_base;
|
||||
MXS_MONITORED_SERVER* database = serv_info->m_server_base;
|
||||
/* Don't probe servers in maintenance mode */
|
||||
if (SERVER_IN_MAINT(database->server))
|
||||
{
|
||||
@ -634,12 +635,12 @@ void MariaDBMonitor::monitor_database(MariaDBServer* serv_info)
|
||||
if (mxs_mysql_query(database->con, "SELECT @@maxscale_version") == 0 &&
|
||||
(result = mysql_store_result(database->con)) != NULL)
|
||||
{
|
||||
serv_info->binlog_relay = true;
|
||||
serv_info->m_binlog_relay = true;
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
serv_info->binlog_relay = false;
|
||||
serv_info->m_binlog_relay = false;
|
||||
}
|
||||
|
||||
/* Get server version string, also get/set numeric representation. */
|
||||
@ -648,25 +649,25 @@ void MariaDBMonitor::monitor_database(MariaDBServer* serv_info)
|
||||
uint64_t version_num = server_get_version(database->server);
|
||||
if (version_num >= 100000)
|
||||
{
|
||||
serv_info->version = MYSQL_SERVER_VERSION_100;
|
||||
serv_info->m_version = MYSQL_SERVER_VERSION_100;
|
||||
}
|
||||
else if (version_num >= 5 * 10000 + 5 * 100)
|
||||
{
|
||||
serv_info->version = MYSQL_SERVER_VERSION_55;
|
||||
serv_info->m_version = MYSQL_SERVER_VERSION_55;
|
||||
}
|
||||
else
|
||||
{
|
||||
serv_info->version = MYSQL_SERVER_VERSION_51;
|
||||
serv_info->m_version = MYSQL_SERVER_VERSION_51;
|
||||
}
|
||||
/* Query a few settings. */
|
||||
serv_info->read_server_variables();
|
||||
/* If gtid domain exists and server is 10.0, update gtid:s */
|
||||
if (m_master_gtid_domain >= 0 && serv_info->version == MYSQL_SERVER_VERSION_100)
|
||||
if (m_master_gtid_domain >= 0 && serv_info->m_version == MYSQL_SERVER_VERSION_100)
|
||||
{
|
||||
serv_info->update_gtids();
|
||||
}
|
||||
/* Check for MariaDB 10.x.x and get status for multi-master replication */
|
||||
if (serv_info->version == MYSQL_SERVER_VERSION_100 || serv_info->version == MYSQL_SERVER_VERSION_55)
|
||||
if (serv_info->m_version == MYSQL_SERVER_VERSION_100 || serv_info->m_version == MYSQL_SERVER_VERSION_55)
|
||||
{
|
||||
monitor_mysql_db(serv_info);
|
||||
}
|
||||
@ -693,7 +694,7 @@ void MariaDBMonitor::monitor_database(MariaDBServer* serv_info)
|
||||
*/
|
||||
void MariaDBMonitor::monitor_mysql_db(MariaDBServer* serv_info)
|
||||
{
|
||||
MXS_MONITORED_SERVER* database = serv_info->server_base;
|
||||
MXS_MONITORED_SERVER* database = serv_info->m_server_base;
|
||||
/** Clear old states */
|
||||
monitor_clear_pending_status(database, SERVER_SLAVE | SERVER_MASTER | SERVER_RELAY_MASTER |
|
||||
SERVER_SLAVE_OF_EXTERNAL_MASTER);
|
||||
@ -701,14 +702,14 @@ void MariaDBMonitor::monitor_mysql_db(MariaDBServer* serv_info)
|
||||
if (serv_info->do_show_slave_status())
|
||||
{
|
||||
/* If all configured slaves are running set this node as slave */
|
||||
if (serv_info->slave_configured && serv_info->n_slaves_running > 0 &&
|
||||
serv_info->n_slaves_running == serv_info->n_slaves_configured)
|
||||
if (serv_info->m_slave_configured && serv_info->m_n_slaves_running > 0 &&
|
||||
serv_info->m_n_slaves_running == serv_info->m_n_slaves_configured)
|
||||
{
|
||||
monitor_set_pending_status(database, SERVER_SLAVE);
|
||||
}
|
||||
|
||||
/** Store master_id of current node. For MySQL 5.1 it will be set at a later point. */
|
||||
database->server->master_id = serv_info->slave_status.master_server_id;
|
||||
database->server->master_id = serv_info->m_slave_status.master_server_id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -949,12 +950,12 @@ bool MariaDBMonitor::standalone_master_required()
|
||||
if (server->is_running())
|
||||
{
|
||||
candidates++;
|
||||
if (server->read_only || server->slave_configured || candidates > 1)
|
||||
if (server->m_read_only || server->m_slave_configured || candidates > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (server->server_base->mon_err_count < m_failcount)
|
||||
else if (server->m_server_base->mon_err_count < m_failcount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -978,7 +979,7 @@ bool MariaDBMonitor::set_standalone_master()
|
||||
for (auto iter = m_servers.begin(); iter != m_servers.end(); iter++)
|
||||
{
|
||||
MariaDBServer* server = *iter;
|
||||
auto mon_server = server->server_base;
|
||||
auto mon_server = server->m_server_base;
|
||||
if (server->is_running())
|
||||
{
|
||||
if (!server->is_master() && m_warn_set_standalone_master)
|
||||
@ -1012,7 +1013,7 @@ bool MariaDBMonitor::set_standalone_master()
|
||||
*/
|
||||
void MariaDBMonitor::monitor_one_server(MariaDBServer& server)
|
||||
{
|
||||
MXS_MONITORED_SERVER* ptr = server.server_base;
|
||||
MXS_MONITORED_SERVER* ptr = server.m_server_base;
|
||||
|
||||
ptr->mon_prev_status = ptr->server->status;
|
||||
/* copy server status into monitor pending_status */
|
||||
@ -1074,7 +1075,7 @@ MariaDBServer* MariaDBMonitor::find_root_master()
|
||||
/* if only one server is configured, that's is Master */
|
||||
if (num_servers == 1)
|
||||
{
|
||||
auto mon_server = m_servers[0]->server_base;
|
||||
auto mon_server = m_servers[0]->m_server_base;
|
||||
if (SERVER_IS_RUNNING(mon_server->server))
|
||||
{
|
||||
mon_server->server->depth = 0;
|
||||
@ -1119,11 +1120,11 @@ MariaDBServer* MariaDBMonitor::find_root_master()
|
||||
*/
|
||||
void MariaDBMonitor::assign_relay_master(MariaDBServer& candidate)
|
||||
{
|
||||
MXS_MONITORED_SERVER* ptr = candidate.server_base;
|
||||
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.group == 0))
|
||||
(!m_detect_multimaster || candidate.m_group == 0))
|
||||
{
|
||||
/** This server is both a slave and a master i.e. a relay master */
|
||||
monitor_set_pending_status(ptr, SERVER_RELAY_MASTER);
|
||||
@ -1139,8 +1140,8 @@ void MariaDBMonitor::assign_relay_master(MariaDBServer& candidate)
|
||||
*/
|
||||
void MariaDBMonitor::update_server_states(MariaDBServer& db_server, MariaDBServer* root_master_server)
|
||||
{
|
||||
MXS_MONITORED_SERVER* ptr = db_server.server_base;
|
||||
MXS_MONITORED_SERVER* root_master = root_master_server ? root_master_server->server_base : NULL;
|
||||
MXS_MONITORED_SERVER* ptr = db_server.m_server_base;
|
||||
MXS_MONITORED_SERVER* root_master = root_master_server ? root_master_server->m_server_base : NULL;
|
||||
if (!SERVER_IN_MAINT(ptr->server))
|
||||
{
|
||||
MariaDBServer *serv_info = get_server_info(ptr);
|
||||
@ -1158,7 +1159,7 @@ void MariaDBMonitor::update_server_states(MariaDBServer& db_server, MariaDBServe
|
||||
ptr->server->port == root_master->server->port) &&
|
||||
(ptr->server->status & SERVER_MASTER) &&
|
||||
!(ptr->pending_status & SERVER_MASTER) &&
|
||||
!serv_info->read_only)
|
||||
!serv_info->m_read_only)
|
||||
{
|
||||
/**
|
||||
* In this case server->status will not be updated from pending_status
|
||||
@ -1210,7 +1211,7 @@ void MariaDBMonitor::update_server_states(MariaDBServer& db_server, MariaDBServe
|
||||
{
|
||||
monitor_set_pending_status(ptr, SERVER_SLAVE);
|
||||
}
|
||||
else if (root_master == NULL && serv_info->slave_configured)
|
||||
else if (root_master == NULL && serv_info->m_slave_configured)
|
||||
{
|
||||
monitor_set_pending_status(ptr, SERVER_SLAVE);
|
||||
}
|
||||
|
@ -222,8 +222,8 @@ int MariaDBMonitor::redirect_slaves(MariaDBServer* new_master, const ServerArray
|
||||
{
|
||||
ss_dassert(redirected_slaves != NULL);
|
||||
MXS_NOTICE("Redirecting slaves to new master.");
|
||||
string change_cmd = generate_change_master_cmd(new_master->server_base->server->name,
|
||||
new_master->server_base->server->port);
|
||||
string change_cmd = generate_change_master_cmd(new_master->m_server_base->server->name,
|
||||
new_master->m_server_base->server->port);
|
||||
int successes = 0;
|
||||
for (auto iter = slaves.begin(); iter != slaves.end(); iter++)
|
||||
{
|
||||
@ -246,7 +246,7 @@ int MariaDBMonitor::redirect_slaves(MariaDBServer* new_master, const ServerArray
|
||||
bool MariaDBMonitor::start_external_replication(MariaDBServer* new_master, json_t** err_out)
|
||||
{
|
||||
bool rval = false;
|
||||
MYSQL* new_master_conn = new_master->server_base->con;
|
||||
MYSQL* new_master_conn = new_master->m_server_base->con;
|
||||
string change_cmd = generate_change_master_cmd(m_external_master_host, m_external_master_port);
|
||||
if (mxs_mysql_query(new_master_conn, change_cmd.c_str()) == 0 &&
|
||||
mxs_mysql_query(new_master_conn, "START SLAVE;") == 0)
|
||||
@ -274,8 +274,8 @@ bool MariaDBMonitor::start_external_replication(MariaDBServer* new_master, json_
|
||||
bool MariaDBMonitor::switchover_start_slave(MariaDBServer* old_master, MariaDBServer* new_master)
|
||||
{
|
||||
bool rval = false;
|
||||
MYSQL* old_master_con = old_master->server_base->con;
|
||||
SERVER* new_master_server = new_master->server_base->server;
|
||||
MYSQL* old_master_con = old_master->m_server_base->con;
|
||||
SERVER* new_master_server = new_master->m_server_base->server;
|
||||
|
||||
string change_cmd = generate_change_master_cmd(new_master_server->name, new_master_server->port);
|
||||
if (mxs_mysql_query(old_master_con, change_cmd.c_str()) == 0 &&
|
||||
@ -303,7 +303,7 @@ bool MariaDBMonitor::switchover_start_slave(MariaDBServer* old_master, MariaDBSe
|
||||
*/
|
||||
uint32_t MariaDBMonitor::do_rejoin(const ServerArray& joinable_servers, json_t** output)
|
||||
{
|
||||
SERVER* master_server = m_master->server_base->server;
|
||||
SERVER* master_server = m_master->m_server_base->server;
|
||||
const char* master_name = master_server->unique_name;
|
||||
uint32_t servers_joined = 0;
|
||||
if (!joinable_servers.empty())
|
||||
@ -315,7 +315,7 @@ uint32_t MariaDBMonitor::do_rejoin(const ServerArray& joinable_servers, json_t**
|
||||
const char* name = joinable->name();
|
||||
|
||||
bool op_success = false;
|
||||
if (joinable->n_slaves_configured == 0)
|
||||
if (joinable->m_n_slaves_configured == 0)
|
||||
{
|
||||
if (!m_demote_sql_file.empty() && !joinable->run_sql_from_file(m_demote_sql_file, output))
|
||||
{
|
||||
@ -413,26 +413,26 @@ bool MariaDBMonitor::server_is_rejoin_suspect(MariaDBServer* rejoin_cand, json_t
|
||||
bool is_suspect = false;
|
||||
if (rejoin_cand->is_running() && !rejoin_cand->is_master())
|
||||
{
|
||||
SlaveStatus* slave_status = &rejoin_cand->slave_status;
|
||||
SlaveStatus* slave_status = &rejoin_cand->m_slave_status;
|
||||
// Has no slave connection, yet is not a master.
|
||||
if (rejoin_cand->n_slaves_configured == 0)
|
||||
if (rejoin_cand->m_n_slaves_configured == 0)
|
||||
{
|
||||
is_suspect = true;
|
||||
}
|
||||
// Or has existing slave connection ...
|
||||
else if (rejoin_cand->n_slaves_configured == 1)
|
||||
else if (rejoin_cand->m_n_slaves_configured == 1)
|
||||
{
|
||||
// which is connected to master but it's the wrong one
|
||||
if (slave_status->slave_io_running == SlaveStatus::SLAVE_IO_YES &&
|
||||
slave_status->master_server_id != m_master->server_id)
|
||||
slave_status->master_server_id != m_master->m_server_id)
|
||||
{
|
||||
is_suspect = true;
|
||||
}
|
||||
// or is disconnected but master host or port is wrong.
|
||||
else if (slave_status->slave_io_running == SlaveStatus::SLAVE_IO_CONNECTING &&
|
||||
slave_status->slave_sql_running &&
|
||||
(slave_status->master_host != m_master->server_base->server->name ||
|
||||
slave_status->master_port != m_master->server_base->server->port))
|
||||
(slave_status->master_host != m_master->m_server_base->server->name ||
|
||||
slave_status->master_port != m_master->m_server_base->server->port))
|
||||
{
|
||||
is_suspect = true;
|
||||
}
|
||||
@ -443,7 +443,7 @@ bool MariaDBMonitor::server_is_rejoin_suspect(MariaDBServer* rejoin_cand, json_t
|
||||
/* User has requested a manual rejoin but with a server which has multiple slave connections or
|
||||
* is already connected or trying to connect to the correct master. TODO: Slave IO stopped is
|
||||
* not yet handled perfectly. */
|
||||
if (rejoin_cand->n_slaves_configured > 1)
|
||||
if (rejoin_cand->m_n_slaves_configured > 1)
|
||||
{
|
||||
const char MULTI_SLAVE[] = "Server '%s' has multiple slave connections, cannot rejoin.";
|
||||
PRINT_MXS_JSON_ERROR(output, MULTI_SLAVE, rejoin_cand->name());
|
||||
@ -567,7 +567,7 @@ bool MariaDBMonitor::do_switchover(MariaDBServer** current_master, MariaDBServer
|
||||
// Step 3: Wait for the slaves (including promotion target) to catch up with master.
|
||||
ServerArray catchup_slaves = redirectable_slaves;
|
||||
catchup_slaves.push_back(promotion_target);
|
||||
if (switchover_wait_slaves_catchup(catchup_slaves, demotion_target->gtid_binlog_pos,
|
||||
if (switchover_wait_slaves_catchup(catchup_slaves, demotion_target->m_gtid_binlog_pos,
|
||||
seconds_remaining, err_out))
|
||||
{
|
||||
time_t step3_time = time(NULL);
|
||||
@ -624,7 +624,7 @@ bool MariaDBMonitor::do_switchover(MariaDBServer** current_master, MariaDBServer
|
||||
{
|
||||
// Step 3 or 4 failed, try to undo step 2.
|
||||
const char QUERY_UNDO[] = "SET GLOBAL read_only=0;";
|
||||
if (mxs_mysql_query(demotion_target->server_base->con, QUERY_UNDO) == 0)
|
||||
if (mxs_mysql_query(demotion_target->m_server_base->con, QUERY_UNDO) == 0)
|
||||
{
|
||||
PRINT_MXS_JSON_ERROR(err_out, "read_only disabled on server %s.", demotion_target->name());
|
||||
}
|
||||
@ -632,7 +632,7 @@ bool MariaDBMonitor::do_switchover(MariaDBServer** current_master, MariaDBServer
|
||||
{
|
||||
PRINT_MXS_JSON_ERROR(err_out, "Could not disable read_only on server %s: '%s'.",
|
||||
demotion_target->name(),
|
||||
mysql_error(demotion_target->server_base->con));
|
||||
mysql_error(demotion_target->m_server_base->con));
|
||||
}
|
||||
|
||||
// Try to reactivate external replication if any.
|
||||
@ -743,10 +743,10 @@ bool MariaDBMonitor::switchover_demote_master(MariaDBServer* current_master, jso
|
||||
MXS_NOTICE("Demoting server '%s'.", current_master->name());
|
||||
bool success = false;
|
||||
bool query_error = false;
|
||||
MYSQL* conn = current_master->server_base->con;
|
||||
MYSQL* conn = current_master->m_server_base->con;
|
||||
const char* query = ""; // The next query to execute. Used also for error printing.
|
||||
// The presence of an external master changes several things.
|
||||
const bool external_master = SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(current_master->server_base->server);
|
||||
const bool external_master = SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(current_master->m_server_base->server);
|
||||
|
||||
if (external_master)
|
||||
{
|
||||
@ -892,13 +892,13 @@ bool MariaDBMonitor::wait_cluster_stabilization(MariaDBServer* new_master, const
|
||||
bool rval = false;
|
||||
time_t begin = time(NULL);
|
||||
|
||||
if (mxs_mysql_query(new_master->server_base->con, "FLUSH TABLES;") == 0 &&
|
||||
if (mxs_mysql_query(new_master->m_server_base->con, "FLUSH TABLES;") == 0 &&
|
||||
new_master->update_gtids())
|
||||
{
|
||||
int query_fails = 0;
|
||||
int repl_fails = 0;
|
||||
int successes = 0;
|
||||
const GtidList& target = new_master->gtid_current_pos;
|
||||
const GtidList& target = new_master->m_gtid_current_pos;
|
||||
ServerArray wait_list = slaves; // Check all the servers in the list
|
||||
bool first_round = true;
|
||||
bool time_is_up = false;
|
||||
@ -918,15 +918,15 @@ bool MariaDBMonitor::wait_cluster_stabilization(MariaDBServer* new_master, const
|
||||
if (slave->update_gtids() &&
|
||||
slave->do_show_slave_status())
|
||||
{
|
||||
if (!slave->slave_status.last_error.empty())
|
||||
if (!slave->m_slave_status.last_error.empty())
|
||||
{
|
||||
// IO or SQL error on slave, replication is a fail
|
||||
MXS_WARNING("Slave '%s' cannot start replication: '%s'.", slave->name(),
|
||||
slave->slave_status.last_error.c_str());
|
||||
slave->m_slave_status.last_error.c_str());
|
||||
wait_list.erase(wait_list.begin() + i);
|
||||
repl_fails++;
|
||||
}
|
||||
else if (GtidList::events_ahead(target, slave->gtid_current_pos,
|
||||
else if (GtidList::events_ahead(target, slave->m_gtid_current_pos,
|
||||
GtidList::MISSING_DOMAIN_IGNORE) == 0)
|
||||
{
|
||||
// This slave has reached the same gtid as master, remove from list
|
||||
@ -997,7 +997,7 @@ bool MariaDBMonitor::switchover_check_preferred_master(MariaDBServer* preferred,
|
||||
bool MariaDBMonitor::promote_new_master(MariaDBServer* new_master, json_t** err_out)
|
||||
{
|
||||
bool success = false;
|
||||
MYSQL* new_master_conn = new_master->server_base->con;
|
||||
MYSQL* new_master_conn = new_master->m_server_base->con;
|
||||
MXS_NOTICE("Promoting server '%s' to master.", new_master->name());
|
||||
const char* query = "STOP SLAVE;";
|
||||
if (mxs_mysql_query(new_master_conn, query) == 0)
|
||||
@ -1154,13 +1154,13 @@ bool MariaDBMonitor::server_is_excluded(const MariaDBServer* server)
|
||||
bool MariaDBMonitor::is_candidate_better(const MariaDBServer* current_best, const MariaDBServer* candidate,
|
||||
uint32_t gtid_domain)
|
||||
{
|
||||
uint64_t cand_io = candidate->slave_status.gtid_io_pos.get_gtid(gtid_domain).m_sequence;
|
||||
uint64_t cand_processed = candidate->gtid_current_pos.get_gtid(gtid_domain).m_sequence;
|
||||
uint64_t curr_io = current_best->slave_status.gtid_io_pos.get_gtid(gtid_domain).m_sequence;
|
||||
uint64_t curr_processed = current_best->gtid_current_pos.get_gtid(gtid_domain).m_sequence;
|
||||
uint64_t cand_io = candidate->m_slave_status.gtid_io_pos.get_gtid(gtid_domain).m_sequence;
|
||||
uint64_t cand_processed = candidate->m_gtid_current_pos.get_gtid(gtid_domain).m_sequence;
|
||||
uint64_t curr_io = current_best->m_slave_status.gtid_io_pos.get_gtid(gtid_domain).m_sequence;
|
||||
uint64_t curr_processed = current_best->m_gtid_current_pos.get_gtid(gtid_domain).m_sequence;
|
||||
|
||||
bool cand_updates = candidate->rpl_settings.log_slave_updates;
|
||||
bool curr_updates = current_best->rpl_settings.log_slave_updates;
|
||||
bool cand_updates = candidate->m_rpl_settings.log_slave_updates;
|
||||
bool curr_updates = current_best->m_rpl_settings.log_slave_updates;
|
||||
bool is_better = false;
|
||||
// Accept a slave with a later event in relay log.
|
||||
if (cand_io > curr_io)
|
||||
@ -1272,7 +1272,7 @@ bool MariaDBMonitor::failover_check(json_t** error_out)
|
||||
for (auto iter = m_servers.begin(); iter != m_servers.end(); iter++)
|
||||
{
|
||||
MariaDBServer* server = *iter;
|
||||
uint64_t status_bits = server->server_base->server->status;
|
||||
uint64_t status_bits = server->m_server_base->server->status;
|
||||
uint64_t master_up = (SERVER_MASTER | SERVER_RUNNING);
|
||||
if ((status_bits & master_up) == master_up)
|
||||
{
|
||||
@ -1351,7 +1351,7 @@ bool MariaDBMonitor::handle_auto_failover()
|
||||
for (auto iter = m_servers.begin(); iter != m_servers.end(); iter++)
|
||||
{
|
||||
MariaDBServer* server = *iter;
|
||||
MXS_MONITORED_SERVER* mon_server = server->server_base;
|
||||
MXS_MONITORED_SERVER* mon_server = server->m_server_base;
|
||||
if (mon_server->new_event && mon_server->server->last_event == MASTER_DOWN_EVENT)
|
||||
{
|
||||
if (mon_server->server->active_event)
|
||||
@ -1378,15 +1378,15 @@ bool MariaDBMonitor::handle_auto_failover()
|
||||
|
||||
if (failed_master)
|
||||
{
|
||||
if (m_failcount > 1 && failed_master->server_base->mon_err_count == 1)
|
||||
if (m_failcount > 1 && failed_master->m_server_base->mon_err_count == 1)
|
||||
{
|
||||
MXS_WARNING("Master has failed. If master status does not change in %d monitor passes, failover "
|
||||
"begins.", m_failcount - 1);
|
||||
}
|
||||
else if (failed_master->server_base->mon_err_count >= m_failcount)
|
||||
else if (failed_master->m_server_base->mon_err_count >= m_failcount)
|
||||
{
|
||||
MXS_NOTICE("Performing automatic failover to replace failed master '%s'.", failed_master->name());
|
||||
failed_master->server_base->new_event = false;
|
||||
failed_master->m_server_base->new_event = false;
|
||||
if (failover_check(NULL))
|
||||
{
|
||||
if (!do_failover(NULL))
|
||||
@ -1412,7 +1412,7 @@ bool MariaDBMonitor::failover_not_possible()
|
||||
{
|
||||
MariaDBServer* info = get_server_info(s);
|
||||
|
||||
if (info->n_slaves_configured > 1)
|
||||
if (info->m_n_slaves_configured > 1)
|
||||
{
|
||||
MXS_ERROR("Server '%s' is configured to replicate from multiple "
|
||||
"masters, failover is not possible.", s->server->unique_name);
|
||||
@ -1432,15 +1432,15 @@ bool MariaDBMonitor::slave_receiving_events()
|
||||
{
|
||||
ss_dassert(m_master);
|
||||
bool received_event = false;
|
||||
int64_t master_id = m_master->server_base->server->node_id;
|
||||
int64_t master_id = m_master->m_server_base->server->node_id;
|
||||
for (MXS_MONITORED_SERVER* server = m_monitor_base->monitored_servers; server; server = server->next)
|
||||
{
|
||||
MariaDBServer* info = get_server_info(server);
|
||||
|
||||
if (info->slave_configured &&
|
||||
info->slave_status.slave_io_running == SlaveStatus::SLAVE_IO_YES &&
|
||||
info->slave_status.master_server_id == master_id &&
|
||||
difftime(time(NULL), info->latest_event) < m_master_failure_timeout)
|
||||
if (info->m_slave_configured &&
|
||||
info->m_slave_status.slave_io_running == SlaveStatus::SLAVE_IO_YES &&
|
||||
info->m_slave_status.master_server_id == master_id &&
|
||||
difftime(time(NULL), info->m_latest_event) < m_master_failure_timeout)
|
||||
{
|
||||
/**
|
||||
* The slave is still connected to the correct master and has received events. This means that
|
||||
|
@ -83,7 +83,7 @@ void MariaDBMonitor::init_server_info()
|
||||
m_server_info.clear();
|
||||
for (auto iter = m_servers.begin(); iter != m_servers.end(); iter++)
|
||||
{
|
||||
auto mon_server = (*iter)->server_base;
|
||||
auto mon_server = (*iter)->m_server_base;
|
||||
ss_dassert(m_server_info.count(mon_server) == 0);
|
||||
ServerInfoMap::value_type new_val(mon_server, *iter);
|
||||
m_server_info.insert(new_val);
|
||||
@ -364,9 +364,9 @@ void MariaDBMonitor::main_loop()
|
||||
assign_relay_master(**iter);
|
||||
|
||||
/* Remove SLAVE status if this server is a Binlog Server relay */
|
||||
if ((*iter)->binlog_relay)
|
||||
if ((*iter)->m_binlog_relay)
|
||||
{
|
||||
monitor_clear_pending_status((*iter)->server_base, SERVER_SLAVE);
|
||||
monitor_clear_pending_status((*iter)->m_server_base, SERVER_SLAVE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -397,10 +397,10 @@ void MariaDBMonitor::main_loop()
|
||||
|
||||
if (root_master && root_master->is_master())
|
||||
{
|
||||
SERVER* root_master_server = root_master->server_base->server;
|
||||
SERVER* root_master_server = root_master->m_server_base->server;
|
||||
// Clear slave and stale slave status bits from current master
|
||||
server_clear_status_nolock(root_master_server, SERVER_SLAVE | SERVER_STALE_SLAVE);
|
||||
monitor_clear_pending_status(root_master->server_base, SERVER_SLAVE | SERVER_STALE_SLAVE);
|
||||
monitor_clear_pending_status(root_master->m_server_base, SERVER_SLAVE | SERVER_STALE_SLAVE);
|
||||
|
||||
/**
|
||||
* Clear external slave status from master if configured to do so.
|
||||
@ -409,14 +409,14 @@ void MariaDBMonitor::main_loop()
|
||||
*/
|
||||
if (m_ignore_external_masters)
|
||||
{
|
||||
monitor_clear_pending_status(root_master->server_base, SERVER_SLAVE_OF_EXTERNAL_MASTER);
|
||||
monitor_clear_pending_status(root_master->m_server_base, SERVER_SLAVE_OF_EXTERNAL_MASTER);
|
||||
server_clear_status_nolock(root_master_server, SERVER_SLAVE_OF_EXTERNAL_MASTER);
|
||||
}
|
||||
}
|
||||
|
||||
ss_dassert(root_master == NULL || root_master == m_master);
|
||||
ss_dassert(root_master == NULL ||
|
||||
((root_master->server_base->server->status & (SERVER_SLAVE | SERVER_MASTER)) !=
|
||||
((root_master->m_server_base->server->status & (SERVER_SLAVE | SERVER_MASTER)) !=
|
||||
(SERVER_SLAVE | SERVER_MASTER)));
|
||||
|
||||
/**
|
||||
@ -436,7 +436,7 @@ void MariaDBMonitor::main_loop()
|
||||
|
||||
/* Generate the replication heartbeat event by performing an update */
|
||||
if (m_detect_replication_lag && root_master &&
|
||||
(root_master->is_master() || SERVER_IS_RELAY_SERVER(root_master->server_base->server)))
|
||||
(root_master->is_master() || SERVER_IS_RELAY_SERVER(root_master->m_server_base->server)))
|
||||
{
|
||||
measure_replication_lag(root_master);
|
||||
}
|
||||
@ -452,7 +452,7 @@ void MariaDBMonitor::main_loop()
|
||||
|
||||
mon_hangup_failed_servers(m_monitor_base);
|
||||
servers_status_current_to_pending(m_monitor_base);
|
||||
store_server_journal(m_monitor_base, m_master ? m_master->server_base : NULL);
|
||||
store_server_journal(m_monitor_base, m_master ? m_master->m_server_base : NULL);
|
||||
release_monitor_servers(m_monitor_base);
|
||||
|
||||
// Check how much the monitor should sleep to get one full monitor interval.
|
||||
@ -482,7 +482,7 @@ void MariaDBMonitor::main_loop()
|
||||
|
||||
void MariaDBMonitor::update_gtid_domain()
|
||||
{
|
||||
int64_t domain = m_master->gtid_domain_id;
|
||||
int64_t domain = m_master->m_gtid_domain_id;
|
||||
if (m_master_gtid_domain >= 0 && domain != m_master_gtid_domain)
|
||||
{
|
||||
MXS_NOTICE("Gtid domain id of master has changed: %" PRId64 " -> %" PRId64 ".",
|
||||
@ -493,13 +493,13 @@ void MariaDBMonitor::update_gtid_domain()
|
||||
|
||||
void MariaDBMonitor::update_external_master()
|
||||
{
|
||||
if (SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(m_master->server_base->server))
|
||||
if (SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(m_master->m_server_base->server))
|
||||
{
|
||||
if (m_master->slave_status.master_host != m_external_master_host ||
|
||||
m_master->slave_status.master_port != m_external_master_port)
|
||||
if (m_master->m_slave_status.master_host != m_external_master_host ||
|
||||
m_master->m_slave_status.master_port != m_external_master_port)
|
||||
{
|
||||
const string new_ext_host = m_master->slave_status.master_host;
|
||||
const int new_ext_port = m_master->slave_status.master_port;
|
||||
const string new_ext_host = m_master->m_slave_status.master_host;
|
||||
const int new_ext_port = m_master->m_slave_status.master_port;
|
||||
if (m_external_master_port == PORT_UNKNOWN)
|
||||
{
|
||||
MXS_NOTICE("Cluster master server is replicating from an external master: %s:%d",
|
||||
@ -529,17 +529,17 @@ void MariaDBMonitor::update_external_master()
|
||||
void MariaDBMonitor::measure_replication_lag(MariaDBServer* root_master)
|
||||
{
|
||||
ss_dassert(root_master);
|
||||
MXS_MONITORED_SERVER* mon_root_master = root_master->server_base;
|
||||
MXS_MONITORED_SERVER* mon_root_master = root_master->m_server_base;
|
||||
set_master_heartbeat(root_master);
|
||||
for (auto iter = m_servers.begin(); iter != m_servers.end(); iter++)
|
||||
{
|
||||
MariaDBServer* server = *iter;
|
||||
MXS_MONITORED_SERVER* ptr = server->server_base;
|
||||
MXS_MONITORED_SERVER* ptr = server->m_server_base;
|
||||
if ((!SERVER_IN_MAINT(ptr->server)) && server->is_running())
|
||||
{
|
||||
if (ptr->server->node_id != mon_root_master->server->node_id &&
|
||||
(server->is_slave() || SERVER_IS_RELAY_SERVER(ptr->server)) &&
|
||||
!server->binlog_relay) // No select lag for Binlog Server
|
||||
!server->m_binlog_relay) // No select lag for Binlog Server
|
||||
{
|
||||
set_slave_heartbeat(server);
|
||||
}
|
||||
@ -549,7 +549,7 @@ void MariaDBMonitor::measure_replication_lag(MariaDBServer* root_master)
|
||||
|
||||
void MariaDBMonitor::log_master_changes(MariaDBServer* root_master_server, int* log_no_master)
|
||||
{
|
||||
MXS_MONITORED_SERVER* root_master = root_master_server ? root_master_server->server_base : NULL;
|
||||
MXS_MONITORED_SERVER* root_master = root_master_server ? root_master_server->m_server_base : NULL;
|
||||
if (root_master &&
|
||||
mon_status_changed(root_master) &&
|
||||
!(root_master->server->status & SERVER_STALE_STATUS))
|
||||
@ -663,7 +663,7 @@ void MariaDBMonitor::set_master_heartbeat(MariaDBServer* server)
|
||||
return;
|
||||
}
|
||||
|
||||
MXS_MONITORED_SERVER* database = server->server_base;
|
||||
MXS_MONITORED_SERVER* database = server->m_server_base;
|
||||
int n_db = get_row_count(database, "SELECT schema_name FROM information_schema.schemata "
|
||||
"WHERE schema_name = 'maxscale_schema'");
|
||||
int n_tbl = get_row_count(database, "SELECT table_name FROM information_schema.tables "
|
||||
@ -707,7 +707,7 @@ void MariaDBMonitor::set_master_heartbeat(MariaDBServer* server)
|
||||
sprintf(heartbeat_insert_query,
|
||||
"UPDATE maxscale_schema.replication_heartbeat "
|
||||
"SET master_timestamp = %lu WHERE master_server_id = %li AND maxscale_id = %lu",
|
||||
heartbeat, m_master->server_base->server->node_id, m_id);
|
||||
heartbeat, m_master->m_server_base->server->node_id, m_id);
|
||||
|
||||
/* Try to insert MaxScale timestamp into master */
|
||||
if (mxs_mysql_query(database->con, heartbeat_insert_query))
|
||||
@ -727,7 +727,7 @@ void MariaDBMonitor::set_master_heartbeat(MariaDBServer* server)
|
||||
sprintf(heartbeat_insert_query,
|
||||
"REPLACE INTO maxscale_schema.replication_heartbeat "
|
||||
"(master_server_id, maxscale_id, master_timestamp ) VALUES ( %li, %lu, %lu)",
|
||||
m_master->server_base->server->node_id, m_id, heartbeat);
|
||||
m_master->m_server_base->server->node_id, m_id, heartbeat);
|
||||
|
||||
if (mxs_mysql_query(database->con, heartbeat_insert_query))
|
||||
{
|
||||
@ -783,9 +783,9 @@ void MariaDBMonitor::set_slave_heartbeat(MariaDBServer* server)
|
||||
sprintf(select_heartbeat_query, "SELECT master_timestamp "
|
||||
"FROM maxscale_schema.replication_heartbeat "
|
||||
"WHERE maxscale_id = %lu AND master_server_id = %li",
|
||||
m_id, m_master->server_base->server->node_id);
|
||||
m_id, m_master->m_server_base->server->node_id);
|
||||
|
||||
MXS_MONITORED_SERVER* database = server->server_base;
|
||||
MXS_MONITORED_SERVER* database = server->m_server_base;
|
||||
/* if there is a master then send the query to the slave with master_id */
|
||||
if (m_master != NULL && (mxs_mysql_query(database->con, select_heartbeat_query) == 0
|
||||
&& (result = mysql_store_result(database->con)) != NULL))
|
||||
@ -845,7 +845,7 @@ void MariaDBMonitor::set_slave_heartbeat(MariaDBServer* server)
|
||||
database->server->rlag = MAX_RLAG_NOT_AVAILABLE;
|
||||
database->server->node_ts = 0;
|
||||
|
||||
if (m_master->server_base->server->node_id < 0)
|
||||
if (m_master->m_server_base->server->node_id < 0)
|
||||
{
|
||||
MXS_ERROR("error: replication heartbeat: "
|
||||
"master_server_id NOT available for %s:%i",
|
||||
@ -1070,7 +1070,7 @@ string get_connection_errors(const ServerArray& servers)
|
||||
string separator;
|
||||
for (auto iter = servers.begin(); iter != servers.end(); iter++)
|
||||
{
|
||||
const char* error = mysql_error((*iter)->server_base->con);
|
||||
const char* error = mysql_error((*iter)->m_server_base->con);
|
||||
ss_dassert(*error); // Every connection should have an error.
|
||||
rval += separator + (*iter)->name() + ": '" + error + "'";
|
||||
separator = ", ";
|
||||
|
@ -38,19 +38,19 @@ SlaveStatus::SlaveStatus()
|
||||
{}
|
||||
|
||||
MariaDBServer::MariaDBServer(MXS_MONITORED_SERVER* monitored_server)
|
||||
: server_base(monitored_server)
|
||||
, version(MYSQL_SERVER_VERSION_51)
|
||||
, server_id(SERVER_ID_UNKNOWN)
|
||||
, group(0)
|
||||
, read_only(false)
|
||||
, slave_configured(false)
|
||||
, binlog_relay(false)
|
||||
, n_slaves_configured(0)
|
||||
, n_slaves_running(0)
|
||||
, slave_heartbeats(0)
|
||||
, heartbeat_period(0)
|
||||
, latest_event(0)
|
||||
, gtid_domain_id(-1)
|
||||
: m_server_base(monitored_server)
|
||||
, m_version(MYSQL_SERVER_VERSION_51)
|
||||
, m_server_id(SERVER_ID_UNKNOWN)
|
||||
, m_group(0)
|
||||
, m_read_only(false)
|
||||
, m_slave_configured(false)
|
||||
, m_binlog_relay(false)
|
||||
, m_n_slaves_configured(0)
|
||||
, m_n_slaves_running(0)
|
||||
, m_n_slave_heartbeats(0)
|
||||
, m_heartbeat_period(0)
|
||||
, m_latest_event(0)
|
||||
, m_gtid_domain_id(-1)
|
||||
{
|
||||
ss_dassert(monitored_server);
|
||||
}
|
||||
@ -61,13 +61,13 @@ int64_t MariaDBServer::relay_log_events()
|
||||
* rare but is possible (I guess?) if the server is replicating a domain from multiple masters
|
||||
* and decides to process events from one relay log before getting new events to the other. In
|
||||
* any case, such events are obsolete and the server can be considered to have processed such logs. */
|
||||
return GtidList::events_ahead(slave_status.gtid_io_pos, gtid_current_pos,
|
||||
return GtidList::events_ahead(m_slave_status.gtid_io_pos, m_gtid_current_pos,
|
||||
GtidList::MISSING_DOMAIN_LHS_ADD);
|
||||
}
|
||||
|
||||
std::auto_ptr<QueryResult> MariaDBServer::execute_query(const string& query)
|
||||
{
|
||||
auto conn = server_base->con;
|
||||
auto conn = m_server_base->con;
|
||||
std::auto_ptr<QueryResult> rval;
|
||||
MYSQL_RES *result = NULL;
|
||||
if (mxs_mysql_query(conn, query.c_str()) == 0 && (result = mysql_store_result(conn)) != NULL)
|
||||
@ -76,7 +76,7 @@ std::auto_ptr<QueryResult> MariaDBServer::execute_query(const string& query)
|
||||
}
|
||||
else
|
||||
{
|
||||
mon_report_query_error(server_base);
|
||||
mon_report_query_error(m_server_base);
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
@ -85,7 +85,7 @@ bool MariaDBServer::do_show_slave_status()
|
||||
{
|
||||
unsigned int columns = 0;
|
||||
string query;
|
||||
switch (version)
|
||||
switch (m_version)
|
||||
{
|
||||
case MYSQL_SERVER_VERSION_100:
|
||||
columns = 42;
|
||||
@ -139,7 +139,7 @@ bool MariaDBServer::do_show_slave_status()
|
||||
|
||||
int64_t i_slave_rec_hbs = -1, i_slave_hb_period = -1;
|
||||
int64_t i_using_gtid = -1, i_gtid_io_pos = -1;
|
||||
if (version == MYSQL_SERVER_VERSION_100)
|
||||
if (m_version == MYSQL_SERVER_VERSION_100)
|
||||
{
|
||||
i_slave_rec_hbs = result->get_col_index("Slave_received_heartbeats");
|
||||
i_slave_hb_period = result->get_col_index("Slave_heartbeat_period");
|
||||
@ -158,33 +158,33 @@ bool MariaDBServer::do_show_slave_status()
|
||||
while (result->next_row())
|
||||
{
|
||||
nconfigured++;
|
||||
slave_status.master_host = result->get_string(i_master_host);
|
||||
slave_status.master_port = result->get_uint(i_master_port);
|
||||
m_slave_status.master_host = result->get_string(i_master_host);
|
||||
m_slave_status.master_port = result->get_uint(i_master_port);
|
||||
string last_io_error = result->get_string(i_last_io_error);
|
||||
string last_sql_error = result->get_string(i_last_sql_error);
|
||||
slave_status.last_error = !last_io_error.empty() ? last_io_error : last_sql_error;
|
||||
m_slave_status.last_error = !last_io_error.empty() ? last_io_error : last_sql_error;
|
||||
|
||||
/* get Slave_IO_Running and Slave_SQL_Running values*/
|
||||
slave_status.slave_io_running =
|
||||
m_slave_status.slave_io_running =
|
||||
SlaveStatus::slave_io_from_string(result->get_string(i_slave_io_running));
|
||||
slave_status.slave_sql_running = (result->get_string(i_slave_sql_running) == "Yes");
|
||||
m_slave_status.slave_sql_running = (result->get_string(i_slave_sql_running) == "Yes");
|
||||
|
||||
if (slave_status.slave_io_running == SlaveStatus::SLAVE_IO_YES && slave_status.slave_sql_running)
|
||||
if (m_slave_status.slave_io_running == SlaveStatus::SLAVE_IO_YES && m_slave_status.slave_sql_running)
|
||||
{
|
||||
if (nrunning == 0)
|
||||
{
|
||||
/** Only check binlog name for the first running slave */
|
||||
string master_log_file = result->get_string(i_master_log_file);
|
||||
uint64_t read_master_log_pos = result->get_uint(i_read_master_log_pos);
|
||||
if (slave_status.master_log_file != master_log_file ||
|
||||
slave_status.read_master_log_pos != read_master_log_pos)
|
||||
if (m_slave_status.master_log_file != master_log_file ||
|
||||
m_slave_status.read_master_log_pos != read_master_log_pos)
|
||||
{
|
||||
// IO thread is reading events from the master
|
||||
latest_event = time(NULL);
|
||||
m_latest_event = time(NULL);
|
||||
}
|
||||
|
||||
slave_status.master_log_file = master_log_file;
|
||||
slave_status.read_master_log_pos = read_master_log_pos;
|
||||
m_slave_status.master_log_file = master_log_file;
|
||||
m_slave_status.read_master_log_pos = read_master_log_pos;
|
||||
}
|
||||
nrunning++;
|
||||
}
|
||||
@ -198,7 +198,7 @@ bool MariaDBServer::do_show_slave_status()
|
||||
int io_errno = last_io_errno;
|
||||
const int connection_errno = 2003;
|
||||
|
||||
if ((io_errno == 0 || io_errno == connection_errno) && version != MYSQL_SERVER_VERSION_51)
|
||||
if ((io_errno == 0 || io_errno == connection_errno) && m_version != MYSQL_SERVER_VERSION_51)
|
||||
{
|
||||
/* Get Master_Server_Id */
|
||||
auto parsed = result->get_uint(i_master_server_id);
|
||||
@ -208,44 +208,44 @@ bool MariaDBServer::do_show_slave_status()
|
||||
}
|
||||
}
|
||||
|
||||
if (version == MYSQL_SERVER_VERSION_100)
|
||||
if (m_version == MYSQL_SERVER_VERSION_100)
|
||||
{
|
||||
int heartbeats = result->get_uint(i_slave_rec_hbs);
|
||||
if (slave_heartbeats < heartbeats)
|
||||
if (m_n_slave_heartbeats < heartbeats)
|
||||
{
|
||||
latest_event = time(NULL);
|
||||
slave_heartbeats = heartbeats;
|
||||
heartbeat_period = result->get_uint(i_slave_hb_period);
|
||||
m_latest_event = time(NULL);
|
||||
m_n_slave_heartbeats = heartbeats;
|
||||
m_heartbeat_period = result->get_uint(i_slave_hb_period);
|
||||
}
|
||||
string using_gtid = result->get_string(i_using_gtid);
|
||||
string gtid_io_pos = result->get_string(i_gtid_io_pos);
|
||||
if (!gtid_io_pos.empty() &&
|
||||
(using_gtid == "Current_Pos" || using_gtid == "Slave_Pos"))
|
||||
{
|
||||
slave_status.gtid_io_pos = GtidList::from_string(gtid_io_pos);
|
||||
m_slave_status.gtid_io_pos = GtidList::from_string(gtid_io_pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
slave_status.gtid_io_pos = GtidList();
|
||||
m_slave_status.gtid_io_pos = GtidList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nconfigured > 0)
|
||||
{
|
||||
slave_configured = true;
|
||||
m_slave_configured = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Query returned no rows, replication is not configured */
|
||||
slave_configured = false;
|
||||
slave_heartbeats = 0;
|
||||
slave_status = SlaveStatus();
|
||||
m_slave_configured = false;
|
||||
m_n_slave_heartbeats = 0;
|
||||
m_slave_status = SlaveStatus();
|
||||
}
|
||||
|
||||
slave_status.master_server_id = master_server_id;
|
||||
n_slaves_configured = nconfigured;
|
||||
n_slaves_running = nrunning;
|
||||
m_slave_status.master_server_id = master_server_id;
|
||||
m_n_slaves_configured = nconfigured;
|
||||
m_n_slaves_running = nrunning;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -265,22 +265,22 @@ bool MariaDBServer::update_gtids()
|
||||
bool binlog_ok = false;
|
||||
if (current_str.empty())
|
||||
{
|
||||
gtid_current_pos = GtidList();
|
||||
m_gtid_current_pos = GtidList();
|
||||
}
|
||||
else
|
||||
{
|
||||
gtid_current_pos = GtidList::from_string(current_str);
|
||||
current_ok = !gtid_current_pos.empty();
|
||||
m_gtid_current_pos = GtidList::from_string(current_str);
|
||||
current_ok = !m_gtid_current_pos.empty();
|
||||
}
|
||||
|
||||
if (binlog_str.empty())
|
||||
{
|
||||
gtid_binlog_pos = GtidList();
|
||||
m_gtid_binlog_pos = GtidList();
|
||||
}
|
||||
else
|
||||
{
|
||||
gtid_binlog_pos = GtidList::from_string(binlog_str);
|
||||
binlog_ok = !gtid_binlog_pos.empty();
|
||||
m_gtid_binlog_pos = GtidList::from_string(binlog_str);
|
||||
binlog_ok = !m_gtid_binlog_pos.empty();
|
||||
}
|
||||
|
||||
rval = (current_ok && binlog_ok);
|
||||
@ -295,9 +295,9 @@ bool MariaDBServer::update_replication_settings()
|
||||
auto result = execute_query(query);
|
||||
if (result.get() != NULL && result->next_row())
|
||||
{
|
||||
rpl_settings.gtid_strict_mode = result->get_bool(0);
|
||||
rpl_settings.log_bin = result->get_bool(1);
|
||||
rpl_settings.log_slave_updates = result->get_bool(2);
|
||||
m_rpl_settings.gtid_strict_mode = result->get_bool(0);
|
||||
m_rpl_settings.log_bin = result->get_bool(1);
|
||||
m_rpl_settings.log_slave_updates = result->get_bool(2);
|
||||
rval = true;
|
||||
}
|
||||
return rval;
|
||||
@ -305,10 +305,10 @@ bool MariaDBServer::update_replication_settings()
|
||||
|
||||
void MariaDBServer::read_server_variables()
|
||||
{
|
||||
MXS_MONITORED_SERVER* database = server_base;
|
||||
MXS_MONITORED_SERVER* database = m_server_base;
|
||||
string query = "SELECT @@global.server_id, @@read_only;";
|
||||
int columns = 2;
|
||||
if (version == MYSQL_SERVER_VERSION_100)
|
||||
if (m_version == MYSQL_SERVER_VERSION_100)
|
||||
{
|
||||
query.erase(query.end() - 1);
|
||||
query += ", @@global.gtid_domain_id;";
|
||||
@ -327,11 +327,11 @@ void MariaDBServer::read_server_variables()
|
||||
server_id_parsed = SERVER_ID_UNKNOWN;
|
||||
}
|
||||
database->server->node_id = server_id_parsed;
|
||||
server_id = server_id_parsed;
|
||||
read_only = result->get_bool(i_ro);
|
||||
m_server_id = server_id_parsed;
|
||||
m_read_only = result->get_bool(i_ro);
|
||||
if (columns == 3)
|
||||
{
|
||||
gtid_domain_id = result->get_uint(i_domain);
|
||||
m_gtid_domain_id = result->get_uint(i_domain);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -340,7 +340,7 @@ bool MariaDBServer::check_replication_settings(print_repl_warnings_t print_warni
|
||||
{
|
||||
bool rval = true;
|
||||
const char* servername = name();
|
||||
if (rpl_settings.log_bin == false)
|
||||
if (m_rpl_settings.log_bin == false)
|
||||
{
|
||||
if (print_warnings == WARNINGS_ON)
|
||||
{
|
||||
@ -352,14 +352,14 @@ bool MariaDBServer::check_replication_settings(print_repl_warnings_t print_warni
|
||||
}
|
||||
else if (print_warnings == WARNINGS_ON)
|
||||
{
|
||||
if (rpl_settings.gtid_strict_mode == false)
|
||||
if (m_rpl_settings.gtid_strict_mode == false)
|
||||
{
|
||||
const char NO_STRICT[] =
|
||||
"Slave '%s' has gtid_strict_mode disabled. Enabling this setting is recommended. "
|
||||
"For more information, see https://mariadb.com/kb/en/library/gtid/#gtid_strict_mode";
|
||||
MXS_WARNING(NO_STRICT, servername);
|
||||
}
|
||||
if (rpl_settings.log_slave_updates == false)
|
||||
if (m_rpl_settings.log_slave_updates == false)
|
||||
{
|
||||
const char NO_SLAVE_UPDATES[] =
|
||||
"Slave '%s' has log_slave_updates disabled. It is a valid candidate but replication "
|
||||
@ -376,7 +376,7 @@ bool MariaDBServer::wait_until_gtid(const GtidList& target, int timeout, json_t*
|
||||
bool error = false;
|
||||
/* Prefer to use gtid_binlog_pos, as that is more reliable. But if log_slave_updates is not on,
|
||||
* use gtid_current_pos. */
|
||||
const bool use_binlog_pos = rpl_settings.log_bin && rpl_settings.log_slave_updates;
|
||||
const bool use_binlog_pos = m_rpl_settings.log_bin && m_rpl_settings.log_slave_updates;
|
||||
|
||||
int seconds_remaining = 1; // Cheat a bit here to allow at least one iteration.
|
||||
int sleep_ms = 200; // How long to sleep on next iteration. Incremented slowly.
|
||||
@ -385,7 +385,7 @@ bool MariaDBServer::wait_until_gtid(const GtidList& target, int timeout, json_t*
|
||||
{
|
||||
if (update_gtids())
|
||||
{
|
||||
const GtidList& compare_to = use_binlog_pos ? gtid_binlog_pos : gtid_current_pos;
|
||||
const GtidList& compare_to = use_binlog_pos ? m_gtid_binlog_pos : m_gtid_current_pos;
|
||||
if (GtidList::events_ahead(target, compare_to, GtidList::MISSING_DOMAIN_IGNORE) == 0)
|
||||
{
|
||||
gtid_reached = true;
|
||||
@ -422,60 +422,60 @@ bool MariaDBServer::wait_until_gtid(const GtidList& target, int timeout, json_t*
|
||||
|
||||
bool MariaDBServer::is_master() const
|
||||
{
|
||||
return SERVER_IS_MASTER(server_base->server);
|
||||
return SERVER_IS_MASTER(m_server_base->server);
|
||||
}
|
||||
|
||||
bool MariaDBServer::is_slave() const
|
||||
{
|
||||
return SERVER_IS_SLAVE(server_base->server);
|
||||
return SERVER_IS_SLAVE(m_server_base->server);
|
||||
}
|
||||
|
||||
bool MariaDBServer::is_running() const
|
||||
{
|
||||
return SERVER_IS_RUNNING(server_base->server);
|
||||
return SERVER_IS_RUNNING(m_server_base->server);
|
||||
}
|
||||
|
||||
bool MariaDBServer::is_down() const
|
||||
{
|
||||
return SERVER_IS_DOWN(server_base->server);
|
||||
return SERVER_IS_DOWN(m_server_base->server);
|
||||
}
|
||||
|
||||
const char* MariaDBServer::name() const
|
||||
{
|
||||
return server_base->server->unique_name;
|
||||
return m_server_base->server->unique_name;
|
||||
}
|
||||
|
||||
string MariaDBServer::diagnostics(bool multimaster) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Server: " << name() << "\n";
|
||||
ss << "Server ID: " << server_id << "\n";
|
||||
ss << "Read only: " << (read_only ? "YES" : "NO") << "\n";
|
||||
ss << "Slave configured: " << (slave_configured ? "YES" : "NO") << "\n";
|
||||
if (slave_configured)
|
||||
ss << "Server ID: " << m_server_id << "\n";
|
||||
ss << "Read only: " << (m_read_only ? "YES" : "NO") << "\n";
|
||||
ss << "Slave configured: " << (m_slave_configured ? "YES" : "NO") << "\n";
|
||||
if (m_slave_configured)
|
||||
{
|
||||
ss << "Slave IO running: " <<
|
||||
SlaveStatus::slave_io_to_string(slave_status.slave_io_running) << "\n";
|
||||
ss << "Slave SQL running: " << (slave_status.slave_sql_running ? "YES" : "NO") << "\n";
|
||||
ss << "Master ID: " << slave_status.master_server_id << "\n";
|
||||
ss << "Master binlog file: " << slave_status.master_log_file << "\n";
|
||||
ss << "Master binlog position: " << slave_status.read_master_log_pos << "\n";
|
||||
SlaveStatus::slave_io_to_string(m_slave_status.slave_io_running) << "\n";
|
||||
ss << "Slave SQL running: " << (m_slave_status.slave_sql_running ? "YES" : "NO") << "\n";
|
||||
ss << "Master ID: " << m_slave_status.master_server_id << "\n";
|
||||
ss << "Master binlog file: " << m_slave_status.master_log_file << "\n";
|
||||
ss << "Master binlog position: " << m_slave_status.read_master_log_pos << "\n";
|
||||
}
|
||||
if (!gtid_current_pos.empty())
|
||||
if (!m_gtid_current_pos.empty())
|
||||
{
|
||||
ss << "Gtid current position: " << gtid_current_pos.to_string() << "\n";
|
||||
ss << "Gtid current position: " << m_gtid_current_pos.to_string() << "\n";
|
||||
}
|
||||
if (!gtid_binlog_pos.empty())
|
||||
if (!m_gtid_binlog_pos.empty())
|
||||
{
|
||||
ss << "Gtid binlog position: " << gtid_binlog_pos.to_string() << "\n";
|
||||
ss << "Gtid binlog position: " << m_gtid_binlog_pos.to_string() << "\n";
|
||||
}
|
||||
if (!slave_status.gtid_io_pos.empty())
|
||||
if (!m_slave_status.gtid_io_pos.empty())
|
||||
{
|
||||
ss << "Gtid slave IO position: " << slave_status.gtid_io_pos.to_string() << "\n";
|
||||
ss << "Gtid slave IO position: " << m_slave_status.gtid_io_pos.to_string() << "\n";
|
||||
}
|
||||
if (multimaster)
|
||||
{
|
||||
ss << "Master group: " << group << "\n";
|
||||
ss << "Master group: " << m_group << "\n";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
@ -484,30 +484,30 @@ json_t* MariaDBServer::diagnostics_json(bool multimaster) const
|
||||
{
|
||||
json_t* srv = json_object();
|
||||
json_object_set_new(srv, "name", json_string(name()));
|
||||
json_object_set_new(srv, "server_id", json_integer(server_id));
|
||||
json_object_set_new(srv, "master_id", json_integer(slave_status.master_server_id));
|
||||
json_object_set_new(srv, "server_id", json_integer(m_server_id));
|
||||
json_object_set_new(srv, "master_id", json_integer(m_slave_status.master_server_id));
|
||||
|
||||
json_object_set_new(srv, "read_only", json_boolean(read_only));
|
||||
json_object_set_new(srv, "slave_configured", json_boolean(slave_configured));
|
||||
json_object_set_new(srv, "read_only", json_boolean(m_read_only));
|
||||
json_object_set_new(srv, "slave_configured", json_boolean(m_slave_configured));
|
||||
json_object_set_new(srv, "slave_io_running",
|
||||
json_string(SlaveStatus::slave_io_to_string(slave_status.slave_io_running).c_str()));
|
||||
json_object_set_new(srv, "slave_sql_running", json_boolean(slave_status.slave_sql_running));
|
||||
json_string(SlaveStatus::slave_io_to_string(m_slave_status.slave_io_running).c_str()));
|
||||
json_object_set_new(srv, "slave_sql_running", json_boolean(m_slave_status.slave_sql_running));
|
||||
|
||||
json_object_set_new(srv, "master_binlog_file", json_string(slave_status.master_log_file.c_str()));
|
||||
json_object_set_new(srv, "master_binlog_position", json_integer(slave_status.read_master_log_pos));
|
||||
json_object_set_new(srv, "gtid_current_pos", json_string(gtid_current_pos.to_string().c_str()));
|
||||
json_object_set_new(srv, "gtid_binlog_pos", json_string(gtid_binlog_pos.to_string().c_str()));
|
||||
json_object_set_new(srv, "gtid_io_pos", json_string(slave_status.gtid_io_pos.to_string().c_str()));
|
||||
json_object_set_new(srv, "master_binlog_file", json_string(m_slave_status.master_log_file.c_str()));
|
||||
json_object_set_new(srv, "master_binlog_position", json_integer(m_slave_status.read_master_log_pos));
|
||||
json_object_set_new(srv, "gtid_current_pos", json_string(m_gtid_current_pos.to_string().c_str()));
|
||||
json_object_set_new(srv, "gtid_binlog_pos", json_string(m_gtid_binlog_pos.to_string().c_str()));
|
||||
json_object_set_new(srv, "gtid_io_pos", json_string(m_slave_status.gtid_io_pos.to_string().c_str()));
|
||||
if (multimaster)
|
||||
{
|
||||
json_object_set_new(srv, "master_group", json_integer(group));
|
||||
json_object_set_new(srv, "master_group", json_integer(m_group));
|
||||
}
|
||||
return srv;
|
||||
}
|
||||
|
||||
bool MariaDBServer::uses_gtid(json_t** error_out)
|
||||
{
|
||||
bool using_gtid = !slave_status.gtid_io_pos.empty();
|
||||
bool using_gtid = !m_slave_status.gtid_io_pos.empty();
|
||||
if (!using_gtid)
|
||||
{
|
||||
string slave_not_gtid_msg = string("Slave server ") + name() + " is not using gtid replication.";
|
||||
@ -518,7 +518,7 @@ bool MariaDBServer::uses_gtid(json_t** error_out)
|
||||
|
||||
bool MariaDBServer::update_slave_info()
|
||||
{
|
||||
return (slave_status.slave_sql_running && update_replication_settings() &&
|
||||
return (m_slave_status.slave_sql_running && update_replication_settings() &&
|
||||
update_gtids() && do_show_slave_status());
|
||||
}
|
||||
|
||||
@ -527,7 +527,7 @@ bool MariaDBServer::can_replicate_from(MariaDBServer* master)
|
||||
bool rval = false;
|
||||
if (update_gtids())
|
||||
{
|
||||
rval = gtid_current_pos.can_replicate_from(master->gtid_binlog_pos);
|
||||
rval = m_gtid_current_pos.can_replicate_from(master->m_gtid_binlog_pos);
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
@ -535,7 +535,7 @@ bool MariaDBServer::can_replicate_from(MariaDBServer* master)
|
||||
bool MariaDBServer::redirect_one_slave(const string& change_cmd)
|
||||
{
|
||||
bool success = false;
|
||||
MYSQL* slave_conn = server_base->con;
|
||||
MYSQL* slave_conn = m_server_base->con;
|
||||
const char* query = "STOP SLAVE;";
|
||||
if (mxs_mysql_query(slave_conn, query) == 0)
|
||||
{
|
||||
@ -569,7 +569,7 @@ bool MariaDBServer::join_cluster(const string& change_cmd)
|
||||
* replication may end up broken. */
|
||||
bool success = false;
|
||||
string error_msg;
|
||||
MYSQL* server_conn = server_base->con;
|
||||
MYSQL* server_conn = m_server_base->con;
|
||||
const char* query = "SET GLOBAL read_only=1;";
|
||||
if (mxs_mysql_query(server_conn, query) == 0)
|
||||
{
|
||||
@ -618,11 +618,11 @@ bool MariaDBServer::failover_wait_relay_log(int seconds_remaining, json_t** err_
|
||||
name(), relay_log_events());
|
||||
thread_millisleep(1000); // Sleep for a while before querying server again.
|
||||
// Todo: check server version before entering failover.
|
||||
GtidList old_gtid_io_pos = slave_status.gtid_io_pos;
|
||||
GtidList old_gtid_io_pos = m_slave_status.gtid_io_pos;
|
||||
// Update gtid:s first to make sure Gtid_IO_Pos is the more recent value.
|
||||
// It doesn't matter here, but is a general rule.
|
||||
query_ok = update_gtids() && do_show_slave_status();
|
||||
io_pos_stable = (old_gtid_io_pos == slave_status.gtid_io_pos);
|
||||
io_pos_stable = (old_gtid_io_pos == m_slave_status.gtid_io_pos);
|
||||
}
|
||||
|
||||
bool rval = false;
|
||||
@ -643,8 +643,8 @@ bool MariaDBServer::failover_wait_relay_log(int seconds_remaining, json_t** err_
|
||||
}
|
||||
else if (relay_log_events() < 0) // TODO: This is currently impossible
|
||||
{
|
||||
reason = "Invalid Gtid(s) (current_pos: " + gtid_current_pos.to_string() +
|
||||
", io_pos: " + slave_status.gtid_io_pos.to_string() + ")";
|
||||
reason = "Invalid Gtid(s) (current_pos: " + m_gtid_current_pos.to_string() +
|
||||
", io_pos: " + m_slave_status.gtid_io_pos.to_string() + ")";
|
||||
}
|
||||
PRINT_MXS_JSON_ERROR(err_out, "Failover: %s while waiting for server '%s' to process relay log. "
|
||||
"Cancelling failover.", reason.c_str(), name());
|
||||
@ -655,7 +655,7 @@ bool MariaDBServer::failover_wait_relay_log(int seconds_remaining, json_t** err_
|
||||
|
||||
bool MariaDBServer::run_sql_from_file(const string& path, json_t** error_out)
|
||||
{
|
||||
MYSQL* conn = server_base->con;
|
||||
MYSQL* conn = m_server_base->con;
|
||||
bool error = false;
|
||||
std::ifstream sql_file(path);
|
||||
if (sql_file.is_open())
|
||||
|
@ -83,27 +83,27 @@ public:
|
||||
class MariaDBServer
|
||||
{
|
||||
public:
|
||||
MXS_MONITORED_SERVER* server_base; /**< Monitored server base class/struct. MariaDBServer does not
|
||||
MXS_MONITORED_SERVER* m_server_base; /**< Monitored server base class/struct. MariaDBServer does not
|
||||
* own the struct, it is not freed (or connection closed) when
|
||||
* a MariaDBServer is destroyed. Can be const on gcc 4.8 */
|
||||
mysql_server_version version; /**< Server version, 10.X, 5.5 or 5.1 */
|
||||
int64_t server_id; /**< Value of @@server_id. Valid values are 32bit unsigned. */
|
||||
int group; /**< Multi-master group where this server belongs,
|
||||
mysql_server_version m_version; /**< Server version, 10.X, 5.5 or 5.1 */
|
||||
int64_t m_server_id; /**< Value of @@server_id. Valid values are 32bit unsigned. */
|
||||
int m_group; /**< Multi-master group where this server belongs,
|
||||
* 0 for servers not in groups */
|
||||
bool read_only; /**< Value of @@read_only */
|
||||
bool slave_configured; /**< Whether SHOW SLAVE STATUS returned rows */
|
||||
bool binlog_relay; /** Server is a Binlog Relay */
|
||||
int n_slaves_configured; /**< Number of configured slave connections*/
|
||||
int n_slaves_running; /**< Number of running slave connections */
|
||||
int slave_heartbeats; /**< Number of received heartbeats */
|
||||
double heartbeat_period; /**< The time interval between heartbeats */
|
||||
time_t latest_event; /**< Time when latest event was received from the master */
|
||||
int64_t gtid_domain_id; /**< The value of gtid_domain_id, the domain which is used for
|
||||
bool m_read_only; /**< Value of @@read_only */
|
||||
bool m_slave_configured; /**< Whether SHOW SLAVE STATUS returned rows */
|
||||
bool m_binlog_relay; /** Server is a Binlog Relay */
|
||||
int m_n_slaves_configured; /**< Number of configured slave connections*/
|
||||
int m_n_slaves_running; /**< Number of running slave connections */
|
||||
int m_n_slave_heartbeats; /**< Number of received heartbeats */
|
||||
double m_heartbeat_period; /**< The time interval between heartbeats */
|
||||
time_t m_latest_event; /**< Time when latest event was received from the master */
|
||||
int64_t m_gtid_domain_id; /**< The value of gtid_domain_id, the domain which is used for
|
||||
* new non-replicated events. */
|
||||
GtidList gtid_current_pos; /**< Gtid of latest event. */
|
||||
GtidList gtid_binlog_pos; /**< Gtid of latest event written to binlog. */
|
||||
SlaveStatus slave_status; /**< Data returned from SHOW SLAVE STATUS */
|
||||
ReplicationSettings rpl_settings; /**< Miscellaneous replication related settings */
|
||||
GtidList m_gtid_current_pos; /**< Gtid of latest event. */
|
||||
GtidList m_gtid_binlog_pos; /**< Gtid of latest event written to binlog. */
|
||||
SlaveStatus m_slave_status; /**< Data returned from SHOW SLAVE STATUS */
|
||||
ReplicationSettings m_rpl_settings; /**< Miscellaneous replication related settings */
|
||||
|
||||
MariaDBServer(MXS_MONITORED_SERVER* monitored_server);
|
||||
|
||||
|
Reference in New Issue
Block a user