Speed up test startup
The VM connectivity and log truncation is now done in parallel.
This commit is contained in:
parent
55bb3e9250
commit
5e3af05d48
@ -18,6 +18,8 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <future>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include "envv.h"
|
||||
|
||||
using std::cout;
|
||||
@ -1084,19 +1086,22 @@ std::string Mariadb_nodes::get_lowest_version()
|
||||
|
||||
int Mariadb_nodes::truncate_mariadb_logs()
|
||||
{
|
||||
int local_result = 0;
|
||||
std::vector<std::future<int>> results;
|
||||
|
||||
for (int node = 0; node < N; node++)
|
||||
{
|
||||
if (strcmp(IP[node], "127.0.0.1") != 0)
|
||||
{
|
||||
local_result += ssh_node_f(node, true,
|
||||
"truncate -s 0 /var/lib/mysql/*.err;"
|
||||
"truncate -s 0 /var/log/syslog;"
|
||||
"truncate -s 0 /var/log/messages;"
|
||||
"rm -f /etc/my.cnf.d/binlog_enc*;");
|
||||
auto f = std::async(std::launch::async, &Nodes::ssh_node_f, this, node, true,
|
||||
"truncate -s 0 /var/lib/mysql/*.err;"
|
||||
"truncate -s 0 /var/log/syslog;"
|
||||
"truncate -s 0 /var/log/messages;"
|
||||
"rm -f /etc/my.cnf.d/binlog_enc*;");
|
||||
results.push_back(std::move(f));
|
||||
}
|
||||
}
|
||||
return local_result;
|
||||
|
||||
return std::count_if(results.begin(), results.end(), std::mem_fn(&std::future<int>::get));
|
||||
}
|
||||
|
||||
int Mariadb_nodes::configure_ssl(bool require)
|
||||
|
@ -2,6 +2,9 @@
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <future>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
#include "envv.h"
|
||||
|
||||
@ -9,36 +12,29 @@ Nodes::Nodes()
|
||||
{
|
||||
}
|
||||
|
||||
int Nodes::check_node_ssh(int node)
|
||||
bool Nodes::check_node_ssh(int node)
|
||||
{
|
||||
int res = 0;
|
||||
bool res = true;
|
||||
|
||||
if (ssh_node(node, (char*) "ls > /dev/null", false) != 0)
|
||||
if (ssh_node(node, "ls > /dev/null", false) != 0)
|
||||
{
|
||||
printf("Node %d is not available\n", node);
|
||||
fflush(stdout);
|
||||
res = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fflush(stdout);
|
||||
std::cout << "Node " << node << " is not available" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int Nodes::check_nodes()
|
||||
bool Nodes::check_nodes()
|
||||
{
|
||||
std::cout << "Checking nodes..." << std::endl;
|
||||
std::vector<std::future<bool>> f;
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
if (check_node_ssh(i) != 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
f.push_back(std::async(std::launch::async, &Nodes::check_node_ssh, this, i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
return std::all_of(f.begin(), f.end(), std::mem_fn(&std::future<bool>::get));
|
||||
}
|
||||
|
||||
void Nodes::generate_ssh_cmd(char* cmd, int node, const char* ssh, bool sudo)
|
||||
|
@ -168,9 +168,9 @@ public:
|
||||
/**
|
||||
* @brief Check node via ssh and restart it if it is not resposible
|
||||
* @param node Node index
|
||||
* @return 0 if node is ok, 1 if start failed
|
||||
* @return True if node is ok, false if start failed
|
||||
*/
|
||||
int check_nodes();
|
||||
bool check_nodes();
|
||||
|
||||
/**
|
||||
* @brief read_basic_env Read IP, sshkey, etc - common parameters for all kinds of nodes
|
||||
@ -206,5 +206,5 @@ public:
|
||||
int stop_vm(int node);
|
||||
|
||||
private:
|
||||
int check_node_ssh(int node);
|
||||
bool check_node_ssh(int node);
|
||||
};
|
||||
|
@ -343,7 +343,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
||||
repl->use_ipv6 = use_ipv6;
|
||||
repl->take_snapshot_command = take_snapshot_command;
|
||||
repl->revert_snapshot_command = revert_snapshot_command;
|
||||
if (repl->check_nodes())
|
||||
if (!repl->check_nodes())
|
||||
{
|
||||
if (call_mdbci("--recreate"))
|
||||
{
|
||||
@ -363,7 +363,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 (!galera->check_nodes())
|
||||
{
|
||||
if (call_mdbci("--recreate"))
|
||||
{
|
||||
@ -377,7 +377,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
||||
}
|
||||
|
||||
maxscales = new Maxscales("maxscale", test_dir, verbose, use_valgrind, network_config);
|
||||
if (maxscales->check_nodes() ||
|
||||
if (!maxscales->check_nodes() ||
|
||||
((maxscales->N < 2) && (mdbci_labels.find(std::string("SECOND_MAXSCALE")) != std::string::npos))
|
||||
)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user