diff options
author | Nisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com> | 2019-04-17 15:36:29 +0530 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2019-07-24 18:32:24 +0200 |
commit | 2536c0b1ebf6c5012ae34435d82fb2f5fa54aea5 (patch) | |
tree | eecff27ba9f10f9bcf1e36c9797a0f75f670c698 | |
parent | 7473a71a282c47a1e95359c575089c8ef51caf56 (diff) | |
download | mariadb-git-2536c0b1ebf6c5012ae34435d82fb2f5fa54aea5.tar.gz |
BUG#28642318: POINT IN TIME RECOVERY USING MYSQLBINLOG BROKEN WITH TEMPORARY TABLE -> ERRORS
Analysis
========
Point in time recovery using mysqlbinlog containing queries
operating on temporary tables results in an error.
While writing the query log event in the binary log, the
thread id used for execution of DROP TABLE and DELETE commands
were incorrect. The thread variable 'thread_specific_used'
is used to determine whether a specific thread id is to used
while executing the statements i.e using 'SET
@@session.pseudo_thread_id'. This variable was not set
correctly for DROP TABLE query and was never set for DELETE
query. The thread id is important for temporary tables
since the tables are session specific. DROP TABLE and DELETE
queries executed using a wrong thread id resulted in errors
while applying the queries generated by mysqlbinlog utility.
Fix
===
Set the 'thread_specific_used' THD variable for DROP TABLE and
DELETE queries.
ReviewBoard: 21833
-rw-r--r-- | mysql-test/extra/binlog_tests/drop_temp_table.test | 69 | ||||
-rw-r--r-- | mysql-test/suite/binlog/r/binlog_row_drop_tmp_tbl.result | 27 | ||||
-rw-r--r-- | mysql-test/suite/binlog/r/binlog_stm_drop_tmp_tbl.result | 27 | ||||
-rw-r--r-- | sql/sql_delete.cc | 5 | ||||
-rw-r--r-- | sql/sql_table.cc | 7 |
5 files changed, 129 insertions, 6 deletions
diff --git a/mysql-test/extra/binlog_tests/drop_temp_table.test b/mysql-test/extra/binlog_tests/drop_temp_table.test index c852ee4c8a0..b53b41292d8 100644 --- a/mysql-test/extra/binlog_tests/drop_temp_table.test +++ b/mysql-test/extra/binlog_tests/drop_temp_table.test @@ -100,3 +100,72 @@ RESET MASTER; DROP TABLE t1; # End of 4.1 tests + + +--echo # +--echo # BUG#28642318: POINT IN TIME RECOVERY USING MYSQLBINLOG BROKEN +--echo # WITH TEMPORARY TABLE -> ERRORS + +--echo # Test case for DELETE query. + +RESET MASTER; +connect (con1,localhost,root,,); + +--echo # Set up. +--connection default +--disable_warnings +SET @save_binlog_format= @@session.binlog_format; +SET @@session.binlog_format=STATEMENT; +let $MYSQLD_DATADIR= `select @@datadir`; +CREATE TABLE t1 (a INT) ENGINE=INNODB; + +--connection con1 +SET @@session.binlog_format=STATEMENT; +CREATE TEMPORARY TABLE t1 (b BLOB) ENGINE=INNODB; + +--connection default +DELETE d1, d2 FROM t1 AS d1, t1 AS d2 WHERE d1.a<>d2.a; + +--exec $MYSQL_BINLOG --force-if-open $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/bug28642318.sql + +--connection default +DROP TABLE t1; + +--echo # DELETE query fails with table re-open error without patch. +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug28642318.sql + +--echo # Clean up. +--connection con1 +DROP TABLE IF EXISTS t1; + +--connection default +DROP TABLE IF EXISTS t1; +RESET MASTER; + +--echo # Test case for DROP query. + +--connection default +CREATE TABLE t1 (a INT) ENGINE=INNODB; + +--connection con1 +CREATE TEMPORARY TABLE t1 (b BLOB) ENGINE=INNODB; + +--connection default +DROP TABLE t1; + +--connection con1 +DROP TABLE t1; + +--connection default +--exec $MYSQL_BINLOG --force-if-open $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/bug28642318.sql + +--echo # DROP table query fails with unknown table error without patch. +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug28642318.sql + +--echo # Clean up +--connection default +SET @@session.binlog_format= @save_binlog_format; +RESET MASTER; + +--disconnect con1 +--enable_warnings diff --git a/mysql-test/suite/binlog/r/binlog_row_drop_tmp_tbl.result b/mysql-test/suite/binlog/r/binlog_row_drop_tmp_tbl.result index ca5181f0106..1641072c930 100644 --- a/mysql-test/suite/binlog/r/binlog_row_drop_tmp_tbl.result +++ b/mysql-test/suite/binlog/r/binlog_row_drop_tmp_tbl.result @@ -55,3 +55,30 @@ master-bin.000001 # Query # # COMMIT master-bin.000001 # Query # # use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `ttmp1` RESET MASTER; DROP TABLE t1; +# +# BUG#28642318: POINT IN TIME RECOVERY USING MYSQLBINLOG BROKEN +# WITH TEMPORARY TABLE -> ERRORS +# Test case for DELETE query. +RESET MASTER; +# Set up. +SET @save_binlog_format= @@session.binlog_format; +SET @@session.binlog_format=STATEMENT; +CREATE TABLE t1 (a INT) ENGINE=INNODB; +SET @@session.binlog_format=STATEMENT; +CREATE TEMPORARY TABLE t1 (b BLOB) ENGINE=INNODB; +DELETE d1, d2 FROM t1 AS d1, t1 AS d2 WHERE d1.a<>d2.a; +DROP TABLE t1; +# DELETE query fails with table re-open error without patch. +# Clean up. +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1; +RESET MASTER; +# Test case for DROP query. +CREATE TABLE t1 (a INT) ENGINE=INNODB; +CREATE TEMPORARY TABLE t1 (b BLOB) ENGINE=INNODB; +DROP TABLE t1; +DROP TABLE t1; +# DROP table query fails with unknown table error without patch. +# Clean up +SET @@session.binlog_format= @save_binlog_format; +RESET MASTER; diff --git a/mysql-test/suite/binlog/r/binlog_stm_drop_tmp_tbl.result b/mysql-test/suite/binlog/r/binlog_stm_drop_tmp_tbl.result index 027bf1eaada..35d5d1e51a1 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_drop_tmp_tbl.result +++ b/mysql-test/suite/binlog/r/binlog_stm_drop_tmp_tbl.result @@ -63,3 +63,30 @@ master-bin.000001 # Query # # COMMIT master-bin.000001 # Query # # use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `ttmp1` RESET MASTER; DROP TABLE t1; +# +# BUG#28642318: POINT IN TIME RECOVERY USING MYSQLBINLOG BROKEN +# WITH TEMPORARY TABLE -> ERRORS +# Test case for DELETE query. +RESET MASTER; +# Set up. +SET @save_binlog_format= @@session.binlog_format; +SET @@session.binlog_format=STATEMENT; +CREATE TABLE t1 (a INT) ENGINE=INNODB; +SET @@session.binlog_format=STATEMENT; +CREATE TEMPORARY TABLE t1 (b BLOB) ENGINE=INNODB; +DELETE d1, d2 FROM t1 AS d1, t1 AS d2 WHERE d1.a<>d2.a; +DROP TABLE t1; +# DELETE query fails with table re-open error without patch. +# Clean up. +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1; +RESET MASTER; +# Test case for DROP query. +CREATE TABLE t1 (a INT) ENGINE=INNODB; +CREATE TEMPORARY TABLE t1 (b BLOB) ENGINE=INNODB; +DROP TABLE t1; +DROP TABLE t1; +# DROP table query fails with unknown table error without patch. +# Clean up +SET @@session.binlog_format= @save_binlog_format; +RESET MASTER; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 27dd4260ea2..df1489fbd93 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1,5 +1,5 @@ -/* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. + Copyright (c) 2009, 2019, 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 @@ -1054,6 +1054,7 @@ bool multi_delete::send_eof() thd->clear_error(); else errcode= query_error_code(thd, killed_status == NOT_KILLED); + thd->thread_specific_used= TRUE; if (thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query(), thd->query_length(), transactional_tables, FALSE, FALSE, errcode) && diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 99f2ce580c0..9e80350f3ab 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. - Copyright (c) 2010, 2018, MariaDB + Copyright (c) 2000, 2019, Oracle and/or its affiliates. + Copyright (c) 2010, 2019, MariaDB 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 @@ -2358,8 +2358,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, table->table_name);); } DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog"); - thd->thread_specific_used|= (trans_tmp_table_deleted || - non_trans_tmp_table_deleted); + thd->thread_specific_used= TRUE; error= 0; err: if (wrong_tables.length()) |