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:
Markus Mäkelä
2019-04-18 11:27:00 +03:00
parent 111ab8f5e4
commit 5e6107d451
5 changed files with 156 additions and 5 deletions

View File

@ -946,6 +946,9 @@ add_test_executable(mxs2417_ignore_persisted_cnf.cpp mxs2417_ignore_persisted_cn
# MXS-1662: PAM admin authentication # MXS-1662: PAM admin authentication
add_test_executable(mxs1662_pam_admin.cpp mxs1662_pam_admin mxs1662_pam_admin LABELS REPL_BACKEND) 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 # # BEGIN: binlogrouter and avrorouter tests #
############################################ ############################################

View 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

View File

@ -1443,16 +1443,21 @@ int Mariadb_nodes::prepare_servers()
} }
void Mariadb_nodes::replicate_from(int slave, int master, const char* type) 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; std::stringstream change_master;
change_master << "CHANGE MASTER TO MASTER_HOST = '" << IP[master] change_master << "CHANGE MASTER TO MASTER_HOST = '" << host
<< "', MASTER_PORT = " << port[master] << ", MASTER_USE_GTID = " << type << ", " << "', MASTER_PORT = " << port << ", MASTER_USE_GTID = "
"MASTER_USER='repl', MASTER_PASSWORD='repl';"; << type << ", MASTER_USER='repl', MASTER_PASSWORD='repl';";
if (verbose) if (verbose)
{ {
std::cout << "Server " << slave + 1 << " starting to replicate from server " << master + 1 std::cout << "Server " << slave + 1
<< std::endl; << " starting to replicate from server " << master + 1 << std::endl;
std::cout << "Query is '" << change_master.str() << "'" << std::endl; std::cout << "Query is '" << change_master.str() << "'" << std::endl;
} }

View File

@ -477,6 +477,9 @@ public:
*/ */
void replicate_from(int slave, int master, const char* type = "current_pos"); 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: private:
bool check_master_node(MYSQL* conn); bool check_master_node(MYSQL* conn);

View 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;
}