| 1 |
# |
| 2 |
# Test opening a corrupted table. |
| 3 |
# |
| 4 |
|
| 5 |
# Valgrind can hang or return spurious messages on DBUG_SUICIDE |
| 6 |
source include/not_valgrind.inc; |
| 7 |
# Avoid CrashReporter popup on Mac |
| 8 |
source include/not_crashrep.inc; |
| 9 |
# Require InnoDB |
| 10 |
# Require Debug for SET DEBUG |
| 11 |
source include/have_debug.inc; |
| 12 |
|
| 13 |
--disable_query_log |
| 14 |
CALL mtr.add_suppression("\\[ERROR\\] .* Unable to read page \\[page id: space=.*, page number=.*\\] into the buffer pool after 100 attempts"); |
| 15 |
CALL mtr.add_suppression("\\[ERROR\\] .* Database page corruption on disk or a failed"); |
| 16 |
# ib::fatal() calls ut_error |
| 17 |
call mtr.add_suppression("\\[ERROR\\] .* Assertion failure: buf0buf\.cc:[0-9]+:ib::fatal triggered"); |
| 18 |
--enable_query_log |
| 19 |
|
| 20 |
# Disable compression for this table, otherwise our pattern matching below |
| 21 |
# will not work |
| 22 |
--echo # Create and populate the table to be corrupted |
| 23 |
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) COMPRESSION="none", |
| 24 |
ROW_FORMAT=COMPACT ENGINE=InnoDB; |
| 25 |
INSERT INTO t1 (b) VALUES ('corrupt me'); |
| 26 |
--disable_query_log |
| 27 |
--let $i = 10 |
| 28 |
while ($i) |
| 29 |
{ |
| 30 |
INSERT INTO t1 (b) VALUES (REPEAT('abcdefghijklmnopqrstuvwxyz', 100)); |
| 31 |
dec $i; |
| 32 |
} |
| 33 |
--enable_query_log |
| 34 |
INSERT INTO t1 (b) VALUES ('corrupt me'); |
| 35 |
|
| 36 |
let $MYSQLD_DATADIR=`select @@datadir`; |
| 37 |
let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd; |
| 38 |
|
| 39 |
--source include/shutdown_mysqld.inc |
| 40 |
|
| 41 |
--echo # Backup the t1.ibd before corrupting |
| 42 |
--copy_file $t1_IBD $MYSQLD_DATADIR/test/t1.ibd.backup |
| 43 |
|
| 44 |
--echo # Corrupt the table |
| 45 |
|
| 46 |
perl; |
| 47 |
use strict; |
| 48 |
use warnings; |
| 49 |
use Fcntl qw(:DEFAULT :seek); |
| 50 |
|
| 51 |
my $ibd_file = $ENV{'t1_IBD'}; |
| 52 |
|
| 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 |
--source include/start_mysqld.inc |
| 72 |
|
| 73 |
SET DEBUG = '+d,innodb_page_corruption_retries'; |
| 74 |
|
| 75 |
--echo # Write file to make mysql-test-run.pl expect the "crash", but don't |
| 76 |
--echo # start it until it's told to |
| 77 |
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 78 |
|
| 79 |
--echo # The below SELECT query will crash the server because some pages |
| 80 |
--echo # on the disk are corrupted |
| 81 |
--error 2013 |
| 82 |
SELECT * FROM t1; |
| 83 |
|
| 84 |
# Disconnect all connections to release all locks on t1.ibd file. |
| 85 |
--disable_reconnect |
| 86 |
--source include/wait_until_disconnected.inc |
| 87 |
|
| 88 |
--echo # Restore the original t1.ibd |
| 89 |
--remove_file $MYSQLD_DATADIR/test/t1.ibd |
| 90 |
--move_file $MYSQLD_DATADIR/test/t1.ibd.backup $MYSQLD_DATADIR/test/t1.ibd |
| 91 |
|
| 92 |
--source include/start_mysqld.inc |
| 93 |
|
| 94 |
# Note SET DEBUG = '-d,innodb_page_corruption_retries' is not required |
| 95 |
# because the session information is lost after server restart |
| 96 |
|
| 97 |
--echo # Cleanup |
| 98 |
DROP TABLE t1; |