From 5fdb14542ae44aa2f0bae512e8305f791c977ca1 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 9 May 2015 11:19:36 +0200 Subject: [PATCH] MDEV-8021 "InnoDB: Tablespace id 4 encrypted but encryption service not available. Can't continue opening tablespace" on server restart when there are encrypted tables key id was written in the wrong place on the tablespace first page (thus its value could not be read back later) --- .../innodb/r/encryption_first_page.result | 5 ++++ .../suite/innodb/t/encryption_first_page.opt | 2 ++ .../suite/innodb/t/encryption_first_page.test | 30 +++++++++++++++++++ storage/innobase/fil/fil0crypt.cc | 2 +- storage/xtradb/fil/fil0crypt.cc | 2 +- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 mysql-test/suite/innodb/r/encryption_first_page.result create mode 100644 mysql-test/suite/innodb/t/encryption_first_page.opt create mode 100644 mysql-test/suite/innodb/t/encryption_first_page.test diff --git a/mysql-test/suite/innodb/r/encryption_first_page.result b/mysql-test/suite/innodb/r/encryption_first_page.result new file mode 100644 index 00000000000..c2bbdb5695b --- /dev/null +++ b/mysql-test/suite/innodb/r/encryption_first_page.result @@ -0,0 +1,5 @@ +call mtr.add_suppression("InnoDB: New log files created, LSN"); +call mtr.add_suppression("InnoDB: Creating foreign key constraint system tables"); +shutdown; +create table t1 (a int); +drop table t1; diff --git a/mysql-test/suite/innodb/t/encryption_first_page.opt b/mysql-test/suite/innodb/t/encryption_first_page.opt new file mode 100644 index 00000000000..1a9099a649d --- /dev/null +++ b/mysql-test/suite/innodb/t/encryption_first_page.opt @@ -0,0 +1,2 @@ +--innodb-encrypt-tables +--innodb-encrypt-log diff --git a/mysql-test/suite/innodb/t/encryption_first_page.test b/mysql-test/suite/innodb/t/encryption_first_page.test new file mode 100644 index 00000000000..917a1e990a6 --- /dev/null +++ b/mysql-test/suite/innodb/t/encryption_first_page.test @@ -0,0 +1,30 @@ +# +# MDEV-8021 "InnoDB: Tablespace id 4 encrypted but encryption service not available. Can't continue opening tablespace" on server restart when there are encrypted tables +# + +--source include/have_innodb.inc +--source include/have_file_key_management_plugin.inc + +call mtr.add_suppression("InnoDB: New log files created, LSN"); +call mtr.add_suppression("InnoDB: Creating foreign key constraint system tables"); + +let datadir=`select @@datadir`; + +--exec echo wait > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + +shutdown; + +--remove_file $datadir/ib_logfile0 +--remove_file $datadir/ib_logfile1 +--remove_file $datadir/ibdata1 + +--exec echo restart > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + +--enable_reconnect +--source include/wait_until_connected_again.inc + +create table t1 (a int); + +--source include/restart_mysqld.inc + +drop table t1; diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index a038d196ceb..41d6b9abc35 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -444,7 +444,7 @@ fil_space_write_crypt_data_low( mtr); mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len, min_key_version, MLOG_4BYTES, mtr); - mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len, key_id, + mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len + 4, key_id, MLOG_4BYTES, mtr); mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len + 8, encryption, MLOG_1BYTE, mtr); diff --git a/storage/xtradb/fil/fil0crypt.cc b/storage/xtradb/fil/fil0crypt.cc index 96291cbda03..dbd17928f90 100644 --- a/storage/xtradb/fil/fil0crypt.cc +++ b/storage/xtradb/fil/fil0crypt.cc @@ -444,7 +444,7 @@ fil_space_write_crypt_data_low( mtr); mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len, min_key_version, MLOG_4BYTES, mtr); - mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len, key_id, + mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len + 4, key_id, MLOG_4BYTES, mtr); mlog_write_ulint(page + offset + MAGIC_SZ + 2 + len + 8, encryption, MLOG_1BYTE, mtr);