From 0932d1016951192ea9696c88d38eee1f13e8eb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 7 Apr 2019 20:11:07 +0300 Subject: [PATCH] Do node checks in parallel The checking of MariaDB and Galera nodes is now done asynchronously while the MaxScale check is done which leads to faster testing. Rough measurements show that doing all the work in parallel reduces test startup time by two seconds. Most of the time appears to still be in the MaxScale startup which takes on average three to four seconds per test. --- maxscale-system-test/testconnections.cpp | 102 ++++++++++------------- maxscale-system-test/testconnections.h | 10 ++- 2 files changed, 50 insertions(+), 62 deletions(-) diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index a57126054..b733d6fbd 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "mariadb_func.h" @@ -337,19 +338,16 @@ TestConnections::TestConnections(int argc, char* argv[]) exit(0); } + std::future repl_future; + std::future galera_future; + if (!no_repl) { repl = new Mariadb_nodes("node", test_dir, verbose, network_config); repl->use_ipv6 = use_ipv6; repl->take_snapshot_command = take_snapshot_command; repl->revert_snapshot_command = revert_snapshot_command; - if (!repl->check_nodes()) - { - if (call_mdbci("--recreate")) - { - exit(MDBCI_FAUILT); - } - } + repl_future = std::async(std::launch::async, &Mariadb_nodes::check_nodes, repl); } else { @@ -363,13 +361,7 @@ TestConnections::TestConnections(int argc, char* argv[]) galera->use_ipv6 = false; galera->take_snapshot_command = take_snapshot_command; galera->revert_snapshot_command = revert_snapshot_command; - if (!galera->check_nodes()) - { - if (call_mdbci("--recreate")) - { - exit(MDBCI_FAUILT); - } - } + galera_future = std::async(std::launch::async, &Galera_nodes::check_nodes, galera); } else { @@ -377,23 +369,26 @@ TestConnections::TestConnections(int argc, char* argv[]) } maxscales = new Maxscales("maxscale", test_dir, verbose, use_valgrind, network_config); - if (!maxscales->check_nodes() || - ((maxscales->N < 2) && (mdbci_labels.find(std::string("SECOND_MAXSCALE")) != std::string::npos)) - ) + + bool maxscale_ok = maxscales->check_nodes(); + bool repl_ok = no_repl || repl_future.get(); + bool galera_ok = no_galera || galera_future.get(); + bool node_error = !maxscale_ok || !repl_ok || !galera_ok; + + if (node_error || too_many_maxscales()) { + tprintf("Recreating VMs: %s", node_error ? "node check failed" : "too many maxscales"); + if (call_mdbci("--recreate")) { exit(MDBCI_FAUILT); } } - if (reinstall_maxscale) + if (reinstall_maxscale && reinstall_maxscales()) { - if (reinstall_maxscales()) - { - tprintf("Failed to install Maxscale: target is %s", target); - exit(MDBCI_FAUILT); - } + tprintf("Failed to install Maxscale: target is %s", target); + exit(MDBCI_FAUILT); } std::string src = std::string(test_dir) + "/mdbci/add_core_cnf.sh"; @@ -414,39 +409,33 @@ TestConnections::TestConnections(int argc, char* argv[]) } } - if (repl) + if (repl && maxscale::required_repl_version.length()) { - if (maxscale::required_repl_version.length()) - { - int ver_repl_required = get_int_version(maxscale::required_repl_version); - std::string ver_repl = repl->get_lowest_version(); - int int_ver_repl = get_int_version(ver_repl); + int ver_repl_required = get_int_version(maxscale::required_repl_version); + std::string ver_repl = repl->get_lowest_version(); + int int_ver_repl = get_int_version(ver_repl); - if (int_ver_repl < ver_repl_required) - { - tprintf("Test requires a higher version of backend servers, skipping test."); - tprintf("Required version: %s", maxscale::required_repl_version.c_str()); - tprintf("Master-slave version: %s", ver_repl.c_str()); - exit(0); - } + if (int_ver_repl < ver_repl_required) + { + tprintf("Test requires a higher version of backend servers, skipping test."); + tprintf("Required version: %s", maxscale::required_repl_version.c_str()); + tprintf("Master-slave version: %s", ver_repl.c_str()); + exit(0); } } - if (galera) + if (galera && maxscale::required_galera_version.length()) { - if (maxscale::required_galera_version.length()) - { - int ver_galera_required = get_int_version(maxscale::required_galera_version); - std::string ver_galera = galera->get_lowest_version(); - int int_ver_galera = get_int_version(ver_galera); + int ver_galera_required = get_int_version(maxscale::required_galera_version); + std::string ver_galera = galera->get_lowest_version(); + int int_ver_galera = get_int_version(ver_galera); - if (int_ver_galera < ver_galera_required) - { - tprintf("Test requires a higher version of backend servers, skipping test."); - tprintf("Required version: %s", maxscale::required_galera_version.c_str()); - tprintf("Galera version: %s", ver_galera.c_str()); - exit(0); - } + if (int_ver_galera < ver_galera_required) + { + tprintf("Test requires a higher version of backend servers, skipping test."); + tprintf("Required version: %s", maxscale::required_galera_version.c_str()); + tprintf("Galera version: %s", ver_galera.c_str()); + exit(0); } } @@ -456,22 +445,15 @@ TestConnections::TestConnections(int argc, char* argv[]) galera->start_replication(); } - if (maxscale::check_nodes) { - if (repl) + if (repl && !repl->fix_replication()) { - if (!repl->fix_replication() ) - { - exit(BROKEN_VM_FAUILT); - } + exit(BROKEN_VM_FAUILT); } - if (galera) + if (galera && !galera->fix_replication()) { - if (!galera->fix_replication()) - { - exit(BROKEN_VM_FAUILT); - } + exit(BROKEN_VM_FAUILT); } } diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index 2f5160d61..aebcb86aa 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -700,9 +700,15 @@ public: private: void report_result(const char* format, va_list argp); - void copy_one_mariadb_log(Mariadb_nodes *nrepl, int i, std::string filename); + void copy_one_mariadb_log(Mariadb_nodes* nrepl, int i, std::string filename); - std::vector> m_on_destroy; + bool too_many_maxscales() const + { + return maxscales->N < 2 + && mdbci_labels.find("SECOND_MAXSCALE") != std::string::npos; + } + + std::vector> m_on_destroy; }; /**