[Commits] 08a8ad7bd79: Fixed wrong error message when row_compressed table is still encrypted.

jan jan.lindstrom at mariadb.com
Fri Mar 24 17:17:17 EET 2017


revision-id: 08a8ad7bd7974bfb90f948758878f70be76e7dc5 (mariadb-10.2.4-80-g08a8ad7bd79)
parent(s): cfbec36db3f0f3ed0103f6dc8bde0356448d1d89
author: Jan Lindström
committer: Jan Lindström
timestamp: 2017-03-24 17:16:57 +0200
message:

Fixed wrong error message when row_compressed table is still encrypted.

In case checksum field on encrypted table is corrupted (as well
as actual key_version) we should mark page as encrypted if we
know it is encrypted.

---
 .../encryption/r/innodb-bad-key-change.result      | 38 +++++++++--------
 .../suite/encryption/r/innodb-force-corrupt.result |  6 ++-
 .../suite/encryption/r/innodb-redo-badkey.result   |  2 +-
 .../suite/encryption/t/innodb-bad-key-change.test  | 19 ++++-----
 .../suite/encryption/t/innodb-force-corrupt.test   | 12 +++---
 .../suite/encryption/t/innodb-redo-badkey.test     |  2 +-
 mysql-test/suite/innodb/disabled.def               |  1 -
 .../suite/innodb/r/innodb_bug14147491.result       |  1 +
 mysql-test/suite/innodb/t/innodb_bug14147491.test  |  2 +-
 storage/innobase/btr/btr0cur.cc                    | 10 +++++
 storage/innobase/buf/buf0buf.cc                    | 14 ++++++-
 storage/innobase/fil/fil0crypt.cc                  | 48 ++++++++++------------
 storage/innobase/row/row0mysql.cc                  |  1 +
 storage/innobase/row/row0sel.cc                    |  2 +-
 14 files changed, 90 insertions(+), 68 deletions(-)

