| 1 |
# Crash-safe InnoDB ALTER operations |
| 2 |
|
| 3 |
--source include/not_valgrind.inc |
| 4 |
--source include/have_debug.inc |
| 5 |
--source include/not_crashrep.inc |
| 6 |
|
| 7 |
--disable_query_log |
| 8 |
call mtr.add_suppression(' Cannot find a free slot for an undo log'); |
| 9 |
call mtr.add_suppression(' ddl_rename_index_to_add failed with error 47'); |
| 10 |
call mtr.add_suppression(' Flagged corruption of `c[23]`'); |
| 11 |
call mtr.add_suppression(' Index `c[23]` .*is corrupted'); |
| 12 |
--enable_query_log |
| 13 |
|
| 14 |
--echo # |
| 15 |
--echo # Bug#20015132 ALTER TABLE FAILS TO CHECK IF TABLE IS CORRUPTED |
| 16 |
--echo # |
| 17 |
|
| 18 |
CREATE TABLE t1(c1 INT PRIMARY KEY, c2 CHAR(1), c3 INT UNSIGNED) ENGINE=InnoDB; |
| 19 |
--disable_testcase BUG#0000 |
| 20 |
SET DEBUG='+d,ib_create_table_fail_too_many_trx'; |
| 21 |
--error ER_TOO_MANY_CONCURRENT_TRXS |
| 22 |
ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3); |
| 23 |
|
| 24 |
SET DEBUG='-d,ib_create_table_fail_too_many_trx'; |
| 25 |
--enable_testcase |
| 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 |
--echo # |
| 50 |
--echo # Bug #14669848 CRASH DURING ALTER MAKES ORIGINAL TABLE INACCESSIBLE |
| 51 |
--echo # |
| 52 |
--echo # -- Scenario 1: |
| 53 |
--echo # Crash the server in ha_innobase::commit_inplace_alter_table() |
| 54 |
--echo # just after committing the dictionary changes. |
| 55 |
|
| 56 |
CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=innodb; |
| 57 |
INSERT INTO t1 VALUES (1,2),(3,4); |
| 58 |
SET DEBUG='d,innodb_alter_commit_crash_after_commit'; |
| 59 |
|
| 60 |
let $orig_table_id = `SELECT table_id |
| 61 |
FROM information_schema.innodb_tables |
| 62 |
WHERE name = 'test/t1'`; |
| 63 |
|
| 64 |
--source include/expect_crash.inc |
| 65 |
|
| 66 |
--error CR_SERVER_LOST |
| 67 |
ALTER TABLE t1 ADD PRIMARY KEY (f2, f1); |
| 68 |
|
| 69 |
--echo # Restart mysqld after the crash and reconnect. |
| 70 |
--source include/start_mysqld.inc |
| 71 |
|
| 72 |
let $temp_table_name = `SELECT SUBSTR(name, 6) |
| 73 |
FROM information_schema.innodb_tables |
| 74 |
WHERE table_id = $orig_table_id`; |
| 75 |
|
| 76 |
--echo # Files in datadir after manual recovery. |
| 77 |
--list_files $MYSQLD_DATADIR/test |
| 78 |
|
| 79 |
SHOW TABLES; |
| 80 |
SHOW CREATE TABLE t1; |
| 81 |
INSERT INTO t1 VALUES (5,6),(7,8); |
| 82 |
SELECT * FROM t1; |
| 83 |
DROP TABLE t1; |
| 84 |
|
| 85 |
CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB; |
| 86 |
ALTER TABLE t1 ADD PRIMARY KEY (f2, f1); |
| 87 |
DROP TABLE t1; |
| 88 |
|
| 89 |
--echo # -- Scenario 2: |
| 90 |
--echo # Crash the server in ha_innobase::commit_inplace_alter_table() |
| 91 |
--echo # just before committing the dictionary changes, but after |
| 92 |
--echo # writing the MLOG_FILE_RENAME records. As the mini-transaction |
| 93 |
--echo # is not committed, the renames will not be replayed. |
| 94 |
|
| 95 |
CREATE TABLE t2 (f1 int not null, f2 int not null) ENGINE=InnoDB; |
| 96 |
INSERT INTO t2 VALUES (1,2),(3,4); |
| 97 |
SET DEBUG='d,innodb_alter_commit_crash_before_commit'; |
| 98 |
|
| 99 |
let $orig_table_id = `SELECT table_id |
| 100 |
FROM information_schema.innodb_tables |
| 101 |
WHERE name = 'test/t2'`; |
| 102 |
|
| 103 |
--source include/expect_crash.inc |
| 104 |
|
| 105 |
--error CR_SERVER_LOST |
| 106 |
ALTER TABLE t2 ADD PRIMARY KEY (f2, f1); |
| 107 |
|
| 108 |
--echo # Startup the server after the crash |
| 109 |
--source include/start_mysqld.inc |
| 110 |
|
| 111 |
SHOW TABLES; |
| 112 |
INSERT INTO t2 VALUES (5,6),(7,8); |
| 113 |
SELECT * from t2; |
| 114 |
SHOW CREATE TABLE t2; |
| 115 |
DROP TABLE t2; |
| 116 |
|
| 117 |
CREATE TABLE t2 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB; |
| 118 |
ALTER TABLE t2 ADD PRIMARY KEY (f2, f1); |
| 119 |
DROP TABLE t2; |
| 120 |
--list_files $MYSQLD_DATADIR/test |
| 121 |
|
| 122 |
--echo # ------------------------- |
| 123 |
--echo # End of Testing Scenario 2 |
| 124 |
--echo # ------------------------- |
| 125 |
|
| 126 |
--echo # |
| 127 |
--echo # Bug#19330255 CRASH DURING ALTER TABLE LEADS TO |
| 128 |
--echo # DATA DICTIONARY INCONSISTENCY |
| 129 |
--echo # |
| 130 |
|
| 131 |
CREATE TABLE t1(a int PRIMARY KEY, b varchar(150), c int NOT NULL); |
| 132 |
INSERT INTO t1 SET a=1,c=2; |
| 133 |
SET DEBUG='d,innodb_alter_commit_crash_after_commit'; |
| 134 |
|
| 135 |
let $orig_table_id = `select table_id from |
| 136 |
information_schema.innodb_tables where name = 'test/t1'`; |
| 137 |
|
| 138 |
--source include/expect_crash.inc |
| 139 |
|
| 140 |
--error CR_SERVER_LOST |
| 141 |
ALTER TABLE t1 ADD INDEX (b), CHANGE c d int; |
| 142 |
|
| 143 |
--echo # Restart mysqld after the crash and reconnect. |
| 144 |
--source include/start_mysqld.inc |
| 145 |
|
| 146 |
--echo # Files in datadir after manual recovery. |
| 147 |
--list_files $MYSQLD_DATADIR/test |
| 148 |
|
| 149 |
SHOW TABLES; |
| 150 |
SHOW CREATE TABLE t1; |
| 151 |
SELECT * FROM t1; |
| 152 |
DROP TABLE t1; |