diff --git a/system-test/mariadbmonitor/CMakeLists.txt b/system-test/mariadbmonitor/CMakeLists.txt index c82e4a6ef..ae7639ef6 100644 --- a/system-test/mariadbmonitor/CMakeLists.txt +++ b/system-test/mariadbmonitor/CMakeLists.txt @@ -102,6 +102,7 @@ add_test_executable_ex(NAME verify_master_failure SOURCE verify_master_failure.c CONFIG verify_master_failure.cnf VMS repl_backend LABELS mysqlmon) # MariaDB-Monitor enforce_simple_topology +# Also MXS-3324 switchover when autocommit is off on backends. add_test_executable_ex(NAME mysqlmon_enforce_simple SOURCE mysqlmon_enforce_simple.cpp CONFIG mysqlmon_enforce_simple.cnf VMS repl_backend LABELS mysqlmon) diff --git a/system-test/mariadbmonitor/mysqlmon_enforce_simple.cpp b/system-test/mariadbmonitor/mysqlmon_enforce_simple.cpp index 75fb73ed6..531d22e44 100644 --- a/system-test/mariadbmonitor/mysqlmon_enforce_simple.cpp +++ b/system-test/mariadbmonitor/mysqlmon_enforce_simple.cpp @@ -97,5 +97,53 @@ int main(int argc, char** argv) new_master_id = get_master_server_id(test); test.expect(new_master_id == server_ids[master_ind], "Switchover to original master failed."); } + + if (test.ok()) + { + // Test that switchover works even if autocommit is off on all backends. + test.tprintf("Setting autocommit=0 on all backends, then check that switchover works."); + test.maxscales->stop(); + test.repl->connect(); + const char set_ac[] = "SET GLOBAL autocommit=%i;"; + for (int i = 0; i < 4; i++) + { + test.try_query(test.repl->nodes[i], set_ac, 0); + } + test.maxscales->start(); + + // Check that autocommit is really off. + Connection conn = test.repl->get_connection(2); + conn.connect(); + auto row = conn.row("SELECT @@GLOBAL.autocommit;"); + test.expect(!row.empty() && row[0] == "0", "autocommit is not off"); + + new_master_id = get_master_server_id(test); + test.expect(new_master_id == server_ids[master_ind], "No valid master"); + + if (test.ok()) + { + test.tprintf("Switchover..."); + string switchover = "call command mariadbmon switchover MariaDB-Monitor"; + 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 failed."); + if (test.ok()) + { + test.expect(new_master_id == server_ids[1], "Switchover to wrong server."); + } + + 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."); + } + + for (int i = 0; i < 4; i++) + { + test.try_query(test.repl->nodes[i], set_ac, 1); + } + } return test.global_result; }