| 1 |
# WL#7142 InnoDB: Simplify tablespace discovery during crash recovery |
| 2 |
# Test the detection of duplicate tablespaces. |
| 3 |
|
| 4 |
--source include/have_innodb.inc |
| 5 |
--source include/no_valgrind_without_big.inc |
| 6 |
|
| 7 |
# Embedded server does not support crashing |
| 8 |
--source include/not_embedded.inc |
| 9 |
|
| 10 |
call mtr.add_suppression("InnoDB: Header page consists of zero bytes in datafile:"); |
| 11 |
FLUSH TABLES; |
| 12 |
|
| 13 |
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 14 |
|
| 15 |
--source include/restart_mysqld.inc |
| 16 |
--source include/no_checkpoint_start.inc |
| 17 |
CREATE TABLE t3(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 18 |
|
| 19 |
BEGIN; |
| 20 |
INSERT INTO t3 VALUES (33101),(347); |
| 21 |
INSERT INTO t1 VALUES (42),(9),(101); |
| 22 |
RENAME TABLE t1 TO t2; |
| 23 |
UPDATE t2 SET a=347 where a=42; |
| 24 |
COMMIT; |
| 25 |
|
| 26 |
--let CLEANUP_IF_CHECKPOINT=DROP TABLE t2,t3; |
| 27 |
--source include/no_checkpoint_end.inc |
| 28 |
|
| 29 |
--echo # Fault 0 (no real fault): Orphan file with duplicate space_id. |
| 30 |
--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t0.ibd |
| 31 |
|
| 32 |
--echo # Fault 1: Two dirty files with the same space_id. |
| 33 |
--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd |
| 34 |
|
| 35 |
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; |
| 36 |
let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES |
| 37 |
WHERE engine = 'innodb' |
| 38 |
AND support IN ('YES', 'DEFAULT', 'ENABLED'); |
| 39 |
|
| 40 |
# This could fail to refuse InnoDB startup, in case there was a log |
| 41 |
# checkpoint after the INSERT. That is what we checked above. |
| 42 |
--source include/start_mysqld.inc |
| 43 |
eval $check_no_innodb; |
| 44 |
let SEARCH_PATTERN= InnoDB: Ignoring data file '.*t2.ibd' with space ID \d+. Another data file called .*t1.ibd exists with the same space ID; |
| 45 |
--source include/search_pattern_in_file.inc |
| 46 |
--source include/shutdown_mysqld.inc |
| 47 |
|
| 48 |
--echo # Fault 4: Missing data file |
| 49 |
|
| 50 |
--move_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t.ibd |
| 51 |
--remove_file $MYSQLD_DATADIR/test/t1.ibd |
| 52 |
|
| 53 |
--source include/start_mysqld.inc |
| 54 |
eval $check_no_innodb; |
| 55 |
--source include/shutdown_mysqld.inc |
| 56 |
|
| 57 |
let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t[12].ibd. |
| 58 |
.*InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace; |
| 59 |
--source include/search_pattern_in_file.inc |
| 60 |
|
| 61 |
--echo # Fault 5: Wrong type of data file |
| 62 |
|
| 63 |
--mkdir $MYSQLD_DATADIR/test/t2.ibd |
| 64 |
|
| 65 |
--source include/start_mysqld.inc |
| 66 |
eval $check_no_innodb; |
| 67 |
--source include/shutdown_mysqld.inc |
| 68 |
|
| 69 |
--rmdir $MYSQLD_DATADIR/test/t2.ibd |
| 70 |
|
| 71 |
# Create a short file. |
| 72 |
--write_file $MYSQLD_DATADIR/test/t2.ibd |
| 73 |
EOF |
| 74 |
|
| 75 |
--source include/start_mysqld.inc |
| 76 |
eval $check_no_innodb; |
| 77 |
--source include/shutdown_mysqld.inc |
| 78 |
|
| 79 |
let SEARCH_PATTERN= \[Note\] InnoDB: Cannot read first page of .*t2.ibd; |
| 80 |
--source include/search_pattern_in_file.inc |
| 81 |
let SEARCH_PATTERN= .*\[ERROR\] InnoDB: Cannot apply log to \\[page id: space=[1-9][0-9]*, page number=3\\] of corrupted file './test/t2\\.ibd'; |
| 82 |
--source include/search_pattern_in_file.inc |
| 83 |
|
| 84 |
# Restore t2.ibd |
| 85 |
--remove_file $MYSQLD_DATADIR/test/t2.ibd |
| 86 |
--move_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t2.ibd |
| 87 |
|
| 88 |
--echo # Fault 2: Wrong space_id in a dirty file, and a missing file. |
| 89 |
--move_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_DATADIR/test/t1.ibd |
| 90 |
|
| 91 |
--source include/start_mysqld.inc |
| 92 |
|
| 93 |
SELECT * FROM t2; |
| 94 |
SELECT * FROM t3; |
| 95 |
SHOW TABLES; |
| 96 |
DROP TABLE t2,t3; |
| 97 |
|
| 98 |
--error ER_CANT_CREATE_TABLE |
| 99 |
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 100 |
--error ER_CANT_CREATE_TABLE |
| 101 |
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 102 |
--remove_file $MYSQLD_DATADIR/test/t0.ibd |
| 103 |
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 104 |
DROP TABLE t0; |
| 105 |
--error ER_CANT_CREATE_TABLE |
| 106 |
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 107 |
--error ER_CANT_CREATE_TABLE |
| 108 |
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 109 |
--remove_file $MYSQLD_DATADIR/test/t1.ibd |
| 110 |
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 111 |
DROP TABLE t1; |
| 112 |
|
| 113 |
--disable_query_log |
| 114 |
# The following are for the orphan file t0.ibd or for the directory t2.ibd: |
| 115 |
call mtr.add_suppression("InnoDB: Operating system error number [0-9]* in a file operation"); |
| 116 |
call mtr.add_suppression("InnoDB: Error number \\d+ means"); |
| 117 |
call mtr.add_suppression("InnoDB: Cannot create file '.*t0.ibd'"); |
| 118 |
call mtr.add_suppression("InnoDB: The file '.*t[01]\.ibd' already exists"); |
| 119 |
call mtr.add_suppression("InnoDB: Cannot open datafile for read-write: '.*t2\.ibd'"); |
| 120 |
call mtr.add_suppression("InnoDB: Could not measure the size of single-table tablespace file '.*test/t2\\.ibd'"); |
| 121 |
# The following are for aborted startup without --innodb-force-recovery: |
| 122 |
call mtr.add_suppression("InnoDB: Tablespace .* was not found at .*test"); |
| 123 |
call mtr.add_suppression("InnoDB: Cannot read first page of '.*test.[tu]2.ibd': I/O error"); |
| 124 |
call mtr.add_suppression("InnoDB: Cannot apply log to \\[page id: space=[1-9][0-9]*, page number=3\\] of corrupted file './test/t2\\.ibd'"); |
| 125 |
call mtr.add_suppression("InnoDB: Datafile '.*test.*ibd' is corrupted"); |
| 126 |
call mtr.add_suppression("InnoDB: Cannot replay file rename. Remove either file and try again"); |
| 127 |
call mtr.add_suppression("InnoDB: Cannot rename.*because the target file exists"); |
| 128 |
call mtr.add_suppression("InnoDB: Log scan aborted at LSN"); |
| 129 |
# The following are for the --innodb-force-recovery=1 with broken u* tables: |
| 130 |
call mtr.add_suppression("InnoDB: The size of the file .*u[12]\\.ibd is only [1-9][0-9]* bytes, should be at least 65536"); |
| 131 |
call mtr.add_suppression("InnoDB: The size of tablespace file '.*test/u[12].ibd' is only"); |
| 132 |
call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified"); |
| 133 |
call mtr.add_suppression("InnoDB: .*you must create directories"); |
| 134 |
call mtr.add_suppression("InnoDB: Cannot open datafile for read-only: '.*u[1-5]\.ibd'"); |
| 135 |
call mtr.add_suppression("InnoDB: Could not find a valid tablespace file for `test/u[1-5]`"); |
| 136 |
call mtr.add_suppression("InnoDB: Ignoring tablespace for test/u[1-3] because it could not be opened\\."); |
| 137 |
call mtr.add_suppression("InnoDB: Failed to find tablespace for table .* in the cache. Attempting to load the tablespace with space id"); |
| 138 |
call mtr.add_suppression("InnoDB: Plugin initialization aborted"); |
| 139 |
call mtr.add_suppression("Fewer engines are enabled now than were before the crash"); |
| 140 |
call mtr.add_suppression("Plugin 'InnoDB' \(init function returned error\|registration as a STORAGE ENGINE failed\)"); |
| 141 |
call mtr.add_suppression("InnoDB: Table test/u[123] in the InnoDB data dictionary has tablespace id [1-9][0-9]*, but tablespace with that id or name does not exist\\. Have you deleted or moved \\.ibd files\\?"); |
| 142 |
call mtr.add_suppression("InnoDB: Cannot replay rename of tablespace.*"); |
| 143 |
call mtr.add_suppression("InnoDB: Attempted to open a previously opened tablespace"); |
| 144 |
call mtr.add_suppression("InnoDB: Recovery cannot access file"); |
| 145 |
call mtr.add_suppression("InnoDB: Cannot read first page in datafile:"); |
| 146 |
FLUSH TABLES; |
| 147 |
--enable_query_log |
| 148 |
|
| 149 |
# Force a log checkpoint to "discard" any FILE_CREATE records. |
| 150 |
SET GLOBAL innodb_max_purge_lag_wait=0; |
| 151 |
SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; |
| 152 |
SET GLOBAL innodb_max_dirty_pages_pct=0.0; |
| 153 |
let $wait_condition = |
| 154 |
SELECT variable_value = 0 |
| 155 |
FROM information_schema.global_status |
| 156 |
WHERE variable_name = 'INNODB_BUFFER_POOL_PAGES_DIRTY'; |
| 157 |
--source include/wait_condition.inc |
| 158 |
SET GLOBAL innodb_max_dirty_pages_pct=90.0; |
| 159 |
|
| 160 |
--source include/no_checkpoint_start.inc |
| 161 |
|
| 162 |
CREATE TABLE u1(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 163 |
CREATE TABLE u2(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 164 |
CREATE TABLE u3(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 165 |
CREATE TABLE u4(a INT PRIMARY KEY) ENGINE=InnoDB; |
| 166 |
INSERT INTO u4 VALUES(1); |
| 167 |
RENAME TABLE u4 TO u5; |
| 168 |
RENAME TABLE u5 TO u6; |
| 169 |
INSERT INTO u6 VALUES(2); |
| 170 |
|
| 171 |
--let CLEANUP_IF_CHECKPOINT=DROP TABLE u1,u2,u3,u6; |
| 172 |
--source include/no_checkpoint_end.inc |
| 173 |
|
| 174 |
--echo # Fault 6: All-zero data file and innodb_force_recovery |
| 175 |
|
| 176 |
--remove_file $MYSQLD_DATADIR/test/u1.ibd |
| 177 |
--remove_file $MYSQLD_DATADIR/test/u2.ibd |
| 178 |
--remove_file $MYSQLD_DATADIR/test/u3.ibd |
| 179 |
|
| 180 |
# InnoDB: Header page consists of zero bytes |
| 181 |
--perl |
| 182 |
die unless open(FILE, ">$ENV{MYSQLD_DATADIR}/test/u1.ibd"); |
| 183 |
print FILE "\0" x 16384; |
| 184 |
close(FILE); |
| 185 |
EOF |
| 186 |
|
| 187 |
--write_line "" $MYSQLD_DATADIR/test/u2.ibd |
| 188 |
|
| 189 |
--copy_file $MYSQLD_DATADIR/test/u6.ibd $MYSQLD_DATADIR/test/u4.ibd |
| 190 |
|
| 191 |
--let $restart_parameters= --innodb-force-recovery=1 |
| 192 |
--source include/start_mysqld.inc |
| 193 |
DROP TABLE u1,u2,u3,u6; |
| 194 |
|
| 195 |
--remove_file $MYSQLD_DATADIR/test/u4.ibd |
| 196 |
|
| 197 |
--echo # List of files: |
| 198 |
--list_files $MYSQLD_DATADIR/test |
| 199 |
|
| 200 |
SHOW TABLES; |