diff --git a/mysql-test/suite/encryption/r/innodb-bad-key-change.result b/mysql-test/suite/encryption/r/innodb-bad-key-change.result
index 6c44c462f0d..c5e6340b833 100644
--- a/mysql-test/suite/encryption/r/innodb-bad-key-change.result
+++ b/mysql-test/suite/encryption/r/innodb-bad-key-change.result
@@ -2,6 +2,7 @@ call mtr.add_suppression("Plugin 'file_key_management' init function returned er
 call mtr.add_suppression("Plugin 'file_key_management' registration.*failed");
 call mtr.add_suppression("InnoDB: The page .* in file test/.* cannot be decrypted");
 call mtr.add_suppression("mysqld: File .* not found");
+call mtr.add_suppression("InnoDB: Cannot calculate statistics for table .* because the .ibd file is missing. Please refer to .*");
 
 # Start server with keys2.txt
 CREATE TABLE t1 (c VARCHAR(8)) ENGINE=InnoDB ENCRYPTED=YES ENCRYPTION_KEY_ID=2;
@@ -28,13 +29,14 @@ SELECT * FROM t1;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SHOW WARNINGS;
 Level	Code	Message
-Warning	192	Table test/t1 in tablespace  is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
-Warning	192	Table test/t1 is encrypted but encryption service or used key_id 2 is not available.  Can't continue reading table.
+Warning	192	Table test/t1 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
+Warning	192	Table test/t1 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 DROP TABLE t1;
 SHOW WARNINGS;
 Level	Code	Message
-# Start server with keys.txt
+# Start server with keys3.txt
+SET GLOBAL innodb_default_encryption_key_id=5;
 CREATE TABLE t2 (c VARCHAR(8), id int not null primary key, b int, key(b)) ENGINE=InnoDB ENCRYPTED=YES;
 INSERT INTO t2 VALUES ('foobar',1,2);
 
@@ -43,14 +45,13 @@ SELECT * FROM t2;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SHOW WARNINGS;
 Level	Code	Message
-Warning	192	Table test/t2 in tablespace  is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
+Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
 Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SELECT * FROM t2 where id = 1;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SHOW WARNINGS;
 Level	Code	Message
-Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SELECT * FROM t2 where b = 1;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
@@ -59,10 +60,10 @@ Level	Code	Message
 Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 INSERT INTO t2 VALUES ('tmp',3,3);
-ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+ERROR HY000: Table test/t2 in tablespace  encrypted.However key management plugin or used key_id is not found or used encryption algorithm or method does not match.
 SHOW WARNINGS;
 Level	Code	Message
-Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
+Error	192	Table test/t2 in tablespace  encrypted.However key management plugin or used key_id is not found or used encryption algorithm or method does not match.
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 DELETE FROM t2 where b = 3;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
@@ -70,26 +71,31 @@ SHOW WARNINGS;
 Level	Code	Message
 Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 DELETE FROM t2 where id = 3;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SHOW WARNINGS;
 Level	Code	Message
-Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
+Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 UPDATE t2 set b = b +1;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SHOW WARNINGS;
 Level	Code	Message
-Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 OPTIMIZE TABLE t2;
 Table	Op	Msg_type	Msg_text
-test.t2	optimize	Warning	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
-test.t2	optimize	Error	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
-test.t2	optimize	error	Corrupt
+test.t2	optimize	note	Table does not support optimize, doing recreate + analyze instead
+test.t2	optimize	error	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+test.t2	optimize	status	Operation failed
+Warnings:
+Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
+Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SHOW WARNINGS;
 Level	Code	Message
-ALTER TABLE t2 ADD COLUMN c INT;
+Warning	192	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
+Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+ALTER TABLE t2 ADD COLUMN d INT;
 ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SHOW WARNINGS;
 Level	Code	Message
@@ -97,9 +103,7 @@ Warning	192	Table test/t2 is encrypted but encryption service or used key_id is
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 ANALYZE TABLE t2;
 Table	Op	Msg_type	Msg_text
-test.t2	analyze	Warning	Table test/t2 is encrypted but encryption service or used key_id is not available.  Can't continue reading table.
-test.t2	analyze	Error	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
-test.t2	analyze	error	Corrupt
+test.t2	analyze	status	Operation failed
 SHOW WARNINGS;
 Level	Code	Message
 TRUNCATE TABLE t2;
@@ -114,7 +118,7 @@ SHOW WARNINGS;
 Level	Code	Message
 Error	1296	Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 
-# Restart server with keys.txt
+# Restart server with keys3.txt
 DROP TABLE t2;
 SHOW WARNINGS;
 Level	Code	Message
diff --git a/mysql-test/suite/encryption/r/innodb-force-corrupt.result b/mysql-test/suite/encryption/r/innodb-force-corrupt.result
index 394a65d494f..5929ef1bc3d 100644
--- a/mysql-test/suite/encryption/r/innodb-force-corrupt.result
+++ b/mysql-test/suite/encryption/r/innodb-force-corrupt.result
@@ -29,6 +29,10 @@ COMMIT;
 # Backup tables before corrupting
 # Corrupt tables
 SELECT * FROM t1;
+ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+SELECT * FROM t2;
+ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
 SELECT * FROM t3;
-# Restore the original t1.ibd
+ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+# Restore the original tables
 DROP TABLE t1,t2,t3;
diff --git a/mysql-test/suite/encryption/r/innodb-redo-badkey.result b/mysql-test/suite/encryption/r/innodb-redo-badkey.result
index fde285c38d5..b9996e65064 100644
--- a/mysql-test/suite/encryption/r/innodb-redo-badkey.result
+++ b/mysql-test/suite/encryption/r/innodb-redo-badkey.result
@@ -14,7 +14,7 @@ call mtr.add_suppression("InnoDB: You may have to recover from a backup.");
 call mtr.add_suppression("InnoDB: Recovery read page .* from tablespace .*");
 call mtr.add_suppression("InnoDB: The page .* cannot be decrypted.");
 call mtr.add_suppression("InnoDB: Missing MLOG_FILE_NAME or MLOG_FILE_DELETE .*");
-call mtr.add_suppression("InnoDB: Plugin initialization aborted at srv0start.cc.*");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted .*");
 call mtr.add_suppression("InnoDB: ############### CORRUPT LOG RECORD FOUND ##################");
 # Restart mysqld --file-key-management-filename=keys2.txt
 # Wait max 10 min for key encryption threads to encrypt all spaces
diff --git a/mysql-test/suite/encryption/t/innodb-bad-key-change.test b/mysql-test/suite/encryption/t/innodb-bad-key-change.test
index e8b5de99d80..9cd9d8ff1b4 100644
--- a/mysql-test/suite/encryption/t/innodb-bad-key-change.test
+++ b/mysql-test/suite/encryption/t/innodb-bad-key-change.test
@@ -2,10 +2,6 @@
 -- source include/have_file_key_management_plugin.inc
 # embedded does not support restart
 -- source include/not_embedded.inc
--- source include/not_valgrind.inc
-# Avoid CrashReporter popup on Mac
--- source include/not_crashrep.inc
--- source include/not_windows.inc
 
 #
 # MDEV-8588: Assertion failure in file ha_innodb.cc line 21140 if at least one encrypted
@@ -16,6 +12,7 @@ call mtr.add_suppression("Plugin 'file_key_management' init function returned er
 call mtr.add_suppression("Plugin 'file_key_management' registration.*failed");
 call mtr.add_suppression("InnoDB: The page .* in file test/.* cannot be decrypted");
 call mtr.add_suppression("mysqld: File .* not found");
+call mtr.add_suppression("InnoDB: Cannot calculate statistics for table .* because the .ibd file is missing. Please refer to .*");
 
 --echo
 --echo # Start server with keys2.txt
@@ -56,10 +53,11 @@ SHOW WARNINGS;
 # line 2856 on querying a table using wrong default encryption key
 #
 
---echo # Start server with keys.txt
--- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys.txt
+--echo # Start server with keys3.txt
+-- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys3.txt
 -- source include/restart_mysqld.inc
 
+SET GLOBAL innodb_default_encryption_key_id=5;
 CREATE TABLE t2 (c VARCHAR(8), id int not null primary key, b int, key(b)) ENGINE=InnoDB ENCRYPTED=YES;
 INSERT INTO t2 VALUES ('foobar',1,2);
 
@@ -80,7 +78,8 @@ SHOW WARNINGS;
 SELECT * FROM t2 where b = 1;
 --replace_regex /tablespace [0-9]*/tablespace /
 SHOW WARNINGS;
---error ER_GET_ERRMSG
+--replace_regex /tablespace [0-9]*/tablespace /
+--error 192
 INSERT INTO t2 VALUES ('tmp',3,3);
 --replace_regex /tablespace [0-9]*/tablespace /
 SHOW WARNINGS;
@@ -100,7 +99,7 @@ OPTIMIZE TABLE t2;
 --replace_regex /tablespace [0-9]*/tablespace /
 SHOW WARNINGS;
 --error ER_GET_ERRMSG
-ALTER TABLE t2 ADD COLUMN c INT;
+ALTER TABLE t2 ADD COLUMN d INT;
 --replace_regex /tablespace [0-9]*/tablespace /
 SHOW WARNINGS;
 ANALYZE TABLE t2;
@@ -117,8 +116,8 @@ DROP TABLE t2;
 SHOW WARNINGS;
 
 --echo
---echo # Restart server with keys.txt
--- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys.txt
+--echo # Restart server with keys3.txt
+-- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys3.txt
 -- source include/restart_mysqld.inc
 
 --replace_regex /.*tablespace [0-9]*//
diff --git a/mysql-test/suite/encryption/t/innodb-force-corrupt.test b/mysql-test/suite/encryption/t/innodb-force-corrupt.test
index 65fbb613a5a..582e7ab668a 100644
--- a/mysql-test/suite/encryption/t/innodb-force-corrupt.test
+++ b/mysql-test/suite/encryption/t/innodb-force-corrupt.test
@@ -50,7 +50,6 @@ INSERT INTO t2 select * from t1;
 INSERT INTO t3 select * from t1;
 COMMIT;
 
-let $MYSQLD_DATADIR=`select @@datadir`;
 let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
 let MYSQLD_DATADIR=`select @@datadir`;
 
@@ -83,17 +82,16 @@ EOF
 
 --source include/start_mysqld.inc
 
---disable_result_log
---error ER_GET_ERRMSG, 1030
+--error ER_GET_ERRMSG
 SELECT * FROM t1;
---error ER_GET_ERRMSG, 1030
+--error ER_GET_ERRMSG
+SELECT * FROM t2;
+--error ER_GET_ERRMSG
 SELECT * FROM t3;
---enable_result_log
 
 --source include/shutdown_mysqld.inc
 
---echo # Restore the original t1.ibd
---remove_file $MYSQLD_DATADIR/test/t1.ibd
+--echo # Restore the original tables
 --move_file $MYSQLD_DATADIR/test/t1.ibd.backup $MYSQLD_DATADIR/test/t1.ibd
 --move_file $MYSQLD_DATADIR/test/t2.ibd.backup $MYSQLD_DATADIR/test/t2.ibd
 --move_file $MYSQLD_DATADIR/test/t3.ibd.backup $MYSQLD_DATADIR/test/t3.ibd
diff --git a/mysql-test/suite/encryption/t/innodb-redo-badkey.test b/mysql-test/suite/encryption/t/innodb-redo-badkey.test
index 79771f83d71..cd79a033375 100644
--- a/mysql-test/suite/encryption/t/innodb-redo-badkey.test
+++ b/mysql-test/suite/encryption/t/innodb-redo-badkey.test
@@ -19,7 +19,7 @@ call mtr.add_suppression("InnoDB: You may have to recover from a backup.");
 call mtr.add_suppression("InnoDB: Recovery read page .* from tablespace .*");
 call mtr.add_suppression("InnoDB: The page .* cannot be decrypted.");
 call mtr.add_suppression("InnoDB: Missing MLOG_FILE_NAME or MLOG_FILE_DELETE .*");
-call mtr.add_suppression("InnoDB: Plugin initialization aborted at srv0start.cc.*");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted .*");
 call mtr.add_suppression("InnoDB: ############### CORRUPT LOG RECORD FOUND ##################");
 
 --echo # Restart mysqld --file-key-management-filename=keys2.txt
diff --git a/mysql-test/suite/innodb/disabled.def b/mysql-test/suite/innodb/disabled.def
index 631f01a8e65..e92e2051994 100644
--- a/mysql-test/suite/innodb/disabled.def
+++ b/mysql-test/suite/innodb/disabled.def
@@ -11,4 +11,3 @@
 ##############################################################################
 
 innodb_defragment_fill_factor : MDEV-10771
-innodb_bug14147491            : MDEV-12253 ut_ad(buf_pool->n_pend_reads > 0)
diff --git a/mysql-test/suite/innodb/r/innodb_bug14147491.result b/mysql-test/suite/innodb/r/innodb_bug14147491.result
index bde86e8d9dc..7227c8760ba 100644
--- a/mysql-test/suite/innodb/r/innodb_bug14147491.result
+++ b/mysql-test/suite/innodb/r/innodb_bug14147491.result
@@ -1,3 +1,4 @@
+call mtr.add_suppression("InnoDB: Unable to read tablespace .* page no .* into the buffer pool after .* attempts");
 CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ROW_FORMAT=COMPACT ENGINE=InnoDB;
 call mtr.add_suppression("InnoDB: Unable to read tablespace .* page no .* into the buffer pool after .* attempts");
 INSERT INTO t1 (b) VALUES ('corrupt me');
diff --git a/mysql-test/suite/innodb/t/innodb_bug14147491.test b/mysql-test/suite/innodb/t/innodb_bug14147491.test
index 307ebd207e8..817249f40f4 100644
--- a/mysql-test/suite/innodb/t/innodb_bug14147491.test
+++ b/mysql-test/suite/innodb/t/innodb_bug14147491.test
@@ -20,7 +20,7 @@ source include/not_windows.inc;
 
 --disable_query_log
 CALL mtr.add_suppression("\\[ERROR\\] \\[FATAL\\] InnoDB: Unable to read page \\[page id: space=.*, page number=.*\\] into the buffer pool after 100 attempts");
-CALL mtr.add_suppression("\\[ERROR\\] InnoDB: Database page corruption on disk or a failed");
+CALL mtr.add_suppression("\\[ERROR\\] InnoDB: Database page corruption on disk or a failed .*");
 --enable_query_log
 
 CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ROW_FORMAT=COMPACT ENGINE=InnoDB;
diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc
index 001bcae5360..cbf73da9117 100644
--- a/storage/innobase/btr/btr0cur.cc
+++ b/storage/innobase/btr/btr0cur.cc
@@ -5479,6 +5479,11 @@ btr_estimate_n_rows_in_range_low(
 					    &cursor, 0,
 					    __FILE__, __LINE__, &mtr);
 
+		if (index->table->file_unreadable) {
+			mtr_commit(&mtr);
+			return (0);
+		}
+
 		ut_ad(!page_rec_is_infimum(btr_cur_get_rec(&cursor)));
 
 		/* We should count the border if there are any records to
@@ -5505,6 +5510,11 @@ btr_estimate_n_rows_in_range_low(
 				   << " index: " << index->name;
 		}
 
+		if (index->table->file_unreadable) {
+			mtr_commit(&mtr);
+			return (0);
+		}
+
 		ut_ad(page_rec_is_infimum(btr_cur_get_rec(&cursor)));
 
 		/* The range specified is wihout a left border, just
diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc
index 701bd5f50c4..3bc5566f506 100644
--- a/storage/innobase/buf/buf0buf.cc
+++ b/storage/innobase/buf/buf0buf.cc
@@ -4364,15 +4364,17 @@ buf_page_get_gen(
 		} else if (retries < BUF_PAGE_READ_MAX_RETRIES) {
 			++retries;
 
+			ib::info() << "Retry: " << retries << "/" << BUF_PAGE_READ_MAX_RETRIES;
 			DBUG_EXECUTE_IF(
 				"innodb_page_corruption_retries",
-				retries = BUF_PAGE_READ_MAX_RETRIES;
+				/* This is needed as we might just mark
+				space corrupted. */
+				goto fatal_exit;
 			);
 		} else {
 			if (err) {
 				*err = local_err;
 			}
-
 			/* Encrypted pages that are not corrupted are marked
 			as encrypted and that fact is later pushed to
 			user thread. */
@@ -4387,6 +4389,7 @@ buf_page_get_gen(
 				return (NULL);
 			}
 
+fatal_exit:
 			ib::fatal() << "Unable to read page " << page_id
 					    << " into the buffer pool after "
 					    << BUF_PAGE_READ_MAX_RETRIES << " attempts."
@@ -7530,6 +7533,13 @@ buf_page_decrypt_after_read(buf_page_t* bpage)
 			if (!fil_space_verify_crypt_checksum(
 				    dst_frame, size,
 				    bpage->id.space(), bpage->id.page_no())) {
+
+				/* Mark page encrypted in case it should
+				be. */
+				if (key_version && space()->crypt_data &&
+				    space()->crypt_data->type != CRYPT_SCHEME_UNENCRYPTED) {
+					bpage->encrypted=true;
+				}
 				return (false);
 			}
 
diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc
index b447a768093..960075149b7 100644
--- a/storage/innobase/fil/fil0crypt.cc
+++ b/storage/innobase/fil/fil0crypt.cc
@@ -2536,36 +2536,30 @@ fil_space_verify_crypt_checksum(
 		return (true);
 	}
 
-	/* Compressed pages use different checksum method. We first store
-	the post encryption checksum on checksum location and after function
-	restore the original. */
-	if (page_size.is_compressed()) {
-		ib_uint32_t old = static_cast<ib_uint32_t>(mach_read_from_4(
-				page + FIL_PAGE_SPACE_OR_CHKSUM));
-
-		mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM, checksum);
+	ib_uint32_t cchecksum1=0;
+	ib_uint32_t cchecksum2=0;
 
-		bool valid = page_zip_verify_checksum(page,
-						      page_size.physical()
-#ifdef UNIV_INNOCHECKSUM
-						      , offset,
-						      strict_check,
-						      log_file != NULL,
-						      log_file
-#endif
-						      );
+	if (page_size.is_compressed()) {
+		cchecksum1 = page_zip_calc_checksum(
+			page, page_size.physical(), SRV_CHECKSUM_ALGORITHM_CRC32);
 
-		mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM, old);
+		if(cchecksum1 != checksum) {
+			cchecksum2 = page_zip_calc_checksum(
+				page, page_size.physical(),
+				SRV_CHECKSUM_ALGORITHM_INNODB);
+		}
+	} else {
+		cchecksum1 = buf_calc_page_crc32(page);
 
-		return (valid);
+		if (cchecksum1 != checksum) {
+			cchecksum2 = (ib_uint32_t) buf_calc_page_new_checksum(
+				page);
+		}
 	}
 
 	/* If stored checksum matches one of the calculated checksums
 	page is not corrupted. */
 
