Skip to content

Commit 13d4dfd

Browse files
committed
MDEV-13626 Merge InnoDB test cases from MySQL 5.7 (part 1)
Import the test innodb.alter_crash
1 parent 95f6026 commit 13d4dfd

File tree

2 files changed

+376
-0
lines changed

2 files changed

+376
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#
2+
# Bug#20015132 ALTER TABLE FAILS TO CHECK IF TABLE IS CORRUPTED
3+
#
4+
CREATE TABLE t1(c1 INT PRIMARY KEY, c2 CHAR(1), c3 INT UNSIGNED) ENGINE=InnoDB;
5+
SET DEBUG='+d,ib_create_table_fail_too_many_trx';
6+
ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3);
7+
ERROR HY000: Too many active concurrent transactions
8+
SET DEBUG='-d,ib_create_table_fail_too_many_trx';
9+
ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3);
10+
SET DEBUG='+d,dict_set_index_corrupted';
11+
CHECK TABLE t1;
12+
Table Op Msg_type Msg_text
13+
test.t1 check Warning InnoDB: The B-tree of index c2 is corrupted.
14+
test.t1 check Warning InnoDB: The B-tree of index c3 is corrupted.
15+
test.t1 check error Corrupt
16+
# restart
17+
CHECK TABLE t1;
18+
Table Op Msg_type Msg_text
19+
test.t1 check Warning InnoDB: Index c2 is marked as corrupted
20+
test.t1 check Warning InnoDB: Index c3 is marked as corrupted
21+
test.t1 check error Corrupt
22+
ALTER TABLE t1 DROP INDEX c2;
23+
CHECK TABLE t1;
24+
Table Op Msg_type Msg_text
25+
test.t1 check Warning InnoDB: Index c3 is marked as corrupted
26+
test.t1 check error Corrupt
27+
ALTER TABLE t1 ADD INDEX (c2,c3);
28+
ERROR 42000: Can't open table
29+
ALTER TABLE t1 CHANGE c3 c3 INT NOT NULL;
30+
CHECK TABLE t1;
31+
Table Op Msg_type Msg_text
32+
test.t1 check status OK
33+
ALTER TABLE t1 ADD INDEX (c2,c3);
34+
DROP TABLE t1;
35+
#
36+
# Bug #14669848 CRASH DURING ALTER MAKES ORIGINAL TABLE INACCESSIBLE
37+
#
38+
# -- Scenario 1:
39+
# Crash the server in ha_innobase::commit_inplace_alter_table()
40+
# just after committing the dictionary changes.
41+
CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=innodb;
42+
INSERT INTO t1 VALUES (1,2),(3,4);
43+
SET DEBUG='d,innodb_alter_commit_crash_after_commit';
44+
ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
45+
ERROR HY000: Lost connection to MySQL server during query
46+
# Restart mysqld after the crash and reconnect.
47+
# restart
48+
# Manual *.frm recovery begin.
49+
# Manual recovery end
50+
FLUSH TABLES;
51+
# Drop the orphaned original table.
52+
# Files in datadir after manual recovery.
53+
t1.frm
54+
t1.ibd
55+
SHOW TABLES;
56+
Tables_in_test
57+
t1
58+
SHOW CREATE TABLE t1;
59+
Table Create Table
60+
t1 CREATE TABLE `t1` (
61+
`f1` int(11) NOT NULL,
62+
`f2` int(11) NOT NULL,
63+
PRIMARY KEY (`f2`,`f1`)
64+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
65+
INSERT INTO t1 VALUES (5,6),(7,8);
66+
SELECT * FROM t1;
67+
f1 f2
68+
1 2
69+
3 4
70+
5 6
71+
7 8
72+
DROP TABLE t1;
73+
CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB;
74+
ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
75+
DROP TABLE t1;
76+
# -- Scenario 2:
77+
# Crash the server in ha_innobase::commit_inplace_alter_table()
78+
# just before committing the dictionary changes, but after
79+
# writing the MLOG_FILE_RENAME records. As the mini-transaction
80+
# is not committed, the renames will not be replayed.
81+
CREATE TABLE t2 (f1 int not null, f2 int not null) ENGINE=InnoDB;
82+
INSERT INTO t2 VALUES (1,2),(3,4);
83+
SET DEBUG='d,innodb_alter_commit_crash_before_commit';
84+
ALTER TABLE t2 ADD PRIMARY KEY (f2, f1);
85+
ERROR HY000: Lost connection to MySQL server during query
86+
# Startup the server after the crash
87+
# restart
88+
# Read and remember the temporary table name
89+
# Manual *.frm recovery begin. The dictionary was not updated
90+
# and the files were not renamed. The rebuilt table
91+
# was left behind on purpose, to faciliate data recovery.
92+
# Manual recovery end
93+
# Drop the orphaned rebuilt table.
94+
SHOW TABLES;
95+
Tables_in_test
96+
t2
97+
INSERT INTO t2 VALUES (5,6),(7,8);
98+
SELECT * from t2;
99+
f1 f2
100+
1 2
101+
3 4
102+
5 6
103+
7 8
104+
SHOW CREATE TABLE t2;
105+
Table Create Table
106+
t2 CREATE TABLE `t2` (
107+
`f1` int(11) NOT NULL,
108+
`f2` int(11) NOT NULL
109+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
110+
DROP TABLE t2;
111+
CREATE TABLE t2 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB;
112+
ALTER TABLE t2 ADD PRIMARY KEY (f2, f1);
113+
DROP TABLE t2;
114+
# -------------------------
115+
# End of Testing Scenario 2
116+
# -------------------------
117+
#
118+
# Bug#19330255 WL#7142 - CRASH DURING ALTER TABLE LEADS TO
119+
# DATA DICTIONARY INCONSISTENCY
120+
#
121+
CREATE TABLE t1(a int PRIMARY KEY, b varchar(255), c int NOT NULL);
122+
INSERT INTO t1 SET a=1,c=2;
123+
SET DEBUG='d,innodb_alter_commit_crash_after_commit';
124+
ALTER TABLE t1 ADD INDEX (b), CHANGE c d int;
125+
ERROR HY000: Lost connection to MySQL server during query
126+
# Restart mysqld after the crash and reconnect.
127+
# restart
128+
# Manual *.frm recovery begin.
129+
# Manual recovery end
130+
FLUSH TABLES;
131+
# Drop the orphaned original table.
132+
# Files in datadir after manual recovery.
133+
t1.frm
134+
t1.ibd
135+
SHOW TABLES;
136+
Tables_in_test
137+
t1
138+
SHOW CREATE TABLE t1;
139+
Table Create Table
140+
t1 CREATE TABLE `t1` (
141+
`a` int(11) NOT NULL,
142+
`b` varchar(255) DEFAULT NULL,
143+
`d` int(11) DEFAULT NULL,
144+
PRIMARY KEY (`a`),
145+
KEY `b` (`b`)
146+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
147+
UPDATE t1 SET d=NULL;
148+
SELECT * FROM t1;
149+
a b d
150+
1 NULL NULL
151+
DROP TABLE t1;
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Crash-safe InnoDB ALTER operations
2+
3+
--source include/not_valgrind.inc
4+
--source include/not_embedded.inc
5+
--source include/have_innodb.inc
6+
--source include/have_debug.inc
7+
--source include/not_crashrep.inc
8+
9+
--disable_query_log
10+
call mtr.add_suppression('InnoDB: cannot find a free slot for an undo log');
11+
call mtr.add_suppression('InnoDB: row_merge_rename_index_to_add failed with error 47');
12+
call mtr.add_suppression('InnoDB: Flagged corruption of `c[23]`');
13+
call mtr.add_suppression('InnoDB: Index `c[23]` .*is corrupted');
14+
--enable_query_log
15+
16+
--echo #
17+
--echo # Bug#20015132 ALTER TABLE FAILS TO CHECK IF TABLE IS CORRUPTED
18+
--echo #
19+
20+
CREATE TABLE t1(c1 INT PRIMARY KEY, c2 CHAR(1), c3 INT UNSIGNED) ENGINE=InnoDB;
21+
SET DEBUG='+d,ib_create_table_fail_too_many_trx';
22+
--error ER_TOO_MANY_CONCURRENT_TRXS
23+
ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3);
24+
25+
SET DEBUG='-d,ib_create_table_fail_too_many_trx';
26+
ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3);
27+
# Flag the secondary indexes corrupted.
28+
SET DEBUG='+d,dict_set_index_corrupted';
29+
CHECK TABLE t1;
30+
31+
# Ensure that the corruption is permanent.
32+
--source include/restart_mysqld.inc
33+
CHECK TABLE t1;
34+
ALTER TABLE t1 DROP INDEX c2;
35+
CHECK TABLE t1;
36+
# We refuse an ALTER TABLE that would modify the InnoDB data dictionary
37+
# while leaving some of the table corrupted.
38+
--error ER_CHECK_NO_SUCH_TABLE
39+
ALTER TABLE t1 ADD INDEX (c2,c3);
40+
# This will rebuild the table, uncorrupting all secondary indexes.
41+
ALTER TABLE t1 CHANGE c3 c3 INT NOT NULL;
42+
CHECK TABLE t1;
43+
ALTER TABLE t1 ADD INDEX (c2,c3);
44+
DROP TABLE t1;
45+
46+
let $MYSQLD_DATADIR= `select @@datadir`;
47+
let datadir= `select @@datadir`;
48+
49+
# These are from include/shutdown_mysqld.inc and allow to call start_mysqld.inc
50+
--let $_server_id= `SELECT @@server_id`
51+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect
52+
53+
--echo #
54+
--echo # Bug #14669848 CRASH DURING ALTER MAKES ORIGINAL TABLE INACCESSIBLE
55+
--echo #
56+
--echo # -- Scenario 1:
57+
--echo # Crash the server in ha_innobase::commit_inplace_alter_table()
58+
--echo # just after committing the dictionary changes.
59+
60+
CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=innodb;
61+
INSERT INTO t1 VALUES (1,2),(3,4);
62+
SET DEBUG='d,innodb_alter_commit_crash_after_commit';
63+
64+
let $orig_table_id = `SELECT table_id
65+
FROM information_schema.innodb_sys_tables
66+
WHERE name = 'test/t1'`;
67+
68+
# Write file to make mysql-test-run.pl expect crash
69+
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
70+
71+
--error 2013
72+
ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
73+
74+
--echo # Restart mysqld after the crash and reconnect.
75+
--source include/start_mysqld.inc
76+
77+
let $temp_table_name = `SELECT SUBSTR(name, 6)
78+
FROM information_schema.innodb_sys_tables
79+
WHERE table_id = $orig_table_id`;
80+
81+
--echo # Manual *.frm recovery begin.
82+
83+
--move_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/$temp_table_name.frm
84+
85+
perl;
86+
my @frm_file = glob "$ENV{'datadir'}/test/#sql-*.frm";
87+
my $t1_frm = "$ENV{'datadir'}/test/t1.frm";
88+
rename($frm_file[0], $t1_frm);
89+
EOF
90+
91+
--echo # Manual recovery end
92+
93+
FLUSH TABLES;
94+
95+
--echo # Drop the orphaned original table.
96+
--disable_query_log
97+
eval DROP TABLE `#mysql50#$temp_table_name`;
98+
--enable_query_log
99+
100+
--echo # Files in datadir after manual recovery.
101+
--list_files $MYSQLD_DATADIR/test
102+
103+
SHOW TABLES;
104+
SHOW CREATE TABLE t1;
105+
INSERT INTO t1 VALUES (5,6),(7,8);
106+
SELECT * FROM t1;
107+
DROP TABLE t1;
108+
109+
CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB;
110+
ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
111+
DROP TABLE t1;
112+
113+
--echo # -- Scenario 2:
114+
--echo # Crash the server in ha_innobase::commit_inplace_alter_table()
115+
--echo # just before committing the dictionary changes, but after
116+
--echo # writing the MLOG_FILE_RENAME records. As the mini-transaction
117+
--echo # is not committed, the renames will not be replayed.
118+
119+
CREATE TABLE t2 (f1 int not null, f2 int not null) ENGINE=InnoDB;
120+
INSERT INTO t2 VALUES (1,2),(3,4);
121+
SET DEBUG='d,innodb_alter_commit_crash_before_commit';
122+
123+
let $orig_table_id = `SELECT table_id
124+
FROM information_schema.innodb_sys_tables
125+
WHERE name = 'test/t2'`;
126+
127+
# Write file to make mysql-test-run.pl expect crash
128+
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
129+
130+
--error 2013
131+
ALTER TABLE t2 ADD PRIMARY KEY (f2, f1);
132+
133+
--echo # Startup the server after the crash
134+
--source include/start_mysqld.inc
135+
136+
--echo # Read and remember the temporary table name
137+
let $temp_table_name = `SELECT SUBSTRING(name,6)
138+
FROM information_schema.innodb_sys_tables
139+
WHERE name LIKE "test/#sql-ib$orig_table_id%"`;
140+
# This second copy is an environment variable for the perl script below.
141+
let temp_table_name = $temp_table_name;
142+
143+
--echo # Manual *.frm recovery begin. The dictionary was not updated
144+
--echo # and the files were not renamed. The rebuilt table
145+
--echo # was left behind on purpose, to faciliate data recovery.
146+
147+
perl;
148+
my @frm_file = glob "$ENV{'datadir'}/test/#sql-*.frm";
149+
my $target_frm = "$ENV{'datadir'}/test/$ENV{'temp_table_name'}.frm";
150+
rename($frm_file[0], $target_frm);
151+
EOF
152+
153+
--echo # Manual recovery end
154+
155+
--echo # Drop the orphaned rebuilt table.
156+
--disable_query_log
157+
eval DROP TABLE `#mysql50#$temp_table_name`;
158+
--enable_query_log
159+
160+
SHOW TABLES;
161+
INSERT INTO t2 VALUES (5,6),(7,8);
162+
SELECT * from t2;
163+
SHOW CREATE TABLE t2;
164+
DROP TABLE t2;
165+
166+
CREATE TABLE t2 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB;
167+
ALTER TABLE t2 ADD PRIMARY KEY (f2, f1);
168+
DROP TABLE t2;
169+
--list_files $MYSQLD_DATADIR/test
170+
171+
--echo # -------------------------
172+
--echo # End of Testing Scenario 2
173+
--echo # -------------------------
174+
175+
--echo #
176+
--echo # Bug#19330255 WL#7142 - CRASH DURING ALTER TABLE LEADS TO
177+
--echo # DATA DICTIONARY INCONSISTENCY
178+
--echo #
179+
180+
CREATE TABLE t1(a int PRIMARY KEY, b varchar(255), c int NOT NULL);
181+
INSERT INTO t1 SET a=1,c=2;
182+
SET DEBUG='d,innodb_alter_commit_crash_after_commit';
183+
184+
let $orig_table_id = `select table_id from
185+
information_schema.innodb_sys_tables where name = 'test/t1'`;
186+
187+
# Write file to make mysql-test-run.pl expect crash
188+
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
189+
190+
--error 2013
191+
ALTER TABLE t1 ADD INDEX (b), CHANGE c d int;
192+
193+
--echo # Restart mysqld after the crash and reconnect.
194+
--source include/start_mysqld.inc
195+
196+
let $temp_table_name = `SELECT SUBSTR(name, 6)
197+
FROM information_schema.innodb_sys_tables
198+
WHERE table_id = $orig_table_id`;
199+
200+
--echo # Manual *.frm recovery begin.
201+
--move_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/$temp_table_name.frm
202+
203+
perl;
204+
my @frm_file = glob "$ENV{'datadir'}/test/#sql-*.frm";
205+
my $t1_frm = "$ENV{'datadir'}/test/t1.frm";
206+
rename($frm_file[0], $t1_frm);
207+
EOF
208+
209+
--echo # Manual recovery end
210+
211+
FLUSH TABLES;
212+
213+
--echo # Drop the orphaned original table.
214+
--disable_query_log
215+
eval DROP TABLE `#mysql50#$temp_table_name`;
216+
--enable_query_log
217+
218+
--echo # Files in datadir after manual recovery.
219+
--list_files $MYSQLD_DATADIR/test
220+
221+
SHOW TABLES;
222+
SHOW CREATE TABLE t1;
223+
UPDATE t1 SET d=NULL;
224+
SELECT * FROM t1;
225+
DROP TABLE t1;

0 commit comments

Comments
 (0)