| 1 |
#************************************************************ |
| 2 |
# WL6045:Improve Innochecksum |
| 3 |
#************************************************************ |
| 4 |
|
| 5 |
# Valgrind would complain about memory leaks when we crash on purpose. |
| 6 |
--source include/not_valgrind.inc |
| 7 |
|
| 8 |
|
| 9 |
# Avoid CrashReporter popup on Mac. |
| 10 |
--source include/not_crashrep.inc |
| 11 |
|
| 12 |
--echo # Set the environmental variables |
| 13 |
let MYSQLD_BASEDIR= `SELECT @@basedir`; |
| 14 |
let MYSQLD_DATADIR= `SELECT @@datadir`; |
| 15 |
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/my_restart.err; |
| 16 |
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Unable to read page \\[page id: space=.*, page number=.*\\] into the buffer pool after 100 attempts"); |
| 17 |
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Database page corruption on disk or a failed"); |
| 18 |
# ib::fatal() calls ut_error |
| 19 |
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Assertion failure: buf0buf\.cc:[0-9]+:ib::fatal triggered"); |
| 20 |
SET GLOBAL innodb_file_per_table=on; |
| 21 |
|
| 22 |
--echo [1]: Test is to corrupt the ibd file, & do repair for (innodb|crc32|none) checksum through innochecksum tool |
| 23 |
|
| 24 |
# Disable compression for this table, otherwise our pattern matching below |
| 25 |
# will not work |
| 26 |
--echo # Create and populate the table to be corrupted |
| 27 |
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) COMPRESSION="none", |
| 28 |
ROW_FORMAT=COMPACT ENGINE=InnoDB; |
| 29 |
INSERT INTO t1 (b) VALUES ('corrupt me'); |
| 30 |
--disable_query_log |
| 31 |
--let $i = 10 |
| 32 |
while ($i) |
| 33 |
{ |
| 34 |
INSERT INTO t1 (b) VALUES (REPEAT('abcdefghijklmnopqrstuvwxyz', 100)); |
| 35 |
dec $i; |
| 36 |
} |
| 37 |
--enable_query_log |
| 38 |
INSERT INTO t1 (b) VALUES ('corrupt me'); |
| 39 |
|
| 40 |
let $MYSQLD_DATADIR=`select @@datadir`; |
| 41 |
let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd; |
| 42 |
|
| 43 |
--echo # Shutdown the server |
| 44 |
--source include/shutdown_mysqld.inc |
| 45 |
|
| 46 |
--echo # Corrupt the t1 table |
| 47 |
|
| 48 |
perl; |
| 49 |
use strict; |
| 50 |
use warnings; |
| 51 |
use Fcntl qw(:DEFAULT :seek); |
| 52 |
my $ibd_file = $ENV{'t1_IBD'}; |
| 53 |
my $chunk; |
| 54 |
my $len; |
| 55 |
|
| 56 |
sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file"; |
| 57 |
|
| 58 |
while ($len = sysread IBD_FILE, $chunk, 1024) |
| 59 |
{ |
| 60 |
if ($chunk =~ s/corrupt me/korrupt me/) |
| 61 |
{ |
| 62 |
print "Munged a string.\n"; |
| 63 |
sysseek IBD_FILE, -$len, SEEK_CUR; |
| 64 |
syswrite IBD_FILE, $chunk, $len; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
close IBD_FILE; |
| 69 |
EOF |
| 70 |
|
| 71 |
--echo # Backup the corrupted t1.ibd for reuse for further testing. |
| 72 |
--copy_file $t1_IBD $MYSQLD_DATADIR/test/t1.ibd.backup1 |
| 73 |
|
| 74 |
--echo # Write file to make mysql-test-run.pl start up the server again |
| 75 |
--source include/start_mysqld.inc |
| 76 |
|
| 77 |
--echo # Write file to make mysql-test-run.pl expect the "crash", but don't |
| 78 |
--echo # start it until it's told to |
| 79 |
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 80 |
|
| 81 |
--echo # The below SELECT query will crash the server because some pages |
| 82 |
--echo # on the disk are corrupted |
| 83 |
--error 2013 |
| 84 |
SELECT * FROM t1; |
| 85 |
--source include/wait_until_disconnected.inc |
| 86 |
--echo [1(a)]: Repair the ibd file with innochecksum with --write=innodb |
| 87 |
--exec $INNOCHECKSUM --no-check --write=innodb $MYSQLD_DATADIR/test/t1.ibd |
| 88 |
# Verify the t1.ibd for --strict-check=innodb |
| 89 |
--exec $INNOCHECKSUM --strict-check=innodb $MYSQLD_DATADIR/test/t1.ibd |
| 90 |
|
| 91 |
--echo # Start the server |
| 92 |
--source include/start_mysqld.inc |
| 93 |
|
| 94 |
--disable_result_log |
| 95 |
select count(*) from t1; |
| 96 |
|
| 97 |
--echo # Shutdown the server |
| 98 |
--source include/shutdown_mysqld.inc |
| 99 |
|
| 100 |
--echo # Move the corrupted ibd file to t1.ibd |
| 101 |
--remove_file $MYSQLD_DATADIR/test/t1.ibd |
| 102 |
--copy_file $MYSQLD_DATADIR/test/t1.ibd.backup1 $MYSQLD_DATADIR/test/t1.ibd |
| 103 |
|
| 104 |
--echo [1(b)]: Repair the ibd file with innochecksum with --write=crc32 |
| 105 |
--exec $INNOCHECKSUM --no-check --write=crc32 $MYSQLD_DATADIR/test/t1.ibd |
| 106 |
#Verify the t1.ibd for --strict-check=crc32 |
| 107 |
--exec $INNOCHECKSUM --strict-check=crc32 $MYSQLD_DATADIR/test/t1.ibd |
| 108 |
|
| 109 |
--echo # Start the server |
| 110 |
--source include/start_mysqld.inc |
| 111 |
|
| 112 |
--disable_result_log |
| 113 |
select count(*) from t1; |
| 114 |
|
| 115 |
--echo # Shutdown the server |
| 116 |
--source include/shutdown_mysqld.inc |
| 117 |
|
| 118 |
--echo # Move the corrupted ib file to t1.ibd |
| 119 |
--remove_file $MYSQLD_DATADIR/test/t1.ibd |
| 120 |
--copy_file $MYSQLD_DATADIR/test/t1.ibd.backup1 $MYSQLD_DATADIR/test/t1.ibd |
| 121 |
|
| 122 |
--echo [1(c)]: Repair the ibd file with innochecksum with --write=none |
| 123 |
--exec $INNOCHECKSUM --no-check --write=none $MYSQLD_DATADIR/test/t1.ibd |
| 124 |
# Verify the t1.ibd for --strict-check=none |
| 125 |
--exec $INNOCHECKSUM --strict-check=none $MYSQLD_DATADIR/test/t1.ibd |
| 126 |
|
| 127 |
--echo # Start the server |
| 128 |
--source include/start_mysqld.inc |
| 129 |
|
| 130 |
--disable_result_log |
| 131 |
select * from t1; |
| 132 |
|
| 133 |
DROP TABLE t1; |
| 134 |
--echo [19]: Test Completed |
| 135 |
|
| 136 |
CREATE TABLE tab1(c1 INT PRIMARY KEY,c2 VARCHAR(20)) COMPRESSION="none", ENGINE=InnoDB; |
| 137 |
CREATE INDEX idx1 ON tab1(c2(10)); |
| 138 |
INSERT INTO tab1 VALUES(1, 'Innochecksum InnoDB1'); |
| 139 |
|
| 140 |
--echo # shutdown the server |
| 141 |
--source include/shutdown_mysqld.inc |
| 142 |
|
| 143 |
--remove_file $MYSQLD_DATADIR/test/t1.ibd.backup1 |
| 144 |
--echo [2]: Test for verbose short option, output from innochecksum |
| 145 |
--exec $INNOCHECKSUM -v $MYSQLD_DATADIR/test/tab1.ibd 2>$MYSQLTEST_VARDIR/tmp/ver_output |
| 146 |
|
| 147 |
perl; |
| 148 |
use strict; |
| 149 |
use warnings; |
| 150 |
use File::Copy; |
| 151 |
my $dir = $ENV{'MYSQLTEST_VARDIR'}; |
| 152 |
opendir(DIR, $dir) or die $!; |
| 153 |
my $file= 'ver_output'; |
| 154 |
# open file in write mode |
| 155 |
open IN_FILE,"<", "$dir/tmp/$file" or die $!; |
| 156 |
open OUT_FILE, ">", "$dir/tmp/tmpfile" or die $!; |
| 157 |
while(<IN_FILE>) |
| 158 |
{ |
| 159 |
unless ($_=~ /^debug.*$/) { |
| 160 |
print OUT_FILE $_; |
| 161 |
} |
| 162 |
} |
| 163 |
close(IN_FILE); |
| 164 |
close(OUT_FILE); |
| 165 |
# move the new content from tmp file to the original file. |
| 166 |
move ("$dir/tmp/tmpfile", "$dir/tmp/$file"); |
| 167 |
closedir(DIR); |
| 168 |
EOF |
| 169 |
|
| 170 |
--echo # Print the verbose output |
| 171 |
cat_file $MYSQLTEST_VARDIR/tmp/ver_output; |
| 172 |
--remove_file $MYSQLTEST_VARDIR/tmp/ver_output |
| 173 |
|
| 174 |
--echo [3]: test for --verbose option with --strict-check=innodb for innochecksum |
| 175 |
--echo : With verbose long option. |
| 176 |
--exec $INNOCHECKSUM --verbose --strict-check=crc32 $MYSQLD_DATADIR/test/tab1.ibd 2>$MYSQLTEST_VARDIR/tmp/ver_output |
| 177 |
|
| 178 |
perl; |
| 179 |
use strict; |
| 180 |
use warnings; |
| 181 |
use File::Copy; |
| 182 |
my $dir = $ENV{'MYSQLTEST_VARDIR'}; |
| 183 |
opendir(DIR, $dir) or die $!; |
| 184 |
my $file= 'ver_output'; |
| 185 |
# open file in write mode |
| 186 |
open IN_FILE,"<", "$dir/tmp/$file" or die $!; |
| 187 |
open OUT_FILE, ">", "$dir/tmp/tmpfile" or die $!; |
| 188 |
while(<IN_FILE>) |
| 189 |
{ |
| 190 |
unless ($_=~ /^debug.*$/) { |
| 191 |
print OUT_FILE $_; |
| 192 |
} |
| 193 |
} |
| 194 |
close(IN_FILE); |
| 195 |
close(OUT_FILE); |
| 196 |
# move the new content from tmp file to the orginal file. |
| 197 |
move ("$dir/tmp/tmpfile", "$dir/tmp/$file"); |
| 198 |
closedir(DIR); |
| 199 |
EOF |
| 200 |
|
| 201 |
--echo # Print the verbose output |
| 202 |
cat_file $MYSQLTEST_VARDIR/tmp/ver_output; |
| 203 |
--remove_file $MYSQLTEST_VARDIR/tmp/ver_output |
| 204 |
|
| 205 |
--echo [4]: Test for --allow-mismatches =99 |
| 206 |
|
| 207 |
--echo # Expect the fails for checksum mismatches. Print the error message. |
| 208 |
--exec $INNOCHECKSUM --allow-mismatches=99 --strict-check=none $MYSQLD_DATADIR/test/tab1.ibd 2>$MYSQLTEST_VARDIR/log/my_restart.err |
| 209 |
# Remove extra line which will cause result-content mismatch on 4k page |
| 210 |
# size. |
| 211 |
perl; |
| 212 |
use strict; |
| 213 |
use warnings; |
| 214 |
my $file = $ENV{'SEARCH_FILE'}; |
| 215 |
open IN_FILE,"<", $file or die $!; |
| 216 |
while(<IN_FILE>) |
| 217 |
{ |
| 218 |
if (!m/page number=7/) |
| 219 |
{ |
| 220 |
s/space=\d+, page number=\d+/space=X, page number=Y/; |
| 221 |
print; |
| 222 |
} |
| 223 |
} |
| 224 |
close(IN_FILE); |
| 225 |
EOF |
| 226 |
|
| 227 |
|
| 228 |
--echo [5]: Test checksum check for page: 2 to page:5 |
| 229 |
--exec $INNOCHECKSUM -s 2 -e 5 $MYSQLD_DATADIR/test/tab1.ibd |
| 230 |
|
| 231 |
--echo [6]: Test for checksum check for only pageno.= 2 |
| 232 |
--exec $INNOCHECKSUM -p 2 $MYSQLD_DATADIR/test/tab1.ibd |
| 233 |
|
| 234 |
--echo [7]: Further Test are for rewrite checksum (innodb|crc32|none) for all ibd file & start the server. |
| 235 |
|
| 236 |
# Cleanup |
| 237 |
--echo # Restart the server |
| 238 |
--source include/start_mysqld.inc |
| 239 |
|
| 240 |
DROP TABLE tab1; |
| 241 |
SET GLOBAL innodb_file_per_table=default; |