List:Commits« Previous MessageNext Message »
From:Li-Bing.Song Date:September 2 2009 10:43am
Subject:bzr commit into mysql-5.1 branch (Li-Bing.Song:3078) Bug#45999
View as plain text  
#At file:///home/anders/work/bzrwork/bug45999/mysql-5.1-bugteam/ based on revid:joro@stripped

 3078 Li-Bing.Song@stripped	2009-09-02
      BUG#45999 Row based replication fails when auto_increment field = 0
      
      In RBR, When we insert an entry into a table in which has a auto_increment field, 
      Master treats 0 as value of the auto_increment field if NO_AUTO_VALUE_ON_ZERO is seted into SQL_MODE.
      In contrast, slave generates new sequence numbers when it encounters the 0 values.
      So, it results in a inconsistency between master and slave.
      
      The table->auto_increment_is_not_null is FALSE, which causes this bug to appear.
      When store engine encounters the 0 values, it will generate new sequence numbers unless 
      table->auto_increment_is_not_null is TRUE and NO_AUTO_VALUE_ON_ZERO is seted into SQL_MODE.
      This patch assigns TRUE to table->auto_increment_is_not_null at the begin of the Write_rows_log_event's execution.

    modified:
      mysql-test/extra/rpl_tests/rpl_auto_increment.test
      mysql-test/suite/rpl/r/rpl_auto_increment.result
      sql/log_event.cc
=== modified file 'mysql-test/extra/rpl_tests/rpl_auto_increment.test'
--- a/mysql-test/extra/rpl_tests/rpl_auto_increment.test	2009-01-14 08:27:32 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_auto_increment.test	2009-09-02 10:43:27 +0000
@@ -163,5 +163,39 @@ show create table t1;
 connection master;
 drop table t1;
 
+#
+# BUG#45999 Row based replication fails when auto_increment field = 0.
+# Slave generates a new index for the auto_increment field which's value is 0.
+# In this case, the new index is 1. This will results in an error of
+# "duplicate key" when writing the second row.
+#
+connection master;
+disable_warnings;
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+enable_warnings;
+eval CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=$engine_type;
+eval CREATE TABLE t2 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=$engine_type2;
+SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES(0);
+INSERT INTO t1 VALUES(3);
+INSERT INTO t1 VALUES();
+INSERT INTO t2 VALUES(NULL);
+INSERT INTO t2 VALUES(0);
+INSERT INTO t2 VALUES(3);
+INSERT INTO t2 VALUES();
+sync_slave_with_master;
+echo ----on master----;
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+connection slave;
+echo ----on slave----;
+SELECT * FROM t1;
+SELECT * FROM t2;
+connection master;
+DROP TABLE t1;
+DROP TABLE t2;
 # End cleanup
 sync_slave_with_master;

=== modified file 'mysql-test/suite/rpl/r/rpl_auto_increment.result'
--- a/mysql-test/suite/rpl/r/rpl_auto_increment.result	2009-01-14 08:27:32 +0000
+++ b/mysql-test/suite/rpl/r/rpl_auto_increment.result	2009-09-02 10:43:27 +0000
@@ -244,3 +244,44 @@ t1	CREATE TABLE `t1` (
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
 drop table t1;
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=innodb;
+CREATE TABLE t2 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=myisam;
+SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES(0);
+INSERT INTO t1 VALUES(3);
+INSERT INTO t1 VALUES();
+INSERT INTO t2 VALUES(NULL);
+INSERT INTO t2 VALUES(0);
+INSERT INTO t2 VALUES(3);
+INSERT INTO t2 VALUES();
+----on master----
+SELECT * FROM t1;
+id
+0
+1
+3
+4
+SELECT * FROM t2;
+id
+0
+1
+3
+4
+----on slave----
+SELECT * FROM t1;
+id
+0
+1
+3
+4
+SELECT * FROM t2;
+id
+0
+1
+3
+4
+DROP TABLE t1;
+DROP TABLE t2;

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-08-12 05:31:56 +0000
+++ b/sql/log_event.cc	2009-09-02 10:43:27 +0000
@@ -8294,6 +8294,7 @@ Write_rows_log_event::do_before_row_oper
   
   /* Honor next number column if present */
   m_table->next_number_field= m_table->found_next_number_field;
+  m_table->auto_increment_field_not_null= TRUE;
   return error;
 }
 
@@ -8303,6 +8304,7 @@ Write_rows_log_event::do_after_row_opera
 {
   int local_error= 0;
   m_table->next_number_field=0;
+  m_table->auto_increment_field_not_null= FALSE;
   if (bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1 ||
       m_table->s->db_type()->db_type == DB_TYPE_NDBCLUSTER)
   {


Attachment: [text/bzr-bundle] bzr/li-bing.song@sun.com-20090902104327-ikly75vc5d0ohvyx.bundle
Thread
bzr commit into mysql-5.1 branch (Li-Bing.Song:3078) Bug#45999Li-Bing.Song2 Sep