MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Li-Bing.Song Date:November 22 2009 5:10am
Subject:bzr commit into mysql-5.1-bugteam branch (Li-Bing.Song:3214) Bug#48350
View as plain text  
#At file:///home/anders/work/bzrwork/worktree2/mysql-5.1-bugteam/ based on revid:alfranio.correia@stripped

 3214 Li-Bing.Song@stripped	2009-11-22
      Bug #48350  	truncate temporary table crashes replication
      
      In RBR, All statements operating on temporary tables should not be binlogged.
      Despite this fact, after executing 'TRUNCATE... ' on a temporary table, 
      the command is still logged, even if in row-based mode. Consequently, this raises
      problems in the slave as the table may not exist, resulting in an
      execution failure. Ultimately, this causes the slave to report
      an error and abort.
      
      After this patch, 'TRUNCATE ...' statement on a temporary table will not be
      binlogged in RBR.

    added:
      mysql-test/suite/rpl/r/rpl_row_trunc_temp.result
      mysql-test/suite/rpl/t/rpl_row_trunc_temp.test
    modified:
      sql/sql_delete.cc
=== added file 'mysql-test/suite/rpl/r/rpl_row_trunc_temp.result'
--- a/mysql-test/suite/rpl/r/rpl_row_trunc_temp.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_trunc_temp.result	2009-11-22 05:10:33 +0000
@@ -0,0 +1,29 @@
+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;
+CREATE TEMPORARY TABLE t1(c1 INTEGER);
+CREATE TABLE t2(c1 INTEGER);
+CREATE TABLE t1(c1 INTEGER);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1), (2);
+SELECT * FROM t1;
+c1
+1
+2
+SELECT * FROM t2;
+c1
+1
+2
+TRUNCATE t1;
+TRUNCATE t2;
+SELECT * FROM t1;
+c1
+1
+2
+SELECT * FROM t2;
+c1
+DROP TABLE t1;
+DROP TABLE t2;

=== added file 'mysql-test/suite/rpl/t/rpl_row_trunc_temp.test'
--- a/mysql-test/suite/rpl/t/rpl_row_trunc_temp.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_trunc_temp.test	2009-11-22 05:10:33 +0000
@@ -0,0 +1,35 @@
+#
+# Bug#48350 truncate temporary table crashes replication 
+#
+# All statements operating on temporary tables should not be binlogged in RBR.
+# However, before fix of bug#48350, 'TRUNCATE ...' statement on a temporary
+# table was binlogged in RBR.
+#
+
+--source include/master-slave.inc
+--source include/have_binlog_format_row.inc
+
+#This statement is not binlogged in RBR.
+CREATE TEMPORARY TABLE t1(c1 INTEGER);
+CREATE TABLE t2(c1 INTEGER);
+sync_slave_with_master;
+
+CREATE TABLE t1(c1 INTEGER);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1), (2);
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+connection master;
+TRUNCATE t1;
+TRUNCATE t2;
+sync_slave_with_master;
+# t1 will have nothing, if 'TRUNCATE t1' has been replicate from master to
+# slave.
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+DROP TABLE t1;
+connection master;
+DROP TABLE t2;
+--source include/master-slave-end.inc

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2009-11-18 09:32:03 +0000
+++ b/sql/sql_delete.cc	2009-11-22 05:10:33 +0000
@@ -1090,6 +1090,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST
   TABLE *table;
   bool error;
   uint path_length;
+  bool is_temporary_table= false;
   DBUG_ENTER("mysql_truncate");
 
   bzero((char*) &create_info,sizeof(create_info));
@@ -1100,6 +1101,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST
   /* If it is a temporary table, close and regenerate it */
   if (!dont_send_ok && (table= find_temporary_table(thd, table_list)))
   {
+    is_temporary_table= true;
     handlerton *table_type= table->s->db_type();
     TABLE_SHARE *share= table->s;
     if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
@@ -1163,11 +1165,9 @@ end:
   {
     if (!error)
     {
-      /*
-        TRUNCATE must always be statement-based binlogged (not row-based) so
-        we don't test current_stmt_binlog_row_based.
-      */
-      write_bin_log(thd, TRUE, thd->query(), thd->query_length());
+      /* In RBR, the statement is not binlogged if the table is temporary. */
+      if (!is_temporary_table || !thd->current_stmt_binlog_row_based)
+        write_bin_log(thd, TRUE, thd->query(), thd->query_length());
       my_ok(thd);		// This should return record count
     }
     VOID(pthread_mutex_lock(&LOCK_open));


Attachment: [text/bzr-bundle] bzr/li-bing.song@sun.com-20091122051033-whfkkgrwim0j3p8r.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (Li-Bing.Song:3214) Bug#48350Li-Bing.Song22 Nov