From 4042652d7f3ce0f6d0dc84550521df5ca2d06c2c Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 17 Apr 2025 10:32:09 +0300 Subject: [PATCH] Improvements to mtr - Added option $backup_on_restart to store a backup of the var/ directory after restart. This is useful for debugging recovery. - The list_files option in mysqltest is now returning the number of found files in $sys_files. This is useful to break test if there are unknown or lost files in the data directory. --- client/mysqltest.cc | 15 +++++++++++---- mysql-test/include/restart_mysqld.inc | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 63c19bd62d0..01488126394 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -4115,6 +4115,10 @@ void do_rmdir(struct st_command *command) DESCRIPTION list all entries in directory (matching ds_wild if given) + + RETURN + -1 on error + # number of found files */ static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname, @@ -4123,11 +4127,12 @@ static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname, size_t i; MY_DIR *dir_info; FILEINFO *file; + int found= 0; DBUG_ENTER("get_list_files"); DBUG_PRINT("info", ("listing directory: %s", ds_dirname->str)); if (!(dir_info= my_dir(ds_dirname->str, MYF(MY_WANT_SORT)))) - DBUG_RETURN(1); + DBUG_RETURN(-1); set_wild_chars(1); for (i= 0; i < dir_info->number_of_files; i++) { @@ -4137,10 +4142,11 @@ static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname, continue; replace_dynstr_append(ds, file->name); dynstr_append_mem(ds, STRING_WITH_LEN("\n")); + found++; } set_wild_chars(0); my_dirend(dir_info); - DBUG_RETURN(0); + DBUG_RETURN(found); } @@ -4172,7 +4178,8 @@ static void do_list_files(struct st_command *command) sizeof(list_files_args)/sizeof(struct command_arg), ' '); error= get_list_files(&ds_res, &ds_dirname, &ds_wild); - handle_command_error(command, error, my_errno); + var_set_int("$sys_files",error); + handle_command_error(command, error < 0, my_errno); dynstr_free(&ds_dirname); dynstr_free(&ds_wild); DBUG_VOID_RETURN; @@ -4217,7 +4224,7 @@ static void do_list_files_write_file_command(struct st_command *command, DBUG_VOID_RETURN; init_dynamic_string(&ds_content, "", 1024, 1024); - error= get_list_files(&ds_content, &ds_dirname, &ds_wild); + error= get_list_files(&ds_content, &ds_dirname, &ds_wild) < 0; handle_command_error(command, error, my_errno); str_to_file2(ds_filename.str, ds_content.str, ds_content.length, append); dynstr_free(&ds_content); diff --git a/mysql-test/include/restart_mysqld.inc b/mysql-test/include/restart_mysqld.inc index 9abd2b66131..19ed01676ea 100644 --- a/mysql-test/include/restart_mysqld.inc +++ b/mysql-test/include/restart_mysqld.inc @@ -2,11 +2,17 @@ # # [--let $shutdown_timeout= 60] # [--let $allow_rpl_inited= 1] +# Create a copy of the var directory after restart +# [--let $$backup_on_restart=1] # --source include/restart_mysqld.inc --source include/not_embedded.inc --source include/shutdown_mysqld.inc +if ($backup_on_restart) +{ + --exec /bin/tar cfzP /tmp/mtr-backup.tgz --exclude=*.sock $MYSQLTEST_VARDIR/* +} --source include/start_mysqld.inc # The following sleep is required to give sleep_until_file_created() time