#At file:///home/andrei/MySQL/BZR/FIXES/6.0-bt-bug40221/
2781 Andrei Elkin 2008-12-08 [merge]
merge 5.1-bt -> 6.0-bt Bug #33420.
added:
mysql-test/suite/binlog/r/binlog_innodb_row.result
mysql-test/suite/binlog/t/binlog_innodb_row.test
modified:
sql/log.cc
=== added file 'mysql-test/suite/binlog/r/binlog_innodb_row.result'
--- a/mysql-test/suite/binlog/r/binlog_innodb_row.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_innodb_row.result 2008-12-08 15:07:08 +0000
@@ -0,0 +1,31 @@
+CREATE TABLE t1 (i int unique) ENGINE=innodb;
+reset master;
+begin;
+insert into t1 values (1),(2);
+*** the following UPDATE query wont generate any updates for the binlog ***
+update t1 set i = 3 where i < 3;
+ERROR 23000: Duplicate entry '3' for key 'i'
+commit;
+*** Results of the test: the binlog must have only Write_rows events not any Update_rows ***
+show binlog events from <binlog_start>;
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 # Query # # use `test`; BEGIN
+master-bin.000001 # Table_map # # table_id: # (test.t1)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Xid # # COMMIT /* XID */
+delete from t1;
+reset master;
+begin;
+insert into t1 values (1),(2);
+*** the following UPDATE query wont generate any updates for the binlog ***
+insert into t1 values (3),(4),(1),(2);
+ERROR 23000: Duplicate entry '1' for key 'i'
+commit;
+*** Results of the test: the binlog must have only one Write_rows event not two ***
+show binlog events from <binlog_start>;
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 # Query # # use `test`; BEGIN
+master-bin.000001 # Table_map # # table_id: # (test.t1)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Xid # # COMMIT /* XID */
+drop table t1;
=== added file 'mysql-test/suite/binlog/t/binlog_innodb_row.test'
--- a/mysql-test/suite/binlog/t/binlog_innodb_row.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_innodb_row.test 2008-12-08 15:07:08 +0000
@@ -0,0 +1,42 @@
+#
+# Tests of innodb/binlog with the row binlog format
+#
+source include/have_innodb.inc;
+source include/have_log_bin.inc;
+source include/have_binlog_format_row.inc;
+
+#
+# Bug #40221 Replication failure on RBR + UPDATE the primary key
+#
+
+CREATE TABLE t1 (i int unique) ENGINE=innodb;
+reset master;
+
+# part 1: update can cause the dup key
+
+begin;
+insert into t1 values (1),(2);
+--echo *** the following UPDATE query wont generate any updates for the binlog ***
+--error ER_DUP_ENTRY
+update t1 set i = 3 where i < 3;
+commit;
+
+--echo *** Results of the test: the binlog must have only Write_rows events not any Update_rows ***
+source include/show_binlog_events.inc;
+
+# part 2: insert can cause the dup key
+
+delete from t1;
+reset master;
+
+begin;
+insert into t1 values (1),(2);
+--echo *** the following UPDATE query wont generate any updates for the binlog ***
+--error ER_DUP_ENTRY
+insert into t1 values (3),(4),(1),(2);
+commit;
+
+--echo *** Results of the test: the binlog must have only one Write_rows event not two ***
+source include/show_binlog_events.inc;
+
+drop table t1;
=== modified file 'sql/log.cc'
--- a/sql/log.cc 2008-12-08 13:31:24 +0000
+++ b/sql/log.cc 2008-12-08 19:31:12 +0000
@@ -230,6 +230,7 @@ public:
truncate(0);
before_stmt_pos= MY_OFF_T_UNDEF;
trans_log.end_of_file= max_binlog_cache_size;
+ DBUG_ASSERT(empty());
}
Rows_log_event *pending() const
@@ -2596,8 +2597,6 @@ binlog_end_trans(THD *thd, binlog_trx_da
FLAGSTR(thd->options, OPTION_NOT_AUTOCOMMIT),
FLAGSTR(thd->options, OPTION_BEGIN)));
- thd->binlog_flush_pending_rows_event(TRUE);
-
/*
NULL denotes ROLLBACK with nothing to replicate: i.e., rollback of
only transactional tables. If the transaction contain changes to
@@ -2606,6 +2605,7 @@ binlog_end_trans(THD *thd, binlog_trx_da
*/
if (end_ev != NULL)
{
+ thd->binlog_flush_pending_rows_event(TRUE);
/*
Doing a commit or a rollback including non-transactional tables,
i.e., ending a transaction where we might write the transaction
@@ -2659,6 +2659,7 @@ binlog_end_trans(THD *thd, binlog_trx_da
mysql_bin_log.update_table_map_version();
}
+ DBUG_ASSERT(thd->binlog_get_pending_rows_event() == NULL);
DBUG_RETURN(error);
}
@@ -2690,6 +2691,7 @@ static int binlog_prepare(handlerton *ht
*/
static int binlog_commit(handlerton *hton, THD *thd, bool all)
{
+ int error= 0;
DBUG_ENTER("binlog_commit");
binlog_trx_data *const trx_data=
(binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
@@ -2726,14 +2728,17 @@ static int binlog_commit(handlerton *hto
Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE);
qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
int error= binlog_end_trans(thd, trx_data, &qev, all);
- DBUG_RETURN(error);
+ goto end;
}
}
else
{
trx_data->reset();
}
- DBUG_RETURN(0);
+end:
+ if (!all)
+ trx_data->before_stmt_pos = MY_OFF_T_UNDEF; // part of the stmt commit
+ DBUG_RETURN(error);
}
/**
@@ -2793,6 +2798,8 @@ static int binlog_rollback(handlerton *h
*/
error= binlog_end_trans(thd, trx_data, 0, all);
}
+ if (!all)
+ trx_data->before_stmt_pos = MY_OFF_T_UNDEF; // part of the stmt rollback
DBUG_RETURN(error);
}
| Thread |
|---|
| • bzr commit into mysql-6.0-bugteam branch (aelkin:2781) Bug#33420 | Andrei Elkin | 8 Dec |