-	ib_uint32_t cchecksum1 = buf_calc_page_crc32(page);
-	ib_uint32_t cchecksum2 = (ib_uint32_t) buf_calc_page_new_checksum(
-				page);
 	bool encrypted = (checksum == cchecksum1 || checksum == cchecksum2
 		|| checksum == BUF_NO_CHECKSUM_MAGIC);
 
@@ -2620,16 +2614,18 @@ fil_space_verify_crypt_checksum(
 #ifdef UNIV_INNOCHECKSUM
 		fprintf(log_file ? log_file : stderr,
 			"Page " ULINTPF ":" ULINTPF " may be corrupted."
-			" Post encryption checksum %u"
+			" Post encryption stored checksum %u"
+			" calculated [%u:%u] "
 			" stored [" ULINTPF ":" ULINTPF "] key_version %u\n",
-			space, offset, checksum, checksum1, checksum2,
+			space, offset, cchecksum1, cchecksum2, checksum, checksum1, checksum2,
 			key_version);
 #else /* UNIV_INNOCHECKSUM */
 		ib::error()
 			<< " Page " << space << ":" << offset
 			<< " may be corrupted."
-			" Post encryption checksum " << checksum
-			<< " stored [" << checksum1 << ":" << checksum2
+			" Post encryption stored checksum " << checksum
+			<< " calculated [" << cchecksum1 << ":" << cchecksum2
+			<< "] stored [" << checksum1 << ":" << checksum2
 			<< "] key_version " << key_version;
 #endif
 		encrypted = false;
diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc
index f6beeea63d6..478ebb89e1c 100644
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -819,6 +819,7 @@ row_mysql_handle_errors(
 		break;
 
 	case DB_CORRUPTION:
+	case DB_PAGE_CORRUPTED:
 		ib::error() << "We detected index corruption in an InnoDB type"
 			" table. You have to dump + drop + reimport the"
 			" table or, in a case of widespread corruption,"
diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc
index 0ec1a3108bb..9983767535b 100644
--- a/storage/innobase/row/row0sel.cc
+++ b/storage/innobase/row/row0sel.cc
@@ -4696,7 +4696,7 @@ row_search_mvcc(
 
 	rec = btr_pcur_get_rec(pcur);
 
-	if (!rec) {
+	if (!rec || index->table->file_unreadable) {
 		err = DB_DECRYPTION_FAILED;
 		goto lock_wait_or_error;
 	}


More information about the commits mailing list