List:Commits« Previous MessageNext Message »
From:Mats Kindahl Date:November 12 2010 1:13pm
Subject:bzr commit into mysql-5.1-bugteam branch (mats.kindahl:3501) Bug#36541
View as plain text  
#At file:///home/bzr/bugs/b36541-5.1-bugteam/ based on revid:davi.arnaut@stripped

 3501 Mats Kindahl	2010-11-12
      Bug #36541: Master/Slave binlogs out of sync
      
      The master and slave binary logs go out of
      sync because the BEGIN event generated on the
      master when writing a transaction to the 
      binary log contain a database and a catalog,
      while the event on the slave does not (because
      the slave thread resets these).
      
      This patch fixes the issue by:
      - Not writing the database in the event when
        LOG_EVENT_SUPPRESS_USE_F is set, which is
        set for the generated BEGIN.
      - Setting the catalog to "std" for the
        generated BEGIN since the THD constructor
        sets the catalog to "std".
      
      The patch also makes "catalog" be a pointer
      to "const char*" be const-correct.

    added:
      mysql-test/suite/bugs/r/rpl_bug36541.result
      mysql-test/suite/bugs/t/rpl_bug36541.test
    modified:
      sql/log.cc
      sql/log_event.cc
      sql/sql_class.cc
      sql/sql_class.h
=== added file 'mysql-test/suite/bugs/r/rpl_bug36541.result'
--- a/mysql-test/suite/bugs/r/rpl_bug36541.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/bugs/r/rpl_bug36541.result	2010-11-12 13:12:53 +0000
@@ -0,0 +1,22 @@
+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;
+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 TABLE t1 (a INT) ENGINE=InnoDB;
+SET AUTOCOMMIT = 0;
+USE test;
+INSERT INTO t1 VALUES (5);
+COMMIT;
+Master_Diff
+179
+Slave_Diff
+179
+DROP TABLE t1;

=== added file 'mysql-test/suite/bugs/t/rpl_bug36541.test'
--- a/mysql-test/suite/bugs/t/rpl_bug36541.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/bugs/t/rpl_bug36541.test	2010-11-12 13:12:53 +0000
@@ -0,0 +1,40 @@
+#############################################################
+# Author: Mats Kindahl <mats.kindahl@stripped>
+# Date:   2010-11-09
+# Purpose: 
+#   Test that BEGIN does not use a database.
+#############################################################
+
+--source include/master-slave.inc
+--source include/have_innodb.inc
+--source include/have_binlog_format_statement.inc
+
+source include/master-slave-reset.inc;
+
+connection master;
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+SET AUTOCOMMIT = 0;
+USE test;
+sync_slave_with_master;
+let $before_slave = query_get_value(SHOW MASTER STATUS, Position, 1);
+
+connection master;
+let $before_master = query_get_value(SHOW MASTER STATUS, Position, 1);
+INSERT INTO t1 VALUES (5);
+COMMIT;
+let $after_master = query_get_value(SHOW MASTER STATUS, Position, 1);
+
+sync_slave_with_master;
+let $after_slave = query_get_value(SHOW MASTER STATUS, Position, 1);
+
+connection master;
+let $master_diff = `SELECT $after_master - $before_master`;
+let $slave_diff = `SELECT $after_slave - $before_slave`;
+disable_query_log;
+eval SELECT $master_diff AS Master_Diff;
+eval SELECT $slave_diff AS Slave_Diff;
+enable_query_log;
+
+DROP TABLE t1;
+sync_slave_with_master;
+

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2010-10-20 18:21:40 +0000
+++ b/sql/log.cc	2010-11-12 13:12:53 +0000
@@ -4812,7 +4812,15 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_C
         Log "BEGIN" at the beginning of every transaction.  Here, a
         transaction is either a BEGIN..COMMIT block or a single
         statement in autocommit mode.
+
+        We explicitly set the catalog to "std" since the THD
+        constructor set catalog to "std" as well and a BEGIN statement
+        cannot change the catalog. If we didn't do this, the catalog
+        of the BEGIN on the master would be "std" while it would not
+        have a catalog on the slave, causing the events to have
+        different length.
       */
+      thd->catalog= "std";
       Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, TRUE, 0);
 
       /*

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2010-10-23 12:55:44 +0000
+++ b/sql/log_event.cc	2010-11-12 13:12:53 +0000
@@ -2432,7 +2432,8 @@ Query_log_event::Query_log_event(THD* th
              (suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0),
 	     using_trans),
    data_buf(0), query(query_arg), catalog(thd_arg->catalog),
-   db(thd_arg->db), q_len((uint32) query_length),
+   db(suppress_use ? NULL : thd_arg->db),
+   q_len((uint32) query_length),
    thread_id(thd_arg->thread_id),
    /* save the original thread id; we already know the server id */
    slave_proxy_id(thd_arg->variables.pseudo_thread_id),
@@ -3093,7 +3094,7 @@ int Query_log_event::do_apply_event(Rela
     Query_log_event::do_apply_event()). Same for thd->db.  Thank
     you.
   */
-  thd->catalog= catalog_len ? (char *) catalog : (char *)"";
+  thd->catalog= catalog_len ? catalog : "";
   new_db.length= db_len;
   new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length);
   thd->set_db(new_db.str, new_db.length);       /* allocates a copy of 'db' */

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2010-10-23 12:55:44 +0000
+++ b/sql/sql_class.cc	2010-11-12 13:12:53 +0000
@@ -637,7 +637,7 @@ THD::THD()
   init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
   stmt_arena= this;
   thread_stack= 0;
-  catalog= (char*)"std"; // the only catalog we have for now
+  catalog= "std"; // the only catalog we have for now
   main_security_ctx.init();
   security_ctx= &main_security_ctx;
   locked=some_tables_deleted=no_errors=password= 0;

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2010-10-23 12:55:44 +0000
+++ b/sql/sql_class.h	2010-11-12 13:12:53 +0000
@@ -1354,7 +1354,7 @@ public:
   /**
     Currently selected catalog.
   */
-  char *catalog;
+  const char *catalog;
 
   /**
     @note


Attachment: [text/bzr-bundle] bzr/mats.kindahl@oracle.com-20101112131253-5msbn0diwfi76dqa.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (mats.kindahl:3501) Bug#36541Mats Kindahl12 Nov