summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2022-06-09 10:57:28 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2022-06-09 10:57:28 +0300
commit98293130c34cfd39bf2e8c904923abe3942d23be (patch)
tree51951e48ff66afb9e991d62a7cde439e6d0dde69
parent2cd1edfc2176649cda412b2ff4f1075ad23448ba (diff)
downloadmariadb-git-98293130c34cfd39bf2e8c904923abe3942d23be.tar.gz
MDEV-28779: ALTER TABLE IMPORT TABLESPACE corrupts an encrypted table
PageConverter::update_header(): Remove an unnecessary write. The field that was originally called FIL_PAGE_FILE_FLUSH_LSN only made sense for the first page of the system tablespace (initially, for the first page of each file of the system tablespace). It never had any meaning for .ibd files, and it lost its original meaning in MariaDB Server 10.8.1 when commit b07920b634f455c39e3650c6163bec2a8ce0ffe0 (MDEV-27199) removed the ability to start without ib_logfile0. If the most significant 32 bits of the LSN are nonzero, this unnecessary write would write the wrong encryption key identifier to the page. The first page of any file is never encrypted, so normally those bytes should be 0 for any .ibd file.
-rw-r--r--mysql-test/suite/mariabackup/huge_lsn.result10
-rw-r--r--mysql-test/suite/mariabackup/huge_lsn.test18
-rw-r--r--storage/innobase/row/row0import.cc6
3 files changed, 27 insertions, 7 deletions
diff --git a/mysql-test/suite/mariabackup/huge_lsn.result b/mysql-test/suite/mariabackup/huge_lsn.result
index 61ca3400721..2225a958756 100644
--- a/mysql-test/suite/mariabackup/huge_lsn.result
+++ b/mysql-test/suite/mariabackup/huge_lsn.result
@@ -2,7 +2,7 @@
# MDEV-13416 mariabackup fails with EFAULT "Bad Address"
#
FOUND 1 /InnoDB: New log files created, LSN=175964\d{8}/ in mysqld.1.err
-CREATE TABLE t(i INT) ENGINE INNODB;
+CREATE TABLE t(i INT) ENGINE=INNODB ENCRYPTED=YES;
INSERT INTO t VALUES(1);
# xtrabackup backup
SET GLOBAL innodb_flush_log_at_trx_commit=1;
@@ -15,6 +15,14 @@ INSERT INTO t VALUES(2);
SELECT * FROM t;
i
1
+FLUSH TABLE t FOR EXPORT;
+UNLOCK TABLES;
+ALTER TABLE t DISCARD TABLESPACE;
+ALTER TABLE t IMPORT TABLESPACE;
+FLUSH TABLE t FOR EXPORT;
+UNLOCK TABLES;
+ALTER TABLE t DISCARD TABLESPACE;
+ALTER TABLE t IMPORT TABLESPACE;
DROP TABLE t;
# shutdown server
# remove datadir
diff --git a/mysql-test/suite/mariabackup/huge_lsn.test b/mysql-test/suite/mariabackup/huge_lsn.test
index 3349ef40df8..55978071be3 100644
--- a/mysql-test/suite/mariabackup/huge_lsn.test
+++ b/mysql-test/suite/mariabackup/huge_lsn.test
@@ -40,7 +40,7 @@ let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
--let SEARCH_PATTERN= InnoDB: New log files created, LSN=175964\d{8}
--source include/search_pattern_in_file.inc
-CREATE TABLE t(i INT) ENGINE INNODB;
+CREATE TABLE t(i INT) ENGINE=INNODB ENCRYPTED=YES;
INSERT INTO t VALUES(1);
echo # xtrabackup backup;
@@ -56,6 +56,22 @@ exec $XTRABACKUP --prepare --target-dir=$targetdir;
--source include/restart_and_restore.inc
--enable_result_log
SELECT * FROM t;
+FLUSH TABLE t FOR EXPORT;
+copy_file $_datadir/test/t.ibd $_datadir/test/t_copy.ibd;
+copy_file $_datadir/test/t.cfg $_datadir/test/t_copy.cfg;
+UNLOCK TABLES;
+ALTER TABLE t DISCARD TABLESPACE;
+move_file $_datadir/test/t_copy.ibd $_datadir/test/t.ibd;
+move_file $_datadir/test/t_copy.cfg $_datadir/test/t.cfg;
+ALTER TABLE t IMPORT TABLESPACE;
+FLUSH TABLE t FOR EXPORT;
+copy_file $_datadir/test/t.ibd $_datadir/test/t_copy.ibd;
+copy_file $_datadir/test/t.cfg $_datadir/test/t_copy.cfg;
+UNLOCK TABLES;
+ALTER TABLE t DISCARD TABLESPACE;
+move_file $_datadir/test/t_copy.ibd $_datadir/test/t.ibd;
+move_file $_datadir/test/t_copy.cfg $_datadir/test/t.cfg;
+ALTER TABLE t IMPORT TABLESPACE;
DROP TABLE t;
rmdir $targetdir;
let $targetdir= $targetdir_old;
diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc
index 885a43bb2f8..db4c22b4969 100644
--- a/storage/innobase/row/row0import.cc
+++ b/storage/innobase/row/row0import.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2012, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2021, MariaDB Corporation.
+Copyright (c) 2015, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -1996,10 +1996,6 @@ PageConverter::update_header(
ib::warn() << "Space id check in the header failed: ignored";
}
- mach_write_to_8(
- get_frame(block) + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION,
- m_current_lsn);
-
/* Write back the adjusted flags. */
mach_write_to_4(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS
+ get_frame(block), m_space_flags);