| 1 |
#!/usr/bin/perl |
| 2 |
################################################################################ |
| 3 |
# |
| 4 |
# This script runs the transactional stress test "stress_tx_rr" against the |
| 5 |
# transactional storage engine and looks for errors in two log files: |
| 6 |
# var/stress/<timestamp>/mysql-stress-test.log |
| 7 |
# var/log/master.err |
| 8 |
# |
| 9 |
# The script assumes current working dir is mysql-test/. |
| 10 |
# |
| 11 |
# Regarding the server error log, currently only error lines containing the |
| 12 |
# string "Error:" will be reported as a critical error, in addition to signs |
| 13 |
# of crashes. |
| 14 |
# |
| 15 |
# In the stress test log, all lines matching the regex "S\d:" (denoting an |
| 16 |
# error with a specified severity) will be reported as errors. |
| 17 |
# |
| 18 |
# Error information including the full server log in the case of server crash |
| 19 |
# is output to standard out. |
| 20 |
# |
| 21 |
# This script is and should be silent if no errors are detected. |
| 22 |
# |
| 23 |
################################################################################ |
| 24 |
|
| 25 |
use File::Find; |
| 26 |
use File::Spec; |
| 27 |
use Cwd; |
| 28 |
use Cwd 'abs_path'; |
| 29 |
use Getopt::Long; |
| 30 |
|
| 31 |
# Checking script is run from the correct location |
| 32 |
if (! -f "mysql-test-run.pl") { |
| 33 |
print("\nERROR: This script should be run from the \'\<INSTALL_DIR\>/mysql-test\' directory.\n"); |
| 34 |
error(1); |
| 35 |
} |
| 36 |
|
| 37 |
$runlog="rr_trx.log"; |
| 38 |
|
| 39 |
my $errorFound; |
| 40 |
|
| 41 |
my $installdir=abs_path(File::Spec->updir()); |
| 42 |
|
| 43 |
my $f=abs_path($0); |
| 44 |
my ($v,$d,$f)=File::Spec->splitpath($f); |
| 45 |
my $testsuitedir=$v.$d; |
| 46 |
|
| 47 |
################################################################################ |
| 48 |
# Run stress test, redirect output to tmp file. |
| 49 |
# Duration is specified in seconds. Some nice values: |
| 50 |
# 5 minutes = 300 |
| 51 |
# 30 minutes = 1800 |
| 52 |
# 1 hour = 3600 |
| 53 |
# 2 hours = 7200 |
| 54 |
# 5 hours = 18000 |
| 55 |
# 12 hours = 43200 |
| 56 |
# |
| 57 |
################################################################################ |
| 58 |
$opt_duration=600; |
| 59 |
|
| 60 |
# Special handling for the InnoDB plugin |
| 61 |
$plugin_params="\"--plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so\""; |
| 62 |
$plugin_params=~s/so/dll/g if (windows()); |
| 63 |
|
| 64 |
$opt_help=""; |
| 65 |
$opt_try=""; |
| 66 |
$opt_engine=""; |
| 67 |
$opt_threads=10; |
| 68 |
|
| 69 |
# Collection command line options |
| 70 |
GetOptions("engine:s" => \$opt_engine, |
| 71 |
"duration=i" => \$opt_duration, |
| 72 |
"threads=i" => \$opt_treads, |
| 73 |
"try", "help") || usage(); |
| 74 |
|
| 75 |
if ($opt_help) { usage(); } |
| 76 |
if (!$opt_engine) { |
| 77 |
print("\nERROR: --engine=\<engine\> argument is required!!!\n"); |
| 78 |
usage(); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
# setting specific engine parameters |
| 83 |
$engine_options=""; |
| 84 |
# for innodb engine |
| 85 |
if ($opt_engine eq "InnoDB") { |
| 86 |
$engine_options= |
| 87 |
"--mysqld=--innodb " . |
| 88 |
"--mysqld=--innodb-lock-wait-timeout=2 " . |
| 89 |
" "; |
| 90 |
} |
| 91 |
elsif ($opt_engine eq "InnoDB_plugin") { |
| 92 |
$engine_options= |
| 93 |
"--mysqld=--innodb " . |
| 94 |
"--mysqld=--ignore-builtin-innodb " . |
| 95 |
#"--mysqld=--plugin_dir=".$installdir."/lib " . |
| 96 |
"--mysqld=--plugin_dir=".$installdir."/storage/innodb_plugin/.libs " . |
| 97 |
"--mysqld=--innodb-lock-wait-timeout=2 " . |
| 98 |
"--mysqld=".$plugin_params." " . |
| 99 |
" "; |
| 100 |
} |
| 101 |
# add parameters for a new engine by modifying the 'elsif' section below |
| 102 |
elsif ($opt_engine eq "zz") { |
| 103 |
$engine_options= |
| 104 |
" "; |
| 105 |
} |
| 106 |
else { |
| 107 |
print("\nERROR: '".$opt_engine."' - unknown engine\n"); |
| 108 |
add_engine_help(); |
| 109 |
} |
| 110 |
|
| 111 |
# From this point forward there is no difference between the build in InnDB and the plugin |
| 112 |
$opt_engine='InnoDB' if ($opt_engine eq 'InnoDB_plugin'); |
| 113 |
|
| 114 |
# checking that custom files for that engine exist |
| 115 |
$engine_lower= lc($opt_engine); |
| 116 |
$missing=0; |
| 117 |
if (!-f $testsuitedir.'init_'.$engine_lower.'.txt') { |
| 118 |
print("\nERROR: config file 'init_".$engine_lower.".txt' missing."); |
| 119 |
$missing=1; |
| 120 |
} |
| 121 |
if (!-f $testsuitedir.'t/init_'.$engine_lower.'.test') { |
| 122 |
print("\nERROR: config file 'init_".$engine_lower.".test' missing."); |
| 123 |
$missing=1; |
| 124 |
} |
| 125 |
if (!-f $testsuitedir.'r/init_'.$engine_lower.'.result') { |
| 126 |
print("\nERROR: config file 'init_".$engine_lower.".result' missing."); |
| 127 |
$missing=1; |
| 128 |
} |
| 129 |
add_engine_help() if ($missing); |
| 130 |
|
| 131 |
# bilding test command line |
| 132 |
$cmd="MTR_VERSION=1 " . |
| 133 |
"perl ./mysql-test-run.pl " . |
| 134 |
"--comment=stress_tx_rr_".$opt_engine." " . |
| 135 |
"--stress " . |
| 136 |
"--stress-init-file=init_".$engine_lower.".txt " . |
| 137 |
"--stress-test-file=run.txt " . |
| 138 |
"--stress-suite=engines/rr_trx " . |
| 139 |
"--stress-test-duration=".$opt_duration." " . |
| 140 |
"--stress-threads=".$opt_threads." " . |
| 141 |
"--mysqld=--log-output=file " . |
| 142 |
"--mysqld=--sql-mode=no_engine_substitution " . |
| 143 |
"--skip-im " . |
| 144 |
"--skip-ndb " . |
| 145 |
$engine_options . |
| 146 |
" > ".$runlog." 2>&1"; |
| 147 |
|
| 148 |
# running the test |
| 149 |
print("\n Running \'rr_trx\' test with ".$opt_threads." clients\n"); |
| 150 |
print(" for ".$opt_duration." seconds using the ".$opt_engine." storag engine.\n"); |
| 151 |
print("\n Log file: ".$runlog."\n"); |
| 152 |
if ($opt_try) { |
| 153 |
print("\nThe following command will execute:\n"); |
| 154 |
print("$cmd\n\n"); |
| 155 |
exit(0); |
| 156 |
} |
| 157 |
system $cmd; |
| 158 |
|
| 159 |
################################################################################ |
| 160 |
# Check for crash and other severe errors in the server log. |
| 161 |
# |
| 162 |
################################################################################ |
| 163 |
|
| 164 |
# Open log file. If MTR_VERSION=1 this is in var/log/master.err. |
| 165 |
# Otherwise, it is in ?... [stress_tx_rr not yet runnable with MTR_VERSION=2] |
| 166 |
# Assuming current directory mysql-test/ |
| 167 |
my $serverlog=getcwd() . "/var/log/master.err"; |
| 168 |
|
| 169 |
open(SERVERLOG, $serverlog) |
| 170 |
or die "Unable to open $serverlog. Test not run?"; |
| 171 |
my @servererrors = (); # Lines with "Severe" errors in server error log |
| 172 |
my @crash = (); # Empty if no stack trace detected, non-empty otherwise. |
| 173 |
|
| 174 |
# Grep for errors and crashes. Going line-by-line since the file can be large. |
| 175 |
while (<SERVERLOG>) { |
| 176 |
$line = $_; |
| 177 |
push @crash, $line if /This could be because you hit a bug/; |
| 178 |
push @servererrors, $line if /Error:/; |
| 179 |
} |
| 180 |
close(SERVERLOG); |
| 181 |
|
| 182 |
if (@crash) { |
| 183 |
# Crash (stack trace) detected in server log. |
| 184 |
print "Transactional stress test stress_tx_rr:\n\n"; |
| 185 |
print "SERVER CRASH DETECTED!\n"; |
| 186 |
print "Server log: $serverlog printed at the bottom of this log.\n\n"; |
| 187 |
print "########################################################\n\n"; |
| 188 |
} |
| 189 |
if (@servererrors) { |
| 190 |
# "Severe" errors detected. Print error lines to std out |
| 191 |
print "CRITICAL ERRORS:\n\n"; |
| 192 |
foreach $error (@servererrors) { |
| 193 |
print $error; |
| 194 |
} |
| 195 |
print "\n########################################################\n\n"; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
################################################################################ |
| 200 |
# Check for errors reported by mysql-stress-test.pl. Transactional consistency |
| 201 |
# issues are shown as result diffs. |
| 202 |
################################################################################ |
| 203 |
|
| 204 |
my $dir; |
| 205 |
find(\&finddir, cwd); # sets variable $dir |
| 206 |
|
| 207 |
# Open log file |
| 208 |
my $logfile="$dir/mysql-stress-test.log"; |
| 209 |
open(LOGFILE, $logfile) |
| 210 |
or die "Unable to open $logfile. Test not run?"; |
| 211 |
my @errors = (); |
| 212 |
my @heading = (); |
| 213 |
|
| 214 |
# Grep for errors. Going line-by-line since the file can be large. |
| 215 |
while (<LOGFILE>) { |
| 216 |
#push @errors, $_ if ! /No Errors/; |
| 217 |
push @errors, $_ if /S\d:/; |
| 218 |
push @heading, $_ if /TestID|=====/; |
| 219 |
} |
| 220 |
close(LOGFILE); |
| 221 |
|
| 222 |
# Print all errors, i.e. all lines that do not contain the string "No Errors" |
| 223 |
if (@errors) { |
| 224 |
$errorFound = 1; |
| 225 |
print "Stress test main log file: $logfile\n"; |
| 226 |
print "Errors follow:\n\n"; |
| 227 |
# First print the heading |
| 228 |
foreach $header_line (@heading) { |
| 229 |
print $header_line; |
| 230 |
} |
| 231 |
foreach $error (@errors) { |
| 232 |
print $error; |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
# If errors in server log, output the log and exit 1? |
| 238 |
if (@servererrors or @crash) { |
| 239 |
$errorFound = 1; |
| 240 |
print "\n########################################################\n\n"; |
| 241 |
print "Server error log (master.err):\n\n"; |
| 242 |
|
| 243 |
open(SERVERLOG, $serverlog) |
| 244 |
or die "Unable to open $serverlog!"; |
| 245 |
|
| 246 |
while (<SERVERLOG>) { |
| 247 |
print $_; |
| 248 |
} |
| 249 |
close(SERVERLOG); |
| 250 |
} |
| 251 |
|
| 252 |
if ($errorFound) { |
| 253 |
# Exit with error code != 0 if we found an error. |
| 254 |
print("\nTest Completed with errors. \n"); |
| 255 |
print(" - See ".$runlog." for summary.\n"); |
| 256 |
print(" - See files under var/stress for details.\n"); |
| 257 |
exit 1; |
| 258 |
} |
| 259 |
|
| 260 |
print("\nTest Completed - See ".$runlog." for details\n"); |
| 261 |
################################################################################ |
| 262 |
# Helper routines etc. |
| 263 |
# |
| 264 |
################################################################################ |
| 265 |
|
| 266 |
sub finddir { |
| 267 |
my $file = $File::Find::name; # complete path to the file |
| 268 |
|
| 269 |
return unless -d $file; # process directories (-d), not files (-f) |
| 270 |
return unless $_ =~ m/^\d{14}$/; # check if file matches timstamp regex, |
| 271 |
# must be 14 digits |
| 272 |
$dir=$file; |
| 273 |
#$dir= $_; # $_ = just the file name, no path |
| 274 |
return $_; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
sub usage |
| 279 |
{ |
| 280 |
print <<EOF; |
| 281 |
|
| 282 |
SYNTAX $0 --engine=<engine> [--duration=<nn>] [--thread=<nn>] [--try] |
| 283 |
|
| 284 |
--engine=<engine> |
| 285 |
The engine used to run the test. \<engine\> needs to be provided exactly as |
| 286 |
it is reprted in the SHOW ENGINES comand. |
| 287 |
EXCEPTION: In order to use the InnoDB plugin, specify 'InnoDB_plugin' |
| 288 |
Required option. |
| 289 |
|
| 290 |
--duration=nn |
| 291 |
The time the test should run for in seconds. Defaut value is 600 seconds (10 minutes). |
| 292 |
Optional parameter |
| 293 |
|
| 294 |
--threads=nn |
| 295 |
The number of clients used by the test driver. Defaut value is 10. |
| 296 |
Optional parameter |
| 297 |
|
| 298 |
--try |
| 299 |
Do not run the actual test but show what will be run |
| 300 |
Optional parameter |
| 301 |
|
| 302 |
|
| 303 |
EOF |
| 304 |
|
| 305 |
exit(0); |
| 306 |
} |
| 307 |
|
| 308 |
sub add_engine_help |
| 309 |
{ |
| 310 |
print <<EOF; |
| 311 |
|
| 312 |
\nThis test is can be run against any transactional engine. However scripts need to be modifed in order |
| 313 |
to support such engines (support to InnoDB is provided as an example). |
| 314 |
In order to add support for a new engine, you will need to modify scripts as follows: |
| 315 |
1) cd to INSTALL_DIR/mysql-test/suite/engines/rr_trx |
| 316 |
2) Modify the 'run_stress_rr.pl' file by adding an 'elsif' section for your engine and have it |
| 317 |
include specifc values required to be passed as startup parameters to the MySQL server by |
| 318 |
specifying them using "--mysqld" options (see InnoDB example). |
| 319 |
3) Copy the 'init_innodb.txt' file to 'init_<engine>.txt file and change its content to be "init_<engine>". |
| 320 |
4) In the 't' directory copy the "init_innodb.test" file to "init_\<engine\>.test" and change the value of |
| 321 |
the '\$engine' variable to \<engine\>. |
| 322 |
5) In the 'r' directory copy "the init_innodb.result" file to "init_\<engine\>.result" and change refrences |
| 323 |
to 'InnoDB' to \<engine\>. |
| 324 |
|
| 325 |
EOF |
| 326 |
|
| 327 |
exit(0); |
| 328 |
} |
| 329 |
|
| 330 |
sub windows { |
| 331 |
if ( |
| 332 |
($^O eq 'MSWin32') || |
| 333 |
($^O eq 'MSWin64') |
| 334 |
) { |
| 335 |
return 1; |
| 336 |
} else { |
| 337 |
return 0; |
| 338 |
} |
| 339 |
} |
| 340 |
|