From 7c2d5fd6a4b9eaacc934bc4cabf1171979aee739 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Tue, 25 Jun 2019 18:55:35 +0300 Subject: [PATCH] Add test for "enforce_simple_topology" --- maxscale-system-test/CMakeLists.txt | 3 + ...scale.cnf.template.mysqlmon_enforce_simple | 65 +++++++++++ .../mysqlmon_enforce_simple.cpp | 101 ++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 maxscale-system-test/cnf/maxscale.cnf.template.mysqlmon_enforce_simple create mode 100644 maxscale-system-test/mysqlmon_enforce_simple.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index fb69b7855..ac3c9ab54 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -287,6 +287,9 @@ add_test_executable(mysqlmon_switchover_auto.cpp mysqlmon_switchover_auto mysqlm # MySQL Monitor series of failovers and rejoins add_test_executable(mysqlmon_failover_readonly.cpp mysqlmon_failover_readonly mysqlmon_failover_readonly LABELS mysqlmon REPL_BACKEND) +# MariaDB-Monitor enforce_simple_topology +add_test_executable(mysqlmon_enforce_simple.cpp mysqlmon_enforce_simple mysqlmon_enforce_simple LABELS mysqlmon REPL_BACKEND) + # MXS-1506: Delayed query retry # https://jira.mariadb.org/browse/MXS-1506 add_test_executable(mxs1506_delayed_retry.cpp mxs1506_delayed_retry mxs1506_delayed_retry LABELS readwritesplit REPL_BACKEND) diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mysqlmon_enforce_simple b/maxscale-system-test/cnf/maxscale.cnf.template.mysqlmon_enforce_simple new file mode 100644 index 000000000..502475200 --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mysqlmon_enforce_simple @@ -0,0 +1,65 @@ +[maxscale] +threads=###threads### + +[MariaDB-Monitor] +type=monitor +module=mariadbmon +servers= server1, server2, server3, server4 +user=maxskysql +password= skysql +monitor_interval=1000 +failcount=2 +enforce_simple_topology=true +replication_user=repl +replication_password=repl +backend_connect_timeout=10 +backend_read_timeout=10 +backend_write_timeout=10 + +[RW-Split-Router] +type=service +router= readwritesplit +servers=server1, server2, server3, server4 +user=maxskysql +password=skysql + +[RW-Split-Listener] +type=listener +service=RW-Split-Router +protocol=MySQLClient +port=4006 + +[CLI] +type=service +router=cli + +[CLI-Listener] +type=listener +service=CLI +protocol=maxscaled +socket=default + +[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 + diff --git a/maxscale-system-test/mysqlmon_enforce_simple.cpp b/maxscale-system-test/mysqlmon_enforce_simple.cpp new file mode 100644 index 000000000..2d021fd72 --- /dev/null +++ b/maxscale-system-test/mysqlmon_enforce_simple.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2019 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl11. + * + * Change Date: 2023-01-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#include "testconnections.h" +#include +#include + +using std::string; +using std::cout; + +int get_master_server_id(TestConnections& test) +{ + MYSQL* conn = test.maxscales->open_rwsplit_connection(0); + int id = -1; + char str[1024]; + + if (find_field(conn, "SELECT @@server_id, @@last_insert_id;", "@@server_id", str) == 0) + { + id = atoi(str); + } + + mysql_close(conn); + return id; +} + +int main(int argc, char** argv) +{ + Mariadb_nodes::require_gtid(true); + TestConnections::skip_maxscale_start(true); + + TestConnections test(argc, argv); + + if (test.repl->N < 4) + { + test.expect(false, "This test requires at least 4 backends."); + return test.global_result; + } + + test.repl->connect(); + auto server_ids = test.repl->get_all_server_ids(); + + // Stop the master and the last slave, then start MaxScale. + int master_ind = 0; + int last_slave_ind = 3; + + string master_name = mxb::string_printf("server%i", master_ind + 1); + string slave_name = mxb::string_printf("server%i", last_slave_ind + 1); + + test.tprintf("Stopping %s and %s.", master_name.c_str(), slave_name.c_str()); + test.repl->stop_node(master_ind); + test.repl->stop_node(last_slave_ind); + + test.tprintf("Starting MaxScale"); + test.start_maxscale(0); + + sleep(3); + test.maxscales->wait_for_monitor(3); + + test.log_includes(0, "Performing automatic failover"); + int new_master_id = get_master_server_id(test); + int expected_id1 = server_ids[1]; + int expected_id2 = server_ids[2]; + test.expect(new_master_id == expected_id1 || new_master_id == expected_id2, + "Unexpected master server id. Got %i when %i or %i was expected.", + new_master_id, expected_id1, expected_id2); + + if (test.ok()) + { + // Restart server4, check that it rejoins. + test.repl->start_node(last_slave_ind, (char*)""); + test.maxscales->wait_for_monitor(2); + + auto states = test.maxscales->get_server_status(slave_name.c_str()); + test.expect(states.count("Slave") == 1, "%s is not replicating as it should.", slave_name.c_str()); + } + + if (test.ok()) + { + // Finally, bring back old master and swap to it. + test.repl->start_node(master_ind, (char*)""); + test.maxscales->wait_for_monitor(2); + + test.tprintf("Switching back old master %s.", master_name.c_str()); + string switchover = "call command mariadbmon switchover MariaDB-Monitor " + master_name; + test.maxscales->execute_maxadmin_command(0, switchover.c_str()); + test.maxscales->wait_for_monitor(2); + new_master_id = get_master_server_id(test); + test.expect(new_master_id == server_ids[master_ind], "Switchover to original master failed."); + } + return test.global_result; +}