Copy test logs in parallel

The log copying is now done in parallel for all VMs.
This commit is contained in:
Markus Mäkelä
2018-06-18 21:52:36 +03:00
parent 58207ec414
commit 8f71e803c1
2 changed files with 39 additions and 30 deletions

View File

@ -698,43 +698,38 @@ void TestConnections::init_maxscale(int m)
} }
} }
void TestConnections::copy_one_mariadb_log(int i, std::string filename)
{
int exit_code;
char* mariadb_log = repl->ssh_node_output(i, "cat /var/lib/mysql/*.err 2>/dev/null", true, &exit_code);
FILE* f = fopen(filename.c_str(), "w");
int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, char * prefix) if (f != NULL)
{
fwrite(mariadb_log, sizeof(char), strlen(mariadb_log), f);
fclose(f);
}
free(mariadb_log);
}
int TestConnections::copy_mariadb_logs(Mariadb_nodes* repl, const char* prefix, std::vector<std::thread>& threads)
{ {
int local_result = 0; int local_result = 0;
char * mariadb_log;
FILE * f;
int i;
int exit_code;
char str[4096];
if (repl == NULL) if (repl)
{ {
return local_result; for (int i = 0; i < repl->N; i++)
}
sprintf(str, "mkdir -p LOGS/%s", test_name);
system(str);
for (i = 0; i < repl->N; i++)
{
if (strcmp(repl->IP[i], "127.0.0.1") != 0) // Do not copy MariaDB logs in case of local backend
{ {
mariadb_log = repl->ssh_node_output(i, (char *) "cat /var/lib/mysql/*.err", true, &exit_code); if (strcmp(repl->IP[i], "127.0.0.1") != 0) // Do not copy MariaDB logs in case of local backend
sprintf(str, "LOGS/%s/%s%d_mariadb_log", test_name, prefix, i);
f = fopen(str, "w");
if (f != NULL)
{ {
fwrite(mariadb_log, sizeof(char), strlen(mariadb_log), f); char str[4096];
fclose(f); sprintf(str, "LOGS/%s/%s%d_mariadb_log", test_name, prefix, i);
threads.emplace_back(&TestConnections::copy_one_mariadb_log, this, i, str);
} }
else
{
printf("Error writing MariaDB log");
local_result = 1;
}
free(mariadb_log);
} }
} }
return local_result; return local_result;
} }
@ -742,10 +737,16 @@ int TestConnections::copy_all_logs()
{ {
set_timeout(300); set_timeout(300);
char str[PATH_MAX + 1];
sprintf(str, "mkdir -p LOGS/%s", test_name);
system(str);
std::vector<std::thread> threads;
if (!no_backend_log_copy) if (!no_backend_log_copy)
{ {
copy_mariadb_logs(repl, (char *) "node"); copy_mariadb_logs(repl, "node", threads);
copy_mariadb_logs(galera, (char *) "galera"); copy_mariadb_logs(galera, "galera", threads);
} }
int rv = 0; int rv = 0;
@ -755,6 +756,11 @@ int TestConnections::copy_all_logs()
rv = copy_maxscale_logs(0); rv = copy_maxscale_logs(0);
} }
for (auto& a: threads)
{
a.join();
}
return rv; return rv;
} }
int TestConnections::copy_maxscale_logs(double timestamp) int TestConnections::copy_maxscale_logs(double timestamp)

View File

@ -9,6 +9,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <set> #include <set>
#include <string> #include <string>
#include <vector>
#include <thread>
typedef std::set<std::string> StringSet; typedef std::set<std::string> StringSet;
@ -128,7 +130,7 @@ public:
* @param prefix file name prefix * @param prefix file name prefix
* @return 0 if success * @return 0 if success
*/ */
int copy_mariadb_logs(Mariadb_nodes *repl, char * prefix); int copy_mariadb_logs(Mariadb_nodes* repl, const char* prefix, std::vector<std::thread>& threads);
/** /**
* @brief no_backend_log_copy if true logs from backends are not copied * @brief no_backend_log_copy if true logs from backends are not copied
@ -524,6 +526,7 @@ public:
private: private:
void report_result(const char *format, va_list argp); void report_result(const char *format, va_list argp);
void copy_one_mariadb_log(int i, std::string filename);
}; };
/** /**