Avoid using obsolete functions in reset-replication
Removes some duplicate functions.
This commit is contained in:
@ -354,15 +354,35 @@ bool MariaDBMonitor::manual_reset_replication(SERVER* master_server, json_t** er
|
|||||||
|
|
||||||
// Step 7: Set all slaves to replicate from the master.
|
// Step 7: Set all slaves to replicate from the master.
|
||||||
// The following commands are only sent to slaves.
|
// The following commands are only sent to slaves.
|
||||||
auto location = std::find(targets.begin(), targets.end(), new_master);
|
ServerArray slaves;
|
||||||
targets.erase(location);
|
for (auto target : targets)
|
||||||
|
|
||||||
// TODO: the following call does stop slave & reset slave again. Fix this later, although it
|
|
||||||
// doesn't cause error.
|
|
||||||
ServerArray dummy;
|
|
||||||
if ((size_t)redirect_slaves(new_master, targets, &dummy) == targets.size())
|
|
||||||
{
|
{
|
||||||
// TODO: Properly check check slave IO/SQL threads.
|
if (target != new_master)
|
||||||
|
{
|
||||||
|
slaves.push_back(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!slaves.empty())
|
||||||
|
{
|
||||||
|
SlaveStatus new_conn;
|
||||||
|
SERVER* new_master_srv = new_master->m_server_base->server;
|
||||||
|
new_conn.master_host = new_master_srv->address;
|
||||||
|
new_conn.master_port = new_master_srv->port;
|
||||||
|
GeneralOpData general(error_out, mxb::Duration(0.0)); // Expect this to complete quickly.
|
||||||
|
size_t slave_conns_started = 0;
|
||||||
|
for (auto slave : slaves)
|
||||||
|
{
|
||||||
|
if (slave->create_start_slave(general, new_conn))
|
||||||
|
{
|
||||||
|
slave_conns_started++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerArray dummy;
|
||||||
|
if (slave_conns_started == slaves.size())
|
||||||
|
{
|
||||||
|
// TODO: Properly check slave IO/SQL threads.
|
||||||
MXS_NOTICE("All slaves redirected successfully.");
|
MXS_NOTICE("All slaves redirected successfully.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -372,6 +392,7 @@ bool MariaDBMonitor::manual_reset_replication(SERVER* master_server, json_t** er
|
|||||||
"Some servers were not redirected to '%s'.", new_master->name());
|
"Some servers were not redirected to '%s'.", new_master->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error = true;
|
error = true;
|
||||||
@ -420,33 +441,6 @@ string MariaDBMonitor::generate_change_master_cmd(const string& master_host, int
|
|||||||
return change_cmd.str();
|
return change_cmd.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirects slaves to replicate from another master server.
|
|
||||||
*
|
|
||||||
* @param new_master The replication master
|
|
||||||
* @param slaves An array of slaves
|
|
||||||
* @param redirected_slaves A vector where to insert successfully redirected slaves.
|
|
||||||
* @return The number of slaves successfully redirected.
|
|
||||||
*/
|
|
||||||
int MariaDBMonitor::redirect_slaves(MariaDBServer* new_master, const ServerArray& slaves,
|
|
||||||
ServerArray* redirected_slaves)
|
|
||||||
{
|
|
||||||
mxb_assert(redirected_slaves != NULL);
|
|
||||||
MXS_NOTICE("Redirecting slaves to new master.");
|
|
||||||
string change_cmd = generate_change_master_cmd(new_master->m_server_base->server->address,
|
|
||||||
new_master->m_server_base->server->port);
|
|
||||||
int successes = 0;
|
|
||||||
for (MariaDBServer* slave : slaves)
|
|
||||||
{
|
|
||||||
if (slave->redirect_one_slave(change_cmd))
|
|
||||||
{
|
|
||||||
successes++;
|
|
||||||
redirected_slaves->push_back(slave);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return successes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect slave connections from the promotion target to replicate from the demotion target and vice versa.
|
* Redirect slave connections from the promotion target to replicate from the demotion target and vice versa.
|
||||||
*
|
*
|
||||||
|
@ -329,8 +329,7 @@ private:
|
|||||||
int* id_missing_out) const;
|
int* id_missing_out) const;
|
||||||
|
|
||||||
ServerArray get_redirectables(const MariaDBServer* old_master, const MariaDBServer* ignored_slave);
|
ServerArray get_redirectables(const MariaDBServer* old_master, const MariaDBServer* ignored_slave);
|
||||||
int redirect_slaves(MariaDBServer* new_master, const ServerArray& slaves,
|
|
||||||
ServerArray* redirected_slaves);
|
|
||||||
int redirect_slaves_ex(GeneralOpData& op,
|
int redirect_slaves_ex(GeneralOpData& op,
|
||||||
OperationType type,
|
OperationType type,
|
||||||
const MariaDBServer* promotion_target,
|
const MariaDBServer* promotion_target,
|
||||||
|
@ -767,37 +767,6 @@ bool MariaDBServer::can_replicate_from(MariaDBServer* master, string* reason_out
|
|||||||
return can_replicate;
|
return can_replicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MariaDBServer::redirect_one_slave(const string& change_cmd)
|
|
||||||
{
|
|
||||||
bool success = false;
|
|
||||||
MYSQL* slave_conn = m_server_base->con;
|
|
||||||
const char* query = "STOP SLAVE;";
|
|
||||||
if (mxs_mysql_query(slave_conn, query) == 0)
|
|
||||||
{
|
|
||||||
query = "RESET SLAVE;"; // To erase any old I/O or SQL errors
|
|
||||||
if (mxs_mysql_query(slave_conn, query) == 0)
|
|
||||||
{
|
|
||||||
query = "CHANGE MASTER TO ..."; // Don't show the real query as it contains a password.
|
|
||||||
if (mxs_mysql_query(slave_conn, change_cmd.c_str()) == 0)
|
|
||||||
{
|
|
||||||
query = "START SLAVE;";
|
|
||||||
if (mxs_mysql_query(slave_conn, query) == 0)
|
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
MXS_NOTICE("Slave '%s' redirected to new master.", name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
MXS_WARNING("Slave '%s' redirection failed: '%s'. Query: '%s'.",
|
|
||||||
name(), mysql_error(slave_conn), query);
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MariaDBServer::run_sql_from_file(const string& path, json_t** error_out)
|
bool MariaDBServer::run_sql_from_file(const string& path, json_t** error_out)
|
||||||
{
|
{
|
||||||
MYSQL* conn = m_server_base->con;
|
MYSQL* conn = m_server_base->con;
|
||||||
|
@ -300,14 +300,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool can_replicate_from(MariaDBServer* master, std::string* reason_out);
|
bool can_replicate_from(MariaDBServer* master, std::string* reason_out);
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirect one slave server to another master
|
|
||||||
*
|
|
||||||
* @param change_cmd Change master command, usually generated by generate_change_master_cmd()
|
|
||||||
* @return True if slave accepted all commands
|
|
||||||
*/
|
|
||||||
bool redirect_one_slave(const std::string& change_cmd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the server can be demoted by switchover.
|
* Check if the server can be demoted by switchover.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user