Commit 99ee0572 authored by unknown's avatar unknown

Save datadir in case of test failure, but limit the number of times

datadir can be saved in case of constantly failing servers
Remove datadirs each time all servers have been stopped thus limiting
the size of vardir.
The datadirs of failed tests have been saved and that should be
enough to diagnose any failures

parent af06e447
...@@ -193,9 +193,12 @@ our %mysqld_variables; ...@@ -193,9 +193,12 @@ our %mysqld_variables;
my $source_dist= 0; my $source_dist= 0;
our $opt_max_save_core= 5; my $opt_max_save_core= $ENV{MTR_MAX_SAVE_CORE} || 5;
my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far. my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far.
my $opt_max_save_datadir= $ENV{MTR_MAX_SAVE_DATADIR} || 20;
my $num_saved_datadir= 0; # Number of datadirs saved in vardir/log/ so far.
select(STDOUT); select(STDOUT);
$| = 1; # Automatically flush STDOUT $| = 1; # Automatically flush STDOUT
...@@ -351,6 +354,7 @@ sub command_line_setup { ...@@ -351,6 +354,7 @@ sub command_line_setup {
'client-debugger=s' => \$opt_client_debugger, 'client-debugger=s' => \$opt_client_debugger,
'strace-client:s' => \$opt_strace_client, 'strace-client:s' => \$opt_strace_client,
'max-save-core=i' => \$opt_max_save_core, 'max-save-core=i' => \$opt_max_save_core,
'max-save-datadir=i' => \$opt_max_save_datadir,
# Coverage, profiling etc # Coverage, profiling etc
'gcov' => \$opt_gcov, 'gcov' => \$opt_gcov,
...@@ -2325,6 +2329,10 @@ sub run_testcase ($) { ...@@ -2325,6 +2329,10 @@ sub run_testcase ($) {
if ( started(all_servers()) == 0 ) if ( started(all_servers()) == 0 )
{ {
# Remove old datadirs
clean_datadir();
# Restore old ENV # Restore old ENV
while (my ($option, $value)= each( %old_env )) { while (my ($option, $value)= each( %old_env )) {
if (defined $value){ if (defined $value){
...@@ -2448,17 +2456,14 @@ sub run_testcase ($) { ...@@ -2448,17 +2456,14 @@ sub run_testcase ($) {
mtr_report_test_passed($tinfo, $opt_timer); mtr_report_test_passed($tinfo, $opt_timer);
} }
if ( $opt_check_testcases ) if ( $opt_check_testcases and check_testcase($tinfo, "after"))
{
if (check_testcase($tinfo, "after"))
{ {
# Stop all servers that are known to be running # Stop all servers that are known to be running
stop_all_servers(); stop_all_servers();
after_test_failure($tinfo->{'name'}); clean_datadir();
mtr_report("Resuming tests...\n"); mtr_report("Resuming tests...\n");
} }
} }
}
elsif ( $res == 62 ) elsif ( $res == 62 )
{ {
# Testcase itself tell us to skip this one # Testcase itself tell us to skip this one
...@@ -2523,7 +2528,7 @@ sub run_testcase ($) { ...@@ -2523,7 +2528,7 @@ sub run_testcase ($) {
{ {
# Server failed, probably crashed # Server failed, probably crashed
$tinfo->{comment}= $tinfo->{comment}=
"Server failed during test run"; "Server $proc failed during test run";
report_failure_and_restart($tinfo); report_failure_and_restart($tinfo);
return 1; return 1;
...@@ -2667,67 +2672,119 @@ sub check_expected_crash_and_restart { ...@@ -2667,67 +2672,119 @@ sub check_expected_crash_and_restart {
} }
sub clean_datadir {
mtr_verbose("Cleaning datadirs...");
foreach my $cluster ( clusters() )
{
my $cluster_dir= "$opt_vardir/".$cluster->{name};
mtr_verbose(" - removing '$cluster_dir'");
rmtree($cluster_dir);
}
foreach my $mysqld ( mysqlds() )
{
my $mysqld_dir= dirname($mysqld->value('datadir'));
if (-d $mysqld_dir ) {
mtr_verbose(" - removing '$mysqld_dir'");
rmtree($mysqld_dir);
}
}
# Remove all files in tmp and var/tmp
rmtree("$opt_vardir/tmp");
mkpath("$opt_vardir/tmp");
if ($opt_tmpdir ne "$opt_vardir/tmp"){
rmtree($opt_tmpdir);
mkpath($opt_tmpdir);
}
}
# #
# Save any interesting files in the data_dir # Limit number of core files saved
# before the data dir is removed.
# #
sub save_files_after_test_failure($$) { sub limit_cores_after_failure ($) {
my $test_name= shift; my ($datadir)= @_;
my $data_dir= shift;
my $save_name= "$opt_vardir/log/$test_name";
# Look for core files # Look for core files
foreach my $core_file ( glob("$data_dir/core*") ) foreach my $core_file ( glob("$datadir/core*") )
{ {
last if $opt_max_save_core > 0 && $num_saved_cores >= $opt_max_save_core;
my $core_name= basename($core_file); my $core_name= basename($core_file);
mtr_report(" - saving '$core_name'"); if ($opt_max_save_core > 0 && $num_saved_cores >= $opt_max_save_core) {
mkpath($save_name) if ! -d $save_name; # Delete file to avoid saving it when the datadir is later saved
rename("$core_file", "$save_name/$core_name"); mtr_report(" - deleting '$core_name'",
"($num_saved_cores/$opt_max_save_core)");
unlink("$core_file");
}
else {
mtr_report(" - found '$core_name'",
"($num_saved_cores/$opt_max_save_core)");
}
++$num_saved_cores; ++$num_saved_cores;
} }
} }
#
# Save datadir before it's removed
#
sub save_datadir_after_failure($$) {
my ($dir, $savedir)= @_;
sub after_test_failure ($) { if ($opt_max_save_datadir > 0 &&
my $test_name= shift; $num_saved_datadir >= $opt_max_save_datadir)
mtr_report("Cleaning datadirs...");
foreach my $mysqld ( mysqlds() )
{ {
my $data_dir= $mysqld->value('datadir'); mtr_report(" - skipping '$dir'");
my $name= basename($data_dir); }
save_files_after_test_failure($test_name, $data_dir); else {
mtr_debug("Removing '$data_dir'"); mtr_report(" - saving '$dir'");
rmtree($data_dir); my $dir_name= basename($dir);
rename("$dir", "$savedir/$dir_name");
} }
}
# Remove the ndb_*_fs dirs for all ndbd nodes
# forcing a clean start of ndb next time sub after_failure ($) {
foreach my $cluster ( clusters() ) my ($tinfo)= @_;
{
foreach my $ndbd ( ndbds($cluster) ) mtr_report("Saving datadirs...");
{
my $data_dir= $ndbd->value('DataDir'); my $save_dir= "$opt_vardir/log/";
foreach my $fs_dir ( glob("$data_dir/ndb_*_fs") ) { $save_dir.= $tinfo->{name};
rmtree($fs_dir); # Add combination name if any
mtr_debug("Removing '$fs_dir'"); $save_dir.= "_$tinfo->{combination}"
if defined $tinfo->{combination};
mkpath($save_dir) if ! -d $save_dir;
# Save the used my.cnf file
copy($path_config_file, $save_dir);
if ( clusters() ) {
foreach my $cluster ( clusters() ) {
foreach my $server ( ndbds($cluster), ndb_mgmds($cluster) ) {
my $data_dir= $server->value('DataDir');
limit_cores_after_failure($data_dir);
} }
my $backup_dir= $ndbd->value('BackupDataDir'); my $cluster_dir= "$opt_vardir/".$cluster->{name};
rmtree("$backup_dir/BACKUP"); save_datadir_after_failure($cluster_dir, $save_dir);
mtr_debug("Removing '$backup_dir'");
} }
} }
else {
# Remove all files in tmp and var/tmp foreach my $mysqld ( mysqlds() ) {
rmtree("$opt_vardir/tmp"); my $data_dir= $mysqld->value('datadir');
mkpath("$opt_vardir/tmp"); limit_cores_after_failure($data_dir);
if ($opt_tmpdir ne "$opt_vardir/tmp"){ save_datadir_after_failure(dirname($data_dir), $save_dir);
rmtree($opt_tmpdir); }
mkpath($opt_tmpdir);
} }
$num_saved_datadir++;
clean_datadir();
} }
...@@ -2741,7 +2798,7 @@ sub report_failure_and_restart ($) { ...@@ -2741,7 +2798,7 @@ sub report_failure_and_restart ($) {
# Stop all servers that are known to be running # Stop all servers that are known to be running
stop_all_servers(); stop_all_servers();
after_test_failure($tinfo->{'name'}); after_failure($tinfo);
mtr_report("Resuming tests...\n"); mtr_report("Resuming tests...\n");
return; return;
} }
...@@ -3849,7 +3906,12 @@ Options for debugging the product ...@@ -3849,7 +3906,12 @@ Options for debugging the product
Example: $0 --strace-client=ktrace Example: $0 --strace-client=ktrace
max-save-core Limit the number of core files saved (to avoid filling max-save-core Limit the number of core files saved (to avoid filling
up disks for heavily crashing server). Defaults to up disks for heavily crashing server). Defaults to
$opt_max_save_core, set to 0 for no limit. $opt_max_save_core, set to 0 for no limit. Set
it's default with MTR_MAX_SAVE_CORE
max-save-datadir Limit the number of datadir saved (to avoid filling
up disks for heavily crashing server). Defaults to
$opt_max_save_datadir, set to 0 for no limit. Set
it's default with MTR_MAX_SAVE_DATDIR
Options for valgrind Options for valgrind
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment