From e1f21590469239cdccf2759e035f60565fca6414 Mon Sep 17 00:00:00 2001 From: Thejaka Kanewala Date: Wed, 6 Jul 2022 11:38:06 -0700 Subject: PRB1587589: Fixing PRB1587589. Mariabackup --prepare only deals with the redo log and the data files. Currently, this is handled only for SRV_OPERATION_RESTORE only. Therefore, we see errors in prepare log when --prepare is executed with --export. Extended the logic to handle for SRV_OPERATION_RESTORE_EXPORT also. PRB1587589: Fixing a test case failure --- .../suite/mariabackup/innodb_xa_rollback.test | 2 +- .../suite/mariabackup/sparse_file_open_err.result | 28 ++++++++++ .../suite/mariabackup/sparse_file_open_err.test | 61 ++++++++++++++++++++++ storage/innobase/trx/trx0rseg.cc | 3 +- storage/innobase/trx/trx0trx.cc | 3 +- 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/mariabackup/sparse_file_open_err.result create mode 100644 mysql-test/suite/mariabackup/sparse_file_open_err.test diff --git a/mysql-test/suite/mariabackup/innodb_xa_rollback.test b/mysql-test/suite/mariabackup/innodb_xa_rollback.test index f8ba5ea8cfa..34e948a0ecc 100644 --- a/mysql-test/suite/mariabackup/innodb_xa_rollback.test +++ b/mysql-test/suite/mariabackup/innodb_xa_rollback.test @@ -55,7 +55,7 @@ XA ROLLBACK 'test1'; --echo # xtrabackup prepare for export and rollback prepared XA --disable_result_log -exec $XTRABACKUP --prepare --rollback_xa --export --target-dir=$targetdir3; +exec $XTRABACKUP --prepare --rollback_xa --target-dir=$targetdir3; --let $targetdir = $targetdir3 --source include/restart_and_restore.inc --enable_result_log diff --git a/mysql-test/suite/mariabackup/sparse_file_open_err.result b/mysql-test/suite/mariabackup/sparse_file_open_err.result new file mode 100644 index 00000000000..3447b06ee10 --- /dev/null +++ b/mysql-test/suite/mariabackup/sparse_file_open_err.result @@ -0,0 +1,28 @@ +CREATE TABLE t1 (a INT) ENGINE=INNODB; +INSERT t1 VALUES (10); +CREATE TABLE t2 (a INT) ENGINE=INNODB; +INSERT t2 VALUES (12); +start transaction; +INSERT INTO t1 VALUES(1); +INSERT INTO t2 VALUES(1); +"# Do the sparse backup before transaction completes ..." +commit; +"# Prepare the backup with --export ..." +"# Select all should include 10 and 1" +SELECT * FROM t1; +a +10 +1 +"# Remove t1 from the running DB and prepare to import t1 from the backup ..." +DROP TABLE t1; +CREATE TABLE t1 (a INT) ENGINE=INNODB; +ALTER TABLE test.t1 DISCARD TABLESPACE; +"# Import the table ...." +ALTER TABLE t1 IMPORT TABLESPACE; +"# Select all should include only 10" +SELECT * FROM t1; +a +10 +"# Cleanup ..." +DROP TABLE t1; +DROP TABLE t2; diff --git a/mysql-test/suite/mariabackup/sparse_file_open_err.test b/mysql-test/suite/mariabackup/sparse_file_open_err.test new file mode 100644 index 00000000000..b5d370c6dc3 --- /dev/null +++ b/mysql-test/suite/mariabackup/sparse_file_open_err.test @@ -0,0 +1,61 @@ +# +# Testing the error messages written to log; e.g., [ERROR] InnoDB: Cannot open datafile for read-only: './test/t2.ibd' OS error: 71 +# +--source include/have_innodb.inc +--source include/have_binlog_format_mixed.inc + +let targetdir=$MYSQLTEST_VARDIR/tmp/backup1; + +CREATE TABLE t1 (a INT) ENGINE=INNODB; +INSERT t1 VALUES (10); + +CREATE TABLE t2 (a INT) ENGINE=INNODB; +INSERT t2 VALUES (12); + +# Do the sparse backup while the transaction is going on. Only include subset of tables in the sparse +# backup from the tables that participate in the transaction. In this case only t1, t2 is not +# included in the sparse backup. + +start transaction; + +INSERT INTO t1 VALUES(1); +INSERT INTO t2 VALUES(1); + +echo "# Do the sparse backup before transaction completes ..."; +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --tables=t1; + +# Finish the transaction +commit; + +# do the prepare +echo "# Prepare the backup with --export ..."; +exec $XTRABACKUP --prepare --export --target-dir=$targetdir ; + +echo "# Select all should include 10 and 1"; +SELECT * FROM t1; + +echo "# Remove t1 from the running DB and prepare to import t1 from the backup ..."; +DROP TABLE t1; + +CREATE TABLE t1 (a INT) ENGINE=INNODB; +ALTER TABLE test.t1 DISCARD TABLESPACE; + +echo "# Import the table ...."; +# import the table from the backup. +--move_file $targetdir/test/t1.cfg $MYSQLTEST_VARDIR/mysqld.1/data/test/t1.cfg +--move_file $targetdir/test/t1.frm $MYSQLTEST_VARDIR/mysqld.1/data/test/t1.frm +--move_file $targetdir/test/t1.ibd $MYSQLTEST_VARDIR/mysqld.1/data/test/t1.ibd + +--chmod 0660 $MYSQLTEST_VARDIR/mysqld.1/data/test/t1.cfg +--chmod 0660 $MYSQLTEST_VARDIR/mysqld.1/data/test/t1.frm +--chmod 0660 $MYSQLTEST_VARDIR/mysqld.1/data/test/t1.ibd + +ALTER TABLE t1 IMPORT TABLESPACE; +echo "# Select all should include only 10"; +SELECT * FROM t1; + +echo "# Cleanup ..."; +DROP TABLE t1; +DROP TABLE t2; +rmdir $targetdir; + diff --git a/storage/innobase/trx/trx0rseg.cc b/storage/innobase/trx/trx0rseg.cc index ed1499e1392..b0ecdfc2549 100644 --- a/storage/innobase/trx/trx0rseg.cc +++ b/storage/innobase/trx/trx0rseg.cc @@ -483,7 +483,8 @@ trx_rseg_mem_restore(trx_rseg_t* rseg, trx_id_t& max_trx_id, mtr_t* mtr) } } - if (srv_operation == SRV_OPERATION_RESTORE) { + if ((srv_operation == SRV_OPERATION_RESTORE) || + (srv_operation == SRV_OPERATION_RESTORE_EXPORT)) { /* mariabackup --prepare only deals with the redo log and the data files, not with transactions or the data dictionary. */ diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index cce2f7d85f6..11a22e0ee45 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -744,7 +744,8 @@ trx_lists_init_at_db_start() ut_a(srv_is_being_started); ut_ad(!srv_was_started); - if (srv_operation == SRV_OPERATION_RESTORE) { + if ((srv_operation == SRV_OPERATION_RESTORE) || + (srv_operation == SRV_OPERATION_RESTORE_EXPORT)) { /* mariabackup --prepare only deals with the redo log and the data files, not with transactions or the data dictionary. */ -- cgit v1.2.1