Commit 8a608481 authored by Leonard Zhou's avatar Leonard Zhou

Bug#40013 mixed replication: row based format could lead to stale tmp tables on the

slave.

In mixed mode, if we create a temporary table and do some update which switch to ROW format,
the format will keep in ROW format until the session ends or the table is dropped explicitly. 
When the session ends, the temp table is dropped automaticly at cleanup time.
but it checks only current binlog format and so skip insertion of DROP TABLE instructions into binlog.
So the temp table can't be dropped correctly at slave.

Our solution is that when closing temp tables at cleanup time we check both binlog format and binlog mode,
and we could write DROP TABLE instructions into binlog if current binlog format is ROW but in MIX mode.
parent 2515ce79
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
==== Initialize ====
[on master]
CREATE TABLE t1 (a CHAR(48));
CREATE TEMPORARY TABLE t1_tmp1(a INT);
INSERT INTO t1 VALUES (UUID());
[on slave]
==== Verify results on slave ====
SHOW STATUS LIKE "Slave_open_temp_tables";
Variable_name Value
Slave_open_temp_tables 1
[on master]
[on slave]
==== Verify results on slave ====
SHOW STATUS LIKE "Slave_open_temp_tables";
Variable_name Value
Slave_open_temp_tables 0
==== Clean up ====
[on master]
DROP TABLE t1;
[on slave]
# ==== Purpose ====
#
# Test that temporary tables are correctly replicated after switching to ROW format in MIX mode.
# This test case will test the condition of the bug#40013.
# The test step is:
# 1: create temp table on connection 'master';
# 2: switch to ROW format using 'INSERT INTO t1 VALUES (UUID());'
# 3: disconnect 'master' and connect to a new connection 'master1';
# 4: sync to slave and check the number of temp tables on slave.
#
source include/master-slave.inc;
source include/have_binlog_format_mixed.inc;
--echo ==== Initialize ====
--echo [on master]
--connection master
CREATE TABLE t1 (a CHAR(48));
CREATE TEMPORARY TABLE t1_tmp1(a INT);
INSERT INTO t1 VALUES (UUID());
--echo [on slave]
sync_slave_with_master;
--echo ==== Verify results on slave ====
SHOW STATUS LIKE "Slave_open_temp_tables";
--echo [on master]
--connection master
disconnect master;
--connection master1
--echo [on slave]
sync_slave_with_master;
--echo ==== Verify results on slave ====
SHOW STATUS LIKE "Slave_open_temp_tables";
--echo ==== Clean up ====
--echo [on master]
--connection master1
DROP TABLE t1;
--echo [on slave]
sync_slave_with_master;
...@@ -1440,7 +1440,8 @@ void close_temporary_tables(THD *thd) ...@@ -1440,7 +1440,8 @@ void close_temporary_tables(THD *thd)
if (!thd->temporary_tables) if (!thd->temporary_tables)
return; return;
if (!mysql_bin_log.is_open() || thd->current_stmt_binlog_row_based) if (!mysql_bin_log.is_open() ||
(thd->current_stmt_binlog_row_based && thd->variables.binlog_format == BINLOG_FORMAT_ROW))
{ {
TABLE *tmp_next; TABLE *tmp_next;
for (table= thd->temporary_tables; table; table= tmp_next) for (table= thd->temporary_tables; table; table= tmp_next)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment