From 3534500b87482dc7b43f72bcfc1faa08acfdff06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 3 Feb 2017 08:55:36 +0200 Subject: [PATCH] Test recovery when a .ibd file is a directory. Datafile::validate_for_recovery(): Remove a redundant error message. An error is already reported by Datafile::open_read_write() if the file cannot be opened. Also, do not assign SEARCH_ABORT, so that the full test will be executed even if one step fails. --- .../suite/innodb/r/log_file_name.result | 24 +++++++++++ mysql-test/suite/innodb/t/log_file_name.test | 40 +++++++++++-------- storage/innobase/fsp/fsp0file.cc | 5 +-- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/mysql-test/suite/innodb/r/log_file_name.result b/mysql-test/suite/innodb/r/log_file_name.result index 84107403cf2..e5904165781 100644 --- a/mysql-test/suite/innodb/r/log_file_name.result +++ b/mysql-test/suite/innodb/r/log_file_name.result @@ -14,26 +14,41 @@ SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +FOUND /InnoDB: Ignoring data file '.*t2.ibd' with space ID \d+. Another data file called .*t1.ibd exists with the same space ID/ in mysqld.1.err # Fault 2: Wrong space_id in a dirty file, and a missing file. SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +FOUND /InnoDB: Ignoring data file '.*t1.ibd' with space ID/ in mysqld.1.err +FOUND /InnoDB: Tablespace \d+ was not found at.*t3.ibd/ in mysqld.1.err # Fault 3: Wrong space_id in a dirty file, and no missing file. SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +FOUND /InnoDB: Ignoring data file '.*t[23].ibd' with space ID/ in mysqld.1.err +FOUND /InnoDB: Tablespace \d+ was not found at .*t1.ibd/ in mysqld.1.err +FOUND /InnoDB: Tablespace \d+ was not found at .*t3.ibd/ in mysqld.1.err +FOUND /InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace/ in mysqld.1.err # Fault 4: Missing data file SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +FOUND /InnoDB: Tablespace \d+ was not found at .*t[12].ibd. +.*InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace/ in mysqld.1.err # Fault 5: Wrong type of data file SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +SELECT * FROM INFORMATION_SCHEMA.ENGINES +WHERE engine = 'innodb' +AND support IN ('YES', 'DEFAULT', 'ENABLED'); +ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +FOUND /\[ERROR\] InnoDB: Cannot read first page of .*t2.ibd/ in mysqld.1.err +FOUND /\[ERROR\] InnoDB: Datafile .*t2.*\. Cannot determine the space ID from the first 64 pages/ in mysqld.1.err SELECT * FROM t2; a 9 @@ -66,11 +81,20 @@ SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +FOUND /\[ERROR\] InnoDB: Header page consists of zero bytes in datafile: .*u1.ibd/ in mysqld.1.err +FOUND /\[ERROR\] InnoDB: Datafile .*u1.*\. Cannot determine the space ID from the first 64 pages/ in mysqld.1.err +FOUND /\[ERROR\] InnoDB: Cannot read first page of .*u2.ibd/ in mysqld.1.err # Fault 7: Missing or wrong data file and innodb_force_recovery SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS +FOUND /\[ERROR\] InnoDB: Header page consists of zero bytes in datafile: .*u1.ibd/ in mysqld.1.err +FOUND /InnoDB: At LSN: \d+: unable to open file .*u[1-5].ibd for tablespace/ in mysqld.1.err +FOUND /\[ERROR\] InnoDB: Cannot rename '.*u5.ibd' to '.*u6.ibd' for space ID \d+ because the target file exists/ in mysqld.1.err +FOUND /\[ERROR\] InnoDB: Header page consists of zero bytes in datafile: .*u1.ibd/ in mysqld.1.err +FOUND /InnoDB: At LSN: \d+: unable to open file .*u[1-5].ibd for tablespace/ in mysqld.1.err +FOUND /\[Warning\] InnoDB: Tablespace \d+ was not found at .*u[1-5].ibd, and innodb_force_recovery was set. All redo log for this tablespace will be ignored!/ in mysqld.1.err DROP TABLE u1,u2,u3,u6; # List of files: SHOW TABLES; diff --git a/mysql-test/suite/innodb/t/log_file_name.test b/mysql-test/suite/innodb/t/log_file_name.test index 5c063ab124f..78500a6a310 100644 --- a/mysql-test/suite/innodb/t/log_file_name.test +++ b/mysql-test/suite/innodb/t/log_file_name.test @@ -31,7 +31,6 @@ COMMIT; let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; let SEARCH_RANGE= -50000; -let SEARCH_ABORT= NOT FOUND; let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); @@ -94,32 +93,38 @@ let SEARCH_PATTERN= InnoDB: Set innodb_force_recovery=1 to ignore this and to pe --source include/start_mysqld.inc eval $check_no_innodb; +--source include/shutdown_mysqld.inc let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t[12].ibd. .*InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace; --source include/search_pattern_in_file.inc ---source include/shutdown_mysqld.inc - --echo # Fault 5: Wrong type of data file -# TODO: Test the following as well once -# Bug#18131883 IMPROVE INNODB ERROR MESSAGES REGARDING FILES -# has been fixed: -# A file containing 16384 zero bytes. -# --mkdir $MYSQLD_DATADIR/test/t2.ibd - -# Create a short file. ---exec echo "" > $MYSQLD_DATADIR/test/t2.ibd +--mkdir $MYSQLD_DATADIR/test/t2.ibd --source include/start_mysqld.inc eval $check_no_innodb; +--source include/shutdown_mysqld.inc +# On Windows, this error message is not output when t2.ibd is a directory! +#let SEARCH_PATTERN= \[ERROR\] InnoDB: Cannot read first page of .*t2.ibd; +#--source include/search_pattern_in_file.inc +--rmdir $MYSQLD_DATADIR/test/t2.ibd + +# Create a short file. +--write_file $MYSQLD_DATADIR/test/t2.ibd +EOF + +--source include/start_mysqld.inc +eval $check_no_innodb; +--source include/shutdown_mysqld.inc + +let SEARCH_PATTERN= \[ERROR\] InnoDB: Cannot read first page of .*t2.ibd; +--source include/search_pattern_in_file.inc let SEARCH_PATTERN= \[ERROR\] InnoDB: Datafile .*t2.*\. Cannot determine the space ID from the first 64 pages; --source include/search_pattern_in_file.inc ---source include/shutdown_mysqld.inc - # Restore t2.ibd --remove_file $MYSQLD_DATADIR/test/t2.ibd --move_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t2.ibd @@ -141,11 +146,12 @@ CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB; DROP TABLE t0; --disable_query_log -# The following are for the orphan file t0.ibd: +# The following are for the orphan file t0.ibd or for the directory t2.ibd: call mtr.add_suppression("InnoDB: Operating system error number [0-9]* in a file operation"); -call mtr.add_suppression("InnoDB: Error number [0-9]* means 'File exists'"); +call mtr.add_suppression("InnoDB: Error number [0-9]* means '(File exists|Is a directory)'"); call mtr.add_suppression("InnoDB: Cannot create file '.*t0.ibd'"); call mtr.add_suppression("InnoDB: The file '.*t0\.ibd' already exists"); +call mtr.add_suppression("InnoDB: Cannot open datafile for read-write: '.*t2\.ibd'"); # The following are for aborted startup without --innodb-force-recovery: call mtr.add_suppression("InnoDB: Tablespace .* was not found at .*test"); call mtr.add_suppression("InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace"); @@ -189,7 +195,7 @@ INSERT INTO u6 VALUES(2); --remove_file $MYSQLD_DATADIR/test/u3.ibd # InnoDB: Header page consists of zero bytes -perl; +--perl die unless open(FILE, ">$ENV{MYSQLD_DATADIR}/test/u1.ibd"); print FILE "\0" x 16384; close(FILE); @@ -218,7 +224,7 @@ let SEARCH_PATTERN= \[ERROR\] InnoDB: Datafile .*u1.*\. Cannot determine the spa # in innodb-force-recovery mode once # Bug#18131883 IMPROVE INNODB ERROR MESSAGES REGARDING FILES # has been fixed: -let SEARCH_PATTERN= \[ERROR\] InnoDB: Cannot read first page of .*u2.ibd.*; +let SEARCH_PATTERN= \[ERROR\] InnoDB: Cannot read first page of .*u2.ibd; --source include/search_pattern_in_file.inc --source include/shutdown_mysqld.inc diff --git a/storage/innobase/fsp/fsp0file.cc b/storage/innobase/fsp/fsp0file.cc index 22cd4862162..74c153a65d5 100644 --- a/storage/innobase/fsp/fsp0file.cc +++ b/storage/innobase/fsp/fsp0file.cc @@ -467,11 +467,8 @@ Datafile::validate_for_recovery() close(); err = open_read_write(srv_read_only_mode); if (err != DB_SUCCESS) { - ib::error() << "Datafile '" << m_filepath << "' could not" - " be opened in read-write mode so that the" - " doublewrite pages could be restored."; return(err); - }; + } err = find_space_id(); if (err != DB_SUCCESS || m_space_id == 0) {