Avoid using obsolete functions in reset-replication

Removes some duplicate functions.
This commit is contained in:
Esa Korhonen 2019-06-07 14:02:59 +03:00
parent 190c0ac634
commit b49aeae1c8
4 changed files with 35 additions and 81 deletions

View File

@ -354,22 +354,43 @@ bool MariaDBMonitor::manual_reset_replication(SERVER* master_server, json_t** er
// Step 7: Set all slaves to replicate from the master.
// The following commands are only sent to slaves.
auto location = std::find(targets.begin(), targets.end(), new_master);
targets.erase(location);
// 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())
ServerArray slaves;
for (auto target : targets)
{
// TODO: Properly check check slave IO/SQL threads.
MXS_NOTICE("All slaves redirected successfully.");
if (target != new_master)
{
slaves.push_back(target);
}
}
else
if (!slaves.empty())
{
error = true;
PRINT_MXS_JSON_ERROR(error_out,
"Some servers were not redirected to '%s'.", new_master->name());
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.");
}
else
{
error = true;
PRINT_MXS_JSON_ERROR(error_out,
"Some servers were not redirected to '%s'.", new_master->name());
}
}
}
else
@ -420,33 +441,6 @@ string MariaDBMonitor::generate_change_master_cmd(const string& master_host, int
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.
*

View File

@ -329,8 +329,7 @@ private:
int* id_missing_out) const;
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,
OperationType type,
const MariaDBServer* promotion_target,

View File

@ -767,37 +767,6 @@ bool MariaDBServer::can_replicate_from(MariaDBServer* master, string* reason_out
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)
{
MYSQL* conn = m_server_base->con;

View File

@ -300,14 +300,6 @@ public:
*/
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.
*