mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
MDEV-39368: Make mtr write queries into log/replay_queries.log
This commit is contained in:
@@ -275,6 +275,8 @@ static size_t suite_dir_len, overlay_dir_len;
|
||||
static MYSQL *replay_server_mysql= NULL;
|
||||
static const char *replay_server_socket= NULL;
|
||||
static my_bool replay_test_mode= FALSE;
|
||||
static FILE *replay_log_file= NULL;
|
||||
static const char *replay_log_path= NULL;
|
||||
|
||||
/* Precompiled re's */
|
||||
static regex_t ps_re; /* the query can be run using PS protocol */
|
||||
@@ -1886,6 +1888,18 @@ void free_used_memory()
|
||||
replay_server_mysql= NULL;
|
||||
}
|
||||
|
||||
if (replay_log_file)
|
||||
{
|
||||
fclose(replay_log_file);
|
||||
replay_log_file= NULL;
|
||||
}
|
||||
|
||||
if (replay_log_path)
|
||||
{
|
||||
my_free((void*)replay_log_path);
|
||||
replay_log_path= NULL;
|
||||
}
|
||||
|
||||
if (connections)
|
||||
{
|
||||
close_connections();
|
||||
@@ -11293,6 +11307,30 @@ static my_bool is_explain_format_json(const char *query, size_t query_len)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
Log the start of a new replay session
|
||||
*/
|
||||
static void log_replay_session_start()
|
||||
{
|
||||
if (replay_log_file)
|
||||
{
|
||||
fprintf(replay_log_file, "### REPLAY SESSION ###\n");
|
||||
fflush(replay_log_file);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Log a query being sent to the replay server
|
||||
*/
|
||||
static void log_replay_query(const char *query, size_t query_len)
|
||||
{
|
||||
if (replay_log_file)
|
||||
{
|
||||
fprintf(replay_log_file, "%.*s;\n", (int)query_len, query);
|
||||
fflush(replay_log_file);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Execute queries from SQL script on replay server
|
||||
Split by ";\n" and execute each query
|
||||
@@ -11308,6 +11346,8 @@ static void execute_replay_queries(const char *sql_script, DYNAMIC_STRING *ds)
|
||||
|
||||
verbose_msg("ReplayTest: SQL script from optimizer_context:\n%s", sql_script);
|
||||
|
||||
log_replay_session_start();
|
||||
|
||||
init_dynamic_string(&result, "", 1024, 1024);
|
||||
|
||||
/* Single-pass execution: stop at first EXPLAIN FORMAT=JSON */
|
||||
@@ -11332,6 +11372,9 @@ static void execute_replay_queries(const char *sql_script, DYNAMIC_STRING *ds)
|
||||
is_explain ? "EXPLAIN - will stop after this" : "intermediate",
|
||||
(int)query_len, query_start);
|
||||
|
||||
/* Log the query */
|
||||
log_replay_query(query_start, query_len);
|
||||
|
||||
/* Execute the query */
|
||||
if (mysql_real_query(replay_server_mysql, query_start, query_len))
|
||||
{
|
||||
@@ -11410,6 +11453,9 @@ static void execute_replay_queries(const char *sql_script, DYNAMIC_STRING *ds)
|
||||
is_explain ? "EXPLAIN" : "last query",
|
||||
(int)query_len, query_start);
|
||||
|
||||
/* Log the query */
|
||||
log_replay_query(query_start, query_len);
|
||||
|
||||
if (mysql_real_query(replay_server_mysql, query_start, query_len))
|
||||
{
|
||||
fprintf(stdout, "ReplayTest: Query failed on replay server: %d %s\n",
|
||||
@@ -13527,6 +13573,30 @@ int main(int argc, char **argv)
|
||||
replay_test_mode= TRUE;
|
||||
verbose_msg("ReplayTest mode enabled, replay server socket: %s",
|
||||
replay_server_socket);
|
||||
|
||||
/* Initialize replay query log file */
|
||||
const char *vardir= getenv("MYSQLTEST_VARDIR");
|
||||
if (vardir)
|
||||
{
|
||||
size_t path_len= strlen(vardir) + 30; /* room for "/log/replay_queries.log" */
|
||||
char *log_path= (char*)my_malloc(PSI_NOT_INSTRUMENTED, path_len, MYF(0));
|
||||
if (log_path)
|
||||
{
|
||||
snprintf(log_path, path_len, "%s/log/replay_queries.log", vardir);
|
||||
replay_log_path= log_path;
|
||||
/* Use append mode - MTR cleans var directory on each run */
|
||||
replay_log_file= fopen(replay_log_path, "a");
|
||||
if (!replay_log_file)
|
||||
{
|
||||
fprintf(stderr, "Warning: Could not open replay log file: %s\n",
|
||||
replay_log_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
verbose_msg("ReplayTest: Logging queries to %s", replay_log_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Cursor protocol implies ps protocol */
|
||||
|
||||
Reference in New Issue
Block a user