Skip to content

Commit d69803d

Browse files
committed
BUG#35217728 Speedup mtr.pl by clean vardir
When using mtr.pl for development (running individual tests or parts of suites) the time spent setting up the environment far exceeds the time to run the actual test. Most timeconsuming are the steps to create the MySQL system database (i.e running mysqld --initialize) and copying the std_data directory into the var directory. Since the size of std_data grows over time as more and more stuff are added there, this step takes increasingly longer. Fix by improving the --fast mode to clean the var directory for reuse rather than removing it entirely and creating it again. This allows the data/ and std_data/ directories to be kept. Also make it possible to pass --no-fast to negate any previous --fast arguments one the command line. With this patch, the time to run a single simple test is decreased with 13 seconds on standard development machine. $ mtr alias <snip> Checking leftover processes Removing old var directory Creating var directory '/home/mblaudd/mysql/trunk/bld/mysql-test/var' - symlinking 'var' to '/dev/shm/var_auto_iXMr' Installing system database Using parallel: 1 ============================================================================== TEST NAME RESULT TIME (ms) ------------------------------------------------------------------------------ [ 50%] main.alias [ pass ] 758 [100%] shutdown_report [ pass ] ------------------------------------------------------------------------------ The servers were restarted 0 times The servers were reinitialized 0 times Spent 0.758 of 17 seconds executing testcases $ mtr alias --fast <snip> Checking leftover processes Cleaning var directory to save time Creating var directory '/home/mblaudd/mysql/trunk/bld/mysql-test/var' Reusing system database Using parallel: 1 ============================================================================== TEST NAME RESULT TIME (ms) COMMENT ------------------------------------------------------------------------------ [ 50%] main.alias [ pass ] 696 [100%] shutdown_report [ pass ] ------------------------------------------------------------------------------ The servers were restarted 0 times The servers were reinitialized 0 times Spent 0.696 of 4 seconds executing testcases Change-Id: Ibcf82874f61bbf1e1c8746da028045ccbc0a8a50
1 parent c05a5a0 commit d69803d

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

mysql-test/mysql-test-run.pl

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ sub command_line_setup {
17581758
'default-myisam!' => \&collect_option,
17591759
'disk-usage!' => \&report_option,
17601760
'enable-disabled' => \&collect_option,
1761-
'fast' => \$opt_fast,
1761+
'fast!' => \$opt_fast,
17621762
'force-restart' => \$opt_force_restart,
17631763
'help|h' => \$opt_usage,
17641764
'keep-ndbfs' => \$opt_keep_ndbfs,
@@ -2084,6 +2084,7 @@ sub command_line_setup {
20842084
# fast option
20852085
if ($opt_fast) {
20862086
# Kill processes instead of nice shutdown
2087+
mtr_report("Using kill instead of nice shutdown (--fast)");
20872088
$opt_shutdown_timeout = 0;
20882089
}
20892090

@@ -3407,6 +3408,34 @@ ()
34073408

34083409
# Remove var and any directories in var/ created by previous tests
34093410
sub remove_stale_vardir () {
3411+
3412+
if ($opt_fast) {
3413+
mtr_report(" * NOTE! Using --fast for quicker development testing.");
3414+
mtr_report(" * This may cause spurious test failures if contents");
3415+
mtr_report(" * of std_data/ or data/ does not match the tests or");
3416+
mtr_report(" * compiled binaries. Fix by removing vardir (or run");
3417+
mtr_report(" * once without --fast).");
3418+
3419+
# Just clean the vardir, this allows reusing data/ and std_data/
3420+
# which otherwise takes time to create or copy.
3421+
mtr_report("Cleaning var directory to save time (--fast)");
3422+
foreach my $name (glob("$opt_vardir/*")) {
3423+
if (!-l $name && -d _) {
3424+
if ($name =~ /\/data$/ ||
3425+
$name =~ /\/std_data$/) {
3426+
# Preserve directory
3427+
next;
3428+
}
3429+
# Remove directory
3430+
rmtree($name);
3431+
next;
3432+
}
3433+
# Remove file
3434+
unlink($name);
3435+
}
3436+
return;
3437+
}
3438+
34103439
mtr_report("Removing old var directory");
34113440

34123441
mtr_error("No, don't remove the vardir when running with --extern")
@@ -3517,7 +3546,8 @@ ()
35173546

35183547
# Copy all files from std_data into var/std_data
35193548
# and make them world readable
3520-
copytree("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data", "0022");
3549+
copytree("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data", "0022")
3550+
unless -d "$opt_vardir/std_data";
35213551

35223552
# Remove old log files
35233553
foreach my $name (glob("r/*.progress r/*.log r/*.warnings")) {
@@ -4155,8 +4185,6 @@ sub mysql_install_db {
41554185
my $install_chsdir = $mysqld->value('character-sets-dir');
41564186
my $install_datadir = $datadir || $mysqld->value('datadir');
41574187

4158-
mtr_report("Installing system database");
4159-
41604188
my $args;
41614189
mtr_init_args(\$args);
41624190
mtr_add_arg($args, "--no-defaults");
@@ -4213,6 +4241,14 @@ sub mysql_install_db {
42134241
# Export MYSQLD_INSTALL_CMD variable containing <path>/mysqld <args>
42144242
$ENV{'MYSQLD_INSTALL_CMD'} = "$exe_mysqld_bootstrap " . join(" ", @$args);
42154243

4244+
if ($opt_fast && -d $datadir) {
4245+
mtr_report("Reusing system database (--fast)");
4246+
4247+
return;
4248+
}
4249+
4250+
mtr_report("Installing system database");
4251+
42164252
# Create the bootstrap.sql file
42174253
my $bootstrap_sql_file = "$opt_vardir/tmp/bootstrap.sql";
42184254

@@ -7975,8 +8011,9 @@ ($)
79758011
tests. This is needed after switching default storage
79768012
engine to InnoDB.
79778013
disk-usage Show disk usage of vardir after each test.
7978-
fast Run as fast as possible, dont't wait for servers
7979-
to shutdown etc.
8014+
fast Run mtr.pl as fast as possible when using it for
8015+
development. This involves reusing the vardir (just
8016+
clean it) and don't wait for servers to shutdown.
79808017
force-restart Always restart servers between tests.
79818018
gcov Collect coverage information after the test.
79828019
The result is a gcov file per source and header file.

0 commit comments

Comments
 (0)