| 1 |
# |
| 2 |
# Test opening a corrupted table. |
| 3 |
# |
| 4 |
# Restarting is not supported under embedded |
| 5 |
-- source include/not_embedded.inc |
| 6 |
# Require InnoDB |
| 7 |
-- source include/have_innodb.inc |
| 8 |
-- source include/not_encrypted.inc |
| 9 |
|
| 10 |
--disable_query_log |
| 11 |
call mtr.add_suppression("InnoDB: Table `test`\\.`t1` is corrupted\\. Please drop the table and recreate\\."); |
| 12 |
call mtr.add_suppression("InnoDB: Failed to read page [1-9][0-9]* from file '.*test.t1\\.ibd'"); |
| 13 |
call mtr.add_suppression("InnoDB: We detected index corruption in an InnoDB type table"); |
| 14 |
call mtr.add_suppression("Index for table 't1' is corrupt; try to repair it"); |
| 15 |
call mtr.add_suppression("InnoDB: File '.*test/t1\\.ibd' is corrupted"); |
| 16 |
--enable_query_log |
| 17 |
|
| 18 |
--echo # Ensure that purge will not crash on the table after we corrupt it. |
| 19 |
SET GLOBAL innodb_fast_shutdown=0; |
| 20 |
|
| 21 |
--echo # Create and populate the table to be corrupted |
| 22 |
|
| 23 |
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ENGINE=InnoDB; |
| 24 |
INSERT INTO t1 (b) VALUES ('corrupt me'); |
| 25 |
--disable_query_log |
| 26 |
--let $i = 10 |
| 27 |
while ($i) |
| 28 |
{ |
| 29 |
INSERT INTO t1 (b) VALUES (REPEAT('abcdefghijklmnopqrstuvwxyz', 100)); |
| 30 |
dec $i; |
| 31 |
} |
| 32 |
--enable_query_log |
| 33 |
INSERT INTO t1 (b) VALUES ('corrupt me'); |
| 34 |
|
| 35 |
let $MYSQLD_DATADIR=`select @@datadir`; |
| 36 |
let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd; |
| 37 |
|
| 38 |
--source include/shutdown_mysqld.inc |
| 39 |
|
| 40 |
--echo # Corrupt the table |
| 41 |
|
| 42 |
perl; |
| 43 |
use strict; |
| 44 |
use warnings; |
| 45 |
use Fcntl qw(:DEFAULT :seek); |
| 46 |
|
| 47 |
my $ibd_file = $ENV{'t1_IBD'}; |
| 48 |
|
| 49 |
my $chunk; |
| 50 |
my $len; |
| 51 |
|
| 52 |
sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file"; |
| 53 |
|
| 54 |
while ($len = sysread IBD_FILE, $chunk, 1024) |
| 55 |
{ |
| 56 |
if ($chunk =~ s/corrupt me/korrupt me/) |
| 57 |
{ |
| 58 |
print "Munged a string.\n"; |
| 59 |
sysseek IBD_FILE, -$len, SEEK_CUR; |
| 60 |
syswrite IBD_FILE, $chunk, $len; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
close IBD_FILE; |
| 65 |
EOF |
| 66 |
|
| 67 |
--source include/start_mysqld.inc |
| 68 |
|
| 69 |
--echo # Now t1 is corrupted but we should not crash |
| 70 |
|
| 71 |
--error ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE |
| 72 |
SELECT * FROM t1; |
| 73 |
|
| 74 |
--error 126,ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE |
| 75 |
INSERT INTO t1(b) VALUES('abcdef'); |
| 76 |
|
| 77 |
--error ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE |
| 78 |
UPDATE t1 set b = 'deadbeef' where a = 1; |
| 79 |
|
| 80 |
--echo # Cleanup, this must be possible |
| 81 |
DROP TABLE t1; |