MXS-2441: Add galera with slaves test case
The test checks that servers replicating from Galera nodes work as expected.
This commit is contained in:
@ -946,6 +946,9 @@ add_test_executable(mxs2417_ignore_persisted_cnf.cpp mxs2417_ignore_persisted_cn
|
||||
# MXS-1662: PAM admin authentication
|
||||
add_test_executable(mxs1662_pam_admin.cpp mxs1662_pam_admin mxs1662_pam_admin LABELS REPL_BACKEND)
|
||||
|
||||
# MXS-2441: Add support for read-only slaves to galeramon
|
||||
add_test_executable(mxs2441_galera_slaves.cpp mxs2441_galera_slaves mxs2441_galera_slaves LABELS REPL_BACKEND GALERA_BACKEND)
|
||||
|
||||
############################################
|
||||
# BEGIN: binlogrouter and avrorouter tests #
|
||||
############################################
|
||||
|
||||
76
maxscale-system-test/cnf/maxscale.cnf.template.mxs2441_galera_slaves
Executable file
76
maxscale-system-test/cnf/maxscale.cnf.template.mxs2441_galera_slaves
Executable file
@ -0,0 +1,76 @@
|
||||
[maxscale]
|
||||
threads=###threads###
|
||||
|
||||
[server1]
|
||||
type=server
|
||||
address=###node_server_IP_1###
|
||||
port=###node_server_port_1###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server2]
|
||||
type=server
|
||||
address=###node_server_IP_2###
|
||||
port=###node_server_port_2###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server3]
|
||||
type=server
|
||||
address=###node_server_IP_3###
|
||||
port=###node_server_port_3###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server4]
|
||||
type=server
|
||||
address=###node_server_IP_4###
|
||||
port=###node_server_port_4###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[gserver1]
|
||||
type=server
|
||||
address=###galera_server_IP_1###
|
||||
port=###galera_server_port_1###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[gserver2]
|
||||
type=server
|
||||
address=###galera_server_IP_2###
|
||||
port=###galera_server_port_2###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[gserver3]
|
||||
type=server
|
||||
address=###galera_server_IP_3###
|
||||
port=###galera_server_port_3###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[gserver4]
|
||||
type=server
|
||||
address=###galera_server_IP_4###
|
||||
port=###galera_server_port_4###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[Galera-Monitor]
|
||||
type=monitor
|
||||
module=galeramon
|
||||
servers=server1,server2,server3,server4,gserver1,gserver2,gserver3,gserver4
|
||||
user=maxskysql
|
||||
password=skysql
|
||||
monitor_interval=1000
|
||||
|
||||
[Hint]
|
||||
type=filter
|
||||
module=hintfilter
|
||||
|
||||
[RW-Split-Router]
|
||||
type=service
|
||||
router=readwritesplit
|
||||
servers=server1,server2,server3,server4,gserver1,gserver2,gserver3,gserver4
|
||||
user=maxskysql
|
||||
password=skysql
|
||||
filters=Hint
|
||||
|
||||
[RW-Split-Listener]
|
||||
type=listener
|
||||
service=RW-Split-Router
|
||||
protocol=MySQLClient
|
||||
port=4006
|
||||
@ -1443,16 +1443,21 @@ int Mariadb_nodes::prepare_servers()
|
||||
}
|
||||
|
||||
void Mariadb_nodes::replicate_from(int slave, int master, const char* type)
|
||||
{
|
||||
replicate_from(slave, IP[master], port[master], type);
|
||||
}
|
||||
|
||||
void Mariadb_nodes::replicate_from(int slave, const std::string& host, uint16_t port, const char* type)
|
||||
{
|
||||
std::stringstream change_master;
|
||||
change_master << "CHANGE MASTER TO MASTER_HOST = '" << IP[master]
|
||||
<< "', MASTER_PORT = " << port[master] << ", MASTER_USE_GTID = " << type << ", "
|
||||
"MASTER_USER='repl', MASTER_PASSWORD='repl';";
|
||||
change_master << "CHANGE MASTER TO MASTER_HOST = '" << host
|
||||
<< "', MASTER_PORT = " << port << ", MASTER_USE_GTID = "
|
||||
<< type << ", MASTER_USER='repl', MASTER_PASSWORD='repl';";
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Server " << slave + 1 << " starting to replicate from server " << master + 1
|
||||
<< std::endl;
|
||||
std::cout << "Server " << slave + 1
|
||||
<< " starting to replicate from server " << master + 1 << std::endl;
|
||||
std::cout << "Query is '" << change_master.str() << "'" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@ -477,6 +477,9 @@ public:
|
||||
*/
|
||||
void replicate_from(int slave, int master, const char* type = "current_pos");
|
||||
|
||||
// Replicates from a host and a port instead of a known server
|
||||
void replicate_from(int slave, const std::string& host, uint16_t port, const char* type = "current_pos");
|
||||
|
||||
private:
|
||||
|
||||
bool check_master_node(MYSQL* conn);
|
||||
|
||||
64
maxscale-system-test/mxs2441_galera_slaves.cpp
Normal file
64
maxscale-system-test/mxs2441_galera_slaves.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* MXS-2441: Add support for read-only slaves to galeramon
|
||||
* https://jira.mariadb.org/browse/MXS-2441
|
||||
*/
|
||||
|
||||
#include "testconnections.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <maxbase/string.hh>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
TestConnections test(argc, argv);
|
||||
test.repl->connect();
|
||||
test.galera->connect();
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
test.repl->replicate_from(i, test.galera->ip(0), test.galera->port[0]);
|
||||
}
|
||||
|
||||
test.maxscales->wait_for_monitor();
|
||||
|
||||
auto output = mxb::strtok(test.maxctrl("list servers").second, "\n");
|
||||
int n_slaves = std::count_if(output.begin(), output.end(), [](const std::string& line) {
|
||||
return line.find("Slave") != std::string::npos;
|
||||
});
|
||||
int n_masters = std::count_if(output.begin(), output.end(), [](const std::string& line) {
|
||||
return line.find("Master") != std::string::npos;
|
||||
});
|
||||
int n_synced = std::count_if(output.begin(), output.end(), [](const std::string& line) {
|
||||
return line.find("Synced") != std::string::npos;
|
||||
});
|
||||
|
||||
test.expect(n_slaves == 7, "Expected 7 slaves but got %d", n_slaves);
|
||||
test.expect(n_masters == 1, "Expected 1 master but got %d", n_masters);
|
||||
test.expect(n_synced == 4, "Expected 4 synced but got %d", n_synced);
|
||||
|
||||
// Check that the queries are routed to the right server
|
||||
auto repl_ids = test.repl->get_all_server_ids_str();
|
||||
auto galera_ids = test.galera->get_all_server_ids_str();
|
||||
auto c = test.maxscales->rwsplit();
|
||||
test.expect(c.connect(), "Could not connect to maxscale: %s", c.error());
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
std::string q = "SELECT @@server_id -- maxscale route to server server" + std::to_string(i + 1);
|
||||
auto res = c.field(q);
|
||||
test.expect(res == repl_ids[i], "Wrong ID: %s(rwsplit) != %s(server)",
|
||||
res.c_str(), repl_ids[i].c_str());
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
std::string q = "SELECT @@server_id -- maxscale route to server gserver" + std::to_string(i + 1);
|
||||
auto res = c.field(q);
|
||||
test.expect(res == galera_ids[i], "Wrong ID: %s(rwsplit) != %s(gserver)",
|
||||
res.c_str(), repl_ids[i].c_str());
|
||||
}
|
||||
|
||||
test.repl->fix_replication();
|
||||
|
||||
return test.global_result;
|
||||
}
|
||||
Reference in New Issue
Block a user