From 5e6107d4513bed5e98db8ce5444d2b2fba547459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 18 Apr 2019 11:27:00 +0300 Subject: [PATCH] MXS-2441: Add galera with slaves test case The test checks that servers replicating from Galera nodes work as expected. --- maxscale-system-test/CMakeLists.txt | 3 + ...axscale.cnf.template.mxs2441_galera_slaves | 76 +++++++++++++++++++ maxscale-system-test/mariadb_nodes.cpp | 15 ++-- maxscale-system-test/mariadb_nodes.h | 3 + .../mxs2441_galera_slaves.cpp | 64 ++++++++++++++++ 5 files changed, 156 insertions(+), 5 deletions(-) create mode 100755 maxscale-system-test/cnf/maxscale.cnf.template.mxs2441_galera_slaves create mode 100644 maxscale-system-test/mxs2441_galera_slaves.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index a624f7719..ef7f9beeb 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -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 # ############################################ diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mxs2441_galera_slaves b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2441_galera_slaves new file mode 100755 index 000000000..6294eee7e --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2441_galera_slaves @@ -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 diff --git a/maxscale-system-test/mariadb_nodes.cpp b/maxscale-system-test/mariadb_nodes.cpp index 426ec134e..01e70ac31 100644 --- a/maxscale-system-test/mariadb_nodes.cpp +++ b/maxscale-system-test/mariadb_nodes.cpp @@ -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; } diff --git a/maxscale-system-test/mariadb_nodes.h b/maxscale-system-test/mariadb_nodes.h index 6a1e49265..27e31e0a3 100644 --- a/maxscale-system-test/mariadb_nodes.h +++ b/maxscale-system-test/mariadb_nodes.h @@ -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); diff --git a/maxscale-system-test/mxs2441_galera_slaves.cpp b/maxscale-system-test/mxs2441_galera_slaves.cpp new file mode 100644 index 000000000..69da6a51f --- /dev/null +++ b/maxscale-system-test/mxs2441_galera_slaves.cpp @@ -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 + +#include + +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; +}