Skip to content

Commit bdf62c8

Browse files
author
Pavan Naik
committed
WL#12367: MTR: Generate a report of number of queries run on secondary
engine Description: ------------ This WL will enhance MTR to generate a report containing information about number of statements run on RAPID server (i.e value of Secondary_engine_execution_count status variable) for each test when a MTR run is started with --secondary-engine option. Change-Id: I7efbee4b0675ae45bb324ebfe97ba1683343bde3
1 parent d14e103 commit bdf62c8

File tree

9 files changed

+644
-323
lines changed

9 files changed

+644
-323
lines changed

client/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ SET(MYSQLTEST_SRC
4949
mysqltest/error_names.cc
5050
mysqltest/expected_errors.cc
5151
mysqltest/secondary_engine.cc
52+
mysqltest/utils.cc
5253
)
5354

5455
MYSQL_ADD_EXECUTABLE(mysqltest mysqltest.cc ${MYSQLTEST_SRC} COMPONENT Test)

client/mysqltest.cc

Lines changed: 94 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "client/mysqltest/error_names.h"
3131
#include "client/mysqltest/expected_errors.h"
3232
#include "client/mysqltest/secondary_engine.h"
33+
#include "client/mysqltest/utils.h"
3334

3435
#include <algorithm>
3536
#include <cmath> // std::isinf
@@ -151,6 +152,7 @@ enum {
151152
OPT_EXPLAIN_PROTOCOL,
152153
OPT_JSON_EXPLAIN_PROTOCOL,
153154
OPT_LOG_DIR,
155+
OPT_OFFLOAD_COUNT_FILE,
154156
OPT_MARK_PROGRESS,
155157
OPT_MAX_CONNECT_RETRIES,
156158
OPT_MAX_CONNECTIONS,
@@ -160,7 +162,6 @@ enum {
160162
#ifdef _WIN32
161163
OPT_SAFEPROCESS_PID,
162164
#endif
163-
OPT_SECONDARY_ENGINE,
164165
OPT_SP_PROTOCOL,
165166
OPT_TAIL_LINES,
166167
OPT_TRACE_EXEC,
@@ -209,8 +210,9 @@ static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos = line_buffer;
209210
static bool can_handle_expired_passwords = true;
210211

211212
// Secondary engine options
213+
static const char *opt_offload_count_file;
212214
static int opt_change_propagation;
213-
static const char *opt_secondary_engine;
215+
Secondary_engine secondary_engine;
214216

215217
#ifdef _WIN32
216218
static DWORD opt_safe_process_pid;
@@ -1365,6 +1367,18 @@ static void free_used_memory() {
13651367
}
13661368

13671369
static void cleanup_and_exit(int exit_code) {
1370+
if (opt_offload_count_file) {
1371+
// Check if the current connection is active, if not create one.
1372+
if (cur_con->mysql.net.vio == 0) {
1373+
mysql_real_connect(&cur_con->mysql, opt_host, opt_user, opt_pass, opt_db,
1374+
opt_port, unix_sock,
1375+
CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS);
1376+
}
1377+
// Save the final value of secondary engine execution status.
1378+
if (secondary_engine.offload_count(&cur_con->mysql, "after")) exit_code = 1;
1379+
secondary_engine.report_offload_count(opt_offload_count_file);
1380+
}
1381+
13681382
free_used_memory();
13691383
my_end(my_end_arg);
13701384

@@ -2981,31 +2995,6 @@ static void do_exec(struct st_command *command, bool run_in_background) {
29812995

29822996
enum enum_operator { DO_DEC, DO_INC };
29832997

2984-
/// Use stoi function to get the integer value from a string.
2985-
///
2986-
/// @param str String which may contain an integer or an alphanumeric
2987-
/// string.
2988-
///
2989-
/// @retval Integer value corresponding to the contents of the string,
2990-
/// if conversion is successful, or -1 if integer is out of
2991-
/// range, or if the conversion fails.
2992-
static int get_int_val(const char *str) {
2993-
int value;
2994-
size_t size;
2995-
2996-
try {
2997-
value = std::stoi(str, &size, 10);
2998-
if (size != std::strlen(str)) value = -1;
2999-
} catch (const std::out_of_range &) {
3000-
fprintf(stderr, "Interger value '%s' is out of range. ", str);
3001-
value = -1;
3002-
} catch (const std::invalid_argument &) {
3003-
value = -1;
3004-
}
3005-
3006-
return value;
3007-
}
3008-
30092998
/// Template function that frees memory of the dynamic string
30102999
/// passed to the function.
30113000
///
@@ -5164,32 +5153,6 @@ static void do_disable_testcase(struct st_command *command) {
51645153
free_dynamic_strings(&ds_bug_number);
51655154
}
51665155

5167-
/*
5168-
Run query and return one field in the result set from the
5169-
first row and <column>
5170-
*/
5171-
5172-
static int query_get_string(MYSQL *mysql, const char *query, int column,
5173-
std::string *ds) {
5174-
MYSQL_RES *res = NULL;
5175-
MYSQL_ROW row;
5176-
5177-
if (mysql_query(mysql, query))
5178-
die("'%s' failed: %d %s", query, mysql_errno(mysql), mysql_error(mysql));
5179-
if ((res = mysql_store_result(mysql)) == NULL)
5180-
die("Failed to store result: %d %s", mysql_errno(mysql),
5181-
mysql_error(mysql));
5182-
5183-
if ((row = mysql_fetch_row(res)) == NULL) {
5184-
mysql_free_result(res);
5185-
ds = 0;
5186-
return 1;
5187-
}
5188-
ds->assign(row[column] ? row[column] : "NULL");
5189-
mysql_free_result(res);
5190-
return 0;
5191-
}
5192-
51935156
/**
51945157
Check if process is active.
51955158
@@ -5293,85 +5256,91 @@ static void abort_process(int pid, const char *path MY_ATTRIBUTE((unused))) {
52935256
#endif
52945257
}
52955258

5296-
/**
5297-
Shutdown or kill the server.
5298-
If timeout is set to 0 the server is killed/terminated
5299-
immediately. Otherwise the shutdown command is first sent
5300-
and then it waits for the server to terminate within
5301-
@<timeout@> seconds. If it has not terminated before @<timeout@>
5302-
seconds the command will fail.
5303-
5304-
@note Currently only works with local server
5305-
5306-
@param command Optionally including a timeout else the
5307-
default of 60 seconds is used.
5308-
*/
5309-
5259+
/// Shutdown or kill the server. If timeout is set to 0 the server is
5260+
/// killed or terminated immediately. Otherwise the shutdown command
5261+
/// is first sent and then it waits for the server to terminate within
5262+
/// 'timeout' seconds. If it has not terminated before 'timeout'
5263+
/// seconds the command will fail.
5264+
///
5265+
/// @note
5266+
/// Currently only works with local server
5267+
///
5268+
/// @param command Pointer to the st_command structure which holds the
5269+
/// arguments and information for the command. Optionally
5270+
/// including a timeout else the default of 60 seconds
5271+
/// is used.
53105272
static void do_shutdown_server(struct st_command *command) {
5311-
long timeout = 60;
5312-
int pid, error = 0;
5313-
std::string ds_file_name;
5314-
MYSQL *mysql = &cur_con->mysql;
53155273
static DYNAMIC_STRING ds_timeout;
53165274
const struct command_arg shutdown_args[] = {
53175275
{"timeout", ARG_STRING, false, &ds_timeout,
53185276
"Timeout before killing server"}};
5319-
DBUG_ENTER("do_shutdown_server");
53205277

53215278
check_command_args(command, command->first_argument, shutdown_args,
53225279
sizeof(shutdown_args) / sizeof(struct command_arg), ' ');
53235280

5281+
if (opt_offload_count_file) {
5282+
// Save the value of secondary engine execution status
5283+
// before shutting down the server.
5284+
if (secondary_engine.offload_count(&cur_con->mysql, "after"))
5285+
cleanup_and_exit(1);
5286+
}
5287+
5288+
long timeout = 60;
53245289
if (ds_timeout.length) {
53255290
char *endptr;
5326-
timeout = strtol(ds_timeout.str, &endptr, 10);
5291+
timeout = std::strtol(ds_timeout.str, &endptr, 10);
53275292
if (*endptr != '\0')
53285293
die("Illegal argument for timeout: '%s'", ds_timeout.str);
53295294
}
5295+
53305296
dynstr_free(&ds_timeout);
53315297

5332-
/* Get the servers pid_file name and use it to read pid */
5298+
MYSQL *mysql = &cur_con->mysql;
5299+
std::string ds_file_name;
5300+
5301+
// Get the servers pid_file name and use it to read pid.
53335302
if (query_get_string(mysql, "SHOW VARIABLES LIKE 'pid_file'", 1,
53345303
&ds_file_name))
53355304
die("Failed to get pid_file from server");
53365305

5337-
/* Read the pid from the file */
5338-
{
5339-
int fd;
5340-
char buff[32];
5306+
// Read the pid from the file
5307+
int fd;
5308+
char buff[32];
53415309

5342-
if ((fd = my_open(ds_file_name.c_str(), O_RDONLY, MYF(0))) < 0)
5343-
die("Failed to open file '%s'", ds_file_name.c_str());
5310+
if ((fd = my_open(ds_file_name.c_str(), O_RDONLY, MYF(0))) < 0)
5311+
die("Failed to open file '%s'", ds_file_name.c_str());
53445312

5345-
if (my_read(fd, (uchar *)&buff, sizeof(buff), MYF(0)) <= 0) {
5346-
my_close(fd, MYF(0));
5347-
die("pid file was empty");
5348-
}
5313+
if (my_read(fd, (uchar *)&buff, sizeof(buff), MYF(0)) <= 0) {
53495314
my_close(fd, MYF(0));
5350-
5351-
pid = atoi(buff);
5352-
if (pid == 0) die("Pidfile didn't contain a valid number");
5315+
die("pid file was empty");
53535316
}
5354-
DBUG_PRINT("info", ("Got pid %d", pid));
53555317

5318+
my_close(fd, MYF(0));
5319+
5320+
int pid = std::atoi(buff);
5321+
if (pid == 0) die("Pidfile didn't contain a valid number");
5322+
5323+
int error = 0;
53565324
if (timeout) {
5357-
/* Check if we should generate a minidump on timeout. */
5325+
// Check if we should generate a minidump on timeout.
53585326
if (query_get_string(mysql, "SHOW VARIABLES LIKE 'core_file'", 1,
53595327
&ds_file_name) ||
53605328
std::strcmp("ON", ds_file_name.c_str())) {
53615329
} else {
5362-
/* Get the data dir and use it as path for a minidump if needed. */
5330+
// Get the data dir and use it as path for a minidump if needed.
53635331
if (query_get_string(mysql, "SHOW VARIABLES LIKE 'datadir'", 1,
53645332
&ds_file_name))
5365-
die("Failed to get datadir from server");
5333+
die("Failed to get datadir from server.");
53665334
}
53675335

5368-
/* Tell server to shutdown if timeout > 0. */
5336+
// Tell server to shutdown if timeout > 0.
53695337
if (timeout > 0 && mysql_query(mysql, "shutdown")) {
5370-
error = 1; /* Failed to issue shutdown command. */
5338+
// Failed to issue shutdown command.
5339+
error = 1;
53715340
goto end;
53725341
}
53735342

5374-
/* Check that server dies */
5343+
// Check that server dies
53755344
do {
53765345
if (!is_process_active(pid)) {
53775346
DBUG_PRINT("info", ("Process %d does not exist anymore", pid));
@@ -5382,25 +5351,23 @@ static void do_shutdown_server(struct st_command *command) {
53825351
my_sleep(1000000L);
53835352
}
53845353
} while (timeout-- > 0);
5354+
53855355
error = 2;
5386-
/*
5387-
Abort to make it easier to find the hang/problem.
5388-
*/
5356+
5357+
// Abort to make it easier to find the hang/problem.
53895358
abort_process(pid, ds_file_name.c_str());
5390-
} else /* timeout == 0 */
5391-
{
5392-
/* Kill the server */
5359+
} else {
5360+
// timeout value is 0, kill the server
53935361
DBUG_PRINT("info", ("Killing server, pid: %d", pid));
5394-
/*
5395-
kill_process can fail (bad privileges, non existing process on *nix etc),
5396-
so also check if the process is active before setting error.
5397-
*/
5362+
5363+
// kill_process can fail (bad privileges, non existing process on
5364+
// *nix etc), so also check if the process is active before setting
5365+
// error.
53985366
if (!kill_process(pid) && is_process_active(pid)) error = 3;
53995367
}
54005368

54015369
end:
54025370
if (error) handle_command_error(command, error);
5403-
DBUG_VOID_RETURN;
54045371
}
54055372

54065373
/// Get the error code corresponding to an error string or to a
@@ -6951,6 +6918,9 @@ static struct my_option my_long_options[] = {
69516918
"Contains comma seperated list of to be excluded inc files.",
69526919
&excluded_string, &excluded_string, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
69536920
0, 0},
6921+
{"offload-count-file", OPT_OFFLOAD_COUNT_FILE, "Offload count report file",
6922+
&opt_offload_count_file, &opt_offload_count_file, 0, GET_STR, REQUIRED_ARG,
6923+
0, 0, 0, 0, 0, 0},
69546924
{"opt-trace-protocol", OPT_TRACE_PROTOCOL,
69556925
"Trace DML statements with optimizer trace", &opt_trace_protocol,
69566926
&opt_trace_protocol, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -6988,9 +6958,6 @@ static struct my_option my_long_options[] = {
69886958
&opt_safe_process_pid, &opt_safe_process_pid, 0, GET_INT, REQUIRED_ARG, 0,
69896959
0, 0, 0, 0, 0},
69906960
#endif
6991-
{"secondary-engine", OPT_SECONDARY_ENGINE,
6992-
"Enable a secondary storage engine.", &opt_secondary_engine,
6993-
&opt_secondary_engine, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
69946961
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
69956962
"Base name of shared memory.", &shared_memory_base_name,
69966963
&shared_memory_base_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -7659,7 +7626,7 @@ static void run_query_normal(struct st_connection *cn,
76597626
if (opt_change_propagation != -1) {
76607627
std::vector<unsigned int> ignore_errors = expected_errors->errors();
76617628
// Run secondary engine unload statements.
7662-
if (run_secondary_engine_unload_statements(query, mysql, ignore_errors))
7629+
if (secondary_engine.run_unload_statements(query, mysql, ignore_errors))
76637630
die("Original query '%s'.", query);
76647631
}
76657632

@@ -7766,9 +7733,7 @@ static void run_query_normal(struct st_connection *cn,
77667733
if (opt_change_propagation != -1) {
77677734
std::vector<unsigned int> ignore_errors = expected_errors->errors();
77687735
// Run secondary engine load statements.
7769-
if (run_secondary_engine_load_statements(opt_secondary_engine, query, mysql,
7770-
ignore_errors,
7771-
opt_change_propagation))
7736+
if (secondary_engine.run_load_statements(query, mysql, ignore_errors))
77727737
die("Original query '%s'.", query);
77737738
}
77747739

@@ -7804,7 +7769,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_command *command,
78047769
if (opt_change_propagation != -1) {
78057770
std::vector<unsigned int> ignore_errors = expected_errors->errors();
78067771
// Run secondary engine unload statements.
7807-
if (run_secondary_engine_unload_statements(query, mysql, ignore_errors))
7772+
if (secondary_engine.run_unload_statements(query, mysql, ignore_errors))
78087773
die("Original query '%s'.", query);
78097774
}
78107775

@@ -7996,9 +7961,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_command *command,
79967961
if (opt_change_propagation != -1) {
79977962
std::vector<unsigned int> ignore_errors = expected_errors->errors();
79987963
// Run secondary engine load statements.
7999-
if (run_secondary_engine_load_statements(opt_secondary_engine, query, mysql,
8000-
ignore_errors,
8001-
opt_change_propagation))
7964+
if (secondary_engine.run_load_statements(query, mysql, ignore_errors))
80027965
die("Original query '%s'.", query);
80037966
}
80047967

@@ -8921,6 +8884,15 @@ int main(int argc, char **argv) {
89218884
open_file(opt_include);
89228885
}
89238886

8887+
if (opt_change_propagation != -1)
8888+
secondary_engine = Secondary_engine(opt_change_propagation);
8889+
8890+
if (opt_offload_count_file) {
8891+
// Save the initial value of secondary engine execution status.
8892+
if (secondary_engine.offload_count(&cur_con->mysql, "before"))
8893+
cleanup_and_exit(1);
8894+
}
8895+
89248896
verbose_msg("Start processing test commands from '%s' ...",
89258897
cur_file->file_name);
89268898
while (!read_command(&command) && !abort_flag) {
@@ -9287,6 +9259,12 @@ int main(int argc, char **argv) {
92879259
do_reset_connection();
92889260
break;
92899261
case Q_SEND_SHUTDOWN:
9262+
if (opt_offload_count_file) {
9263+
// Save the value of secondary engine execution status
9264+
// before shutting down the server.
9265+
if (secondary_engine.offload_count(&cur_con->mysql, "after"))
9266+
cleanup_and_exit(1);
9267+
}
92909268
handle_command_error(command,
92919269
mysql_query(&cur_con->mysql, "shutdown"));
92929270
break;

0 commit comments

Comments
 (0)