Skip to content

Commit 4042652

Browse files
committed
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.
1 parent ce8a74f commit 4042652

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

client/mysqltest.cc

+11-4
Original file line numberDiff line numberDiff line change
@@ -4115,6 +4115,10 @@ void do_rmdir(struct st_command *command)
41154115
41164116
DESCRIPTION
41174117
list all entries in directory (matching ds_wild if given)
4118+
4119+
RETURN
4120+
-1 on error
4121+
# number of found files
41184122
*/
41194123

41204124
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,
41234127
size_t i;
41244128
MY_DIR *dir_info;
41254129
FILEINFO *file;
4130+
int found= 0;
41264131
DBUG_ENTER("get_list_files");
41274132

41284133
DBUG_PRINT("info", ("listing directory: %s", ds_dirname->str));
41294134
if (!(dir_info= my_dir(ds_dirname->str, MYF(MY_WANT_SORT))))
4130-
DBUG_RETURN(1);
4135+
DBUG_RETURN(-1);
41314136
set_wild_chars(1);
41324137
for (i= 0; i < dir_info->number_of_files; i++)
41334138
{
@@ -4137,10 +4142,11 @@ static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname,
41374142
continue;
41384143
replace_dynstr_append(ds, file->name);
41394144
dynstr_append_mem(ds, STRING_WITH_LEN("\n"));
4145+
found++;
41404146
}
41414147
set_wild_chars(0);
41424148
my_dirend(dir_info);
4143-
DBUG_RETURN(0);
4149+
DBUG_RETURN(found);
41444150
}
41454151

41464152

@@ -4172,7 +4178,8 @@ static void do_list_files(struct st_command *command)
41724178
sizeof(list_files_args)/sizeof(struct command_arg), ' ');
41734179

41744180
error= get_list_files(&ds_res, &ds_dirname, &ds_wild);
4175-
handle_command_error(command, error, my_errno);
4181+
var_set_int("$sys_files",error);
4182+
handle_command_error(command, error < 0, my_errno);
41764183
dynstr_free(&ds_dirname);
41774184
dynstr_free(&ds_wild);
41784185
DBUG_VOID_RETURN;
@@ -4217,7 +4224,7 @@ static void do_list_files_write_file_command(struct st_command *command,
42174224
DBUG_VOID_RETURN;
42184225

42194226
init_dynamic_string(&ds_content, "", 1024, 1024);
4220-
error= get_list_files(&ds_content, &ds_dirname, &ds_wild);
4227+
error= get_list_files(&ds_content, &ds_dirname, &ds_wild) < 0;
42214228
handle_command_error(command, error, my_errno);
42224229
str_to_file2(ds_filename.str, ds_content.str, ds_content.length, append);
42234230
dynstr_free(&ds_content);

mysql-test/include/restart_mysqld.inc

+6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
#
33
# [--let $shutdown_timeout= 60]
44
# [--let $allow_rpl_inited= 1]
5+
# Create a copy of the var directory after restart
6+
# [--let $$backup_on_restart=1]
57
# --source include/restart_mysqld.inc
68

79
--source include/not_embedded.inc
810

911
--source include/shutdown_mysqld.inc
12+
if ($backup_on_restart)
13+
{
14+
--exec /bin/tar cfzP /tmp/mtr-backup.tgz --exclude=*.sock $MYSQLTEST_VARDIR/*
15+
}
1016
--source include/start_mysqld.inc
1117

1218
# The following sleep is required to give sleep_until_file_created() time

0 commit comments

Comments
 (0)