Skip to content

Commit

Permalink
MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF …
Browse files Browse the repository at this point in the history
…EXISTS

This was a regression from the patch for MDEV-7668.

A test was incorrect, so the slave would not properly handle re-using
temporary tables, which lead to replication failure in this case.
  • Loading branch information
knielsen committed Apr 20, 2015
1 parent 87d5438 commit 519ad0f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions mysql-test/suite/rpl/r/rpl_temp_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ sum(n)
show status like 'Slave_open_temp_tables';
Variable_name Value
Slave_open_temp_tables 0
*** MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ***
INSERT INTO t2 VALUES (2000), (2001);
CREATE FUNCTION f() RETURNS INTEGER RETURN 1;
CREATE TEMPORARY TABLE t3 AS SELECT f() AS col FROM t2;
drop table if exists t1,t2;
Warnings:
Note 1051 Unknown table 'test.t1'
drop function f;
include/rpl_end.inc
16 changes: 16 additions & 0 deletions mysql-test/suite/rpl/t/rpl_temp_table.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,28 @@ select count(*) from t2;
select sum(n) from t2;
show status like 'Slave_open_temp_tables';

--echo *** MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ***
connect (master2,localhost,root,,);
INSERT INTO t2 VALUES (2000), (2001);
CREATE FUNCTION f() RETURNS INTEGER RETURN 1;
CREATE TEMPORARY TABLE t3 AS SELECT f() AS col FROM t2;
--let $gtid=`SELECT @@gtid_binlog_pos`
--disconnect master2
--connection default
# Wait for implicit DROP TEMPORARY TABLE tmp to be binlogged.
--let $wait_condition= SELECT @@gtid_binlog_pos != '$gtid'
--source include/wait_condition.inc

--sync_slave_with_master


#
# Clean up
#
connect (master2,localhost,root,,);
connection master2;
drop table if exists t1,t2;
drop function f;
sync_slave_with_master;


Expand Down
7 changes: 5 additions & 2 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ bool close_cached_connection_tables(THD *thd, LEX_STRING *connection)

static void mark_temp_tables_as_free_for_reuse(THD *thd)
{
rpl_group_info *rgi_slave;
DBUG_ENTER("mark_temp_tables_as_free_for_reuse");

if (thd->query_id == 0)
Expand All @@ -661,7 +662,9 @@ static void mark_temp_tables_as_free_for_reuse(THD *thd)
DBUG_VOID_RETURN;
}

if (thd->temporary_tables)
rgi_slave=thd->rgi_slave;
if ((!rgi_slave && thd->temporary_tables) ||
(rgi_slave && unlikely(rgi_slave->rli->save_temporary_tables)))
{
thd->lock_temporary_tables();
for (TABLE *table= thd->temporary_tables ; table ; table= table->next)
Expand All @@ -670,7 +673,7 @@ static void mark_temp_tables_as_free_for_reuse(THD *thd)
mark_tmp_table_for_reuse(table);
}
thd->unlock_temporary_tables();
if (thd->rgi_slave)
if (rgi_slave)
{
/*
Temporary tables are shared with other by sql execution threads.
Expand Down

0 comments on commit 519ad0f

Please sign in to comment.