summaryrefslogtreecommitdiff
path: root/mysql-test/suite/innodb/t/innodb_bug14147491.test
blob: ee3519c53fcb77b371d916b2025ec81c63e0d7dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
# Test opening a corrupted table.
#

# Don't test under valgrind, memory leaks will occur
source include/not_valgrind.inc;
# Avoid CrashReporter popup on Mac
source include/not_crashrep.inc;
# Don't test under embedded
source include/not_embedded.inc;
# Require InnoDB
source include/have_innodb.inc;

CALL mtr.add_suppression("InnoDB: Error: Unable to read tablespace .* page no .* into the buffer pool after 100 attempts");
CALL mtr.add_suppression("InnoDB: Warning: database page corruption or a failed");

--echo # Create and populate the table to be corrupted
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ENGINE=InnoDB;
INSERT INTO t1 (b) VALUES ('corrupt me');
--disable_query_log
--let $i = 10
while ($i)
{
  INSERT INTO t1 (b) VALUES (REPEAT('abcdefghijklmnopqrstuvwxyz', 100));
  dec $i;
}
--enable_query_log
INSERT INTO t1 (b) VALUES ('corrupt me');

--echo # Restart server to flush buffers
source include/restart_mysqld.inc;

--echo # Corrupt the table
let $MYSQLD_DATADIR=`select @@datadir`;
let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd;

perl;
use strict;
use warnings;
use Fcntl qw(:DEFAULT :seek);

my $ibd_file = $ENV{'t1_IBD'};

my $chunk;
my $len;

sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file";

while ($len = sysread IBD_FILE, $chunk, 1024)
{
  if ($chunk =~ s/corrupt me/korrupt me/)
  {
    print "Munged a string.\n";
    sysseek IBD_FILE, -$len, SEEK_CUR;
    syswrite IBD_FILE, $chunk, $len;
  }
}

close IBD_FILE;
EOF

--echo # Write file to make mysql-test-run.pl expect crash and restart
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

--error 2013
SELECT * FROM t1;

--echo # Turn on reconnect
--enable_reconnect

--echo # Wait for server to fully start
--source include/wait_until_connected_again.inc

--echo # Cleanup
DROP TABLE t1;