diff options
author | Michael Widenius <monty@askmonty.org> | 2013-08-27 19:18:04 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2013-08-27 19:18:04 +0300 |
commit | 112411b056ae16c4addcb9dc84ebf1992b719d59 (patch) | |
tree | 0fa0c040903263e60a00f455afadaa9e83718736 | |
parent | 7907b9b4da8c299318bd73d32b621dc34acc0f35 (diff) | |
download | mariadb-git-112411b056ae16c4addcb9dc84ebf1992b719d59.tar.gz |
Fixed MySQL bug #69861 LAST_INSERT_ID is replicated incorrectly if replication filters are used
mysql-test/suite/rpl/r/last_insert_id.result:
Test case for last_insert_id
mysql-test/suite/rpl/t/last_insert_id.cnf:
Test case for last_insert_id
mysql-test/suite/rpl/t/last_insert_id.test:
Test case for last_insert_id
sql/log_event.cc:
Added DBUG_PRINT
Set thd->first_successful_insert_id_in_prev_stmt_for_binlog when setting thd->first_successful_insert_id_in_prev_stmt.
This is required to get last_insert_id() replicated.
This is analog to how read_first_successful_insert_id_in_prev_stmt() works.
sql/rpl_utility.cc:
Added DBUG_PRINT
-rw-r--r-- | mysql-test/suite/rpl/r/last_insert_id.result | 18 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/last_insert_id.cnf | 20 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/last_insert_id.test | 30 | ||||
-rw-r--r-- | sql/log_event.cc | 12 | ||||
-rw-r--r-- | sql/rpl_utility.cc | 4 |
5 files changed, 79 insertions, 5 deletions
diff --git a/mysql-test/suite/rpl/r/last_insert_id.result b/mysql-test/suite/rpl/r/last_insert_id.result new file mode 100644 index 00000000000..ce64e9df41e --- /dev/null +++ b/mysql-test/suite/rpl/r/last_insert_id.result @@ -0,0 +1,18 @@ +include/rpl_init.inc [topology=1->2->3] +create table t1 (id int not null auto_increment primary key, i int) engine=InnoDB; +insert into t1 (i) values (-1); +insert into t1 (i) values (LAST_INSERT_ID()); +select * from t1; +id i +1 -1 +2 1 +select * from t1; +id i +1 -1 +2 1 +select * from t1; +id i +1 -1 +2 1 +drop table t1; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/last_insert_id.cnf b/mysql-test/suite/rpl/t/last_insert_id.cnf new file mode 100644 index 00000000000..1c229e4ac94 --- /dev/null +++ b/mysql-test/suite/rpl/t/last_insert_id.cnf @@ -0,0 +1,20 @@ +!include suite/rpl/my.cnf + +[mysqld.1] +log-slave-updates +loose-innodb + +[mysqld.2] +log-slave-updates +loose-innodb +replicate-ignore-table=db.t2 + +[mysqld.3] +log-slave-updates +loose-innodb + +[ENV] +SERVER_MYPORT_3= @mysqld.3.port +SERVER_MYSOCK_3= @mysqld.3.socket + + diff --git a/mysql-test/suite/rpl/t/last_insert_id.test b/mysql-test/suite/rpl/t/last_insert_id.test new file mode 100644 index 00000000000..f23cca405ac --- /dev/null +++ b/mysql-test/suite/rpl/t/last_insert_id.test @@ -0,0 +1,30 @@ +--source include/have_innodb.inc +--source include/have_binlog_format_mixed_or_statement.inc +--let $rpl_topology=1->2->3 +--source include/rpl_init.inc + +connection server_1; + +create table t1 (id int not null auto_increment primary key, i int) engine=InnoDB; +insert into t1 (i) values (-1); +insert into t1 (i) values (LAST_INSERT_ID()); +select * from t1; + +save_master_pos; + +connection server_2; + +sync_with_master; +select * from t1; +save_master_pos; + +connection server_3; + +sync_with_master; +select * from t1; + +connection server_1; +drop table t1; + +--source include/rpl_end.inc + diff --git a/sql/log_event.cc b/sql/log_event.cc index e29e0cd688e..928c65f3e44 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -5933,6 +5933,7 @@ void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info) int Intvar_log_event::do_apply_event(Relay_log_info const *rli) { + DBUG_ENTER("Intvar_log_event::do_apply_event"); /* We are now in a statement until the associated query log event has been processed. @@ -5940,18 +5941,23 @@ int Intvar_log_event::do_apply_event(Relay_log_info const *rli) const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT); if (rli->deferred_events_collecting) - return rli->deferred_events->add(this); + { + DBUG_PRINT("info",("deferring event")); + DBUG_RETURN(rli->deferred_events->add(this)); + } switch (type) { case LAST_INSERT_ID_EVENT: thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1; - thd->first_successful_insert_id_in_prev_stmt= val; + thd->first_successful_insert_id_in_prev_stmt_for_binlog= + thd->first_successful_insert_id_in_prev_stmt= val; + DBUG_PRINT("info",("last_insert_id_event: %ld", (long) val)); break; case INSERT_ID_EVENT: thd->force_one_auto_inc_interval(val); break; } - return 0; + DBUG_RETURN(0); } int Intvar_log_event::do_update_pos(Relay_log_info *rli) diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index ed6b9d13584..171112b09f0 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -1145,7 +1145,7 @@ bool Deferred_log_events::is_empty() bool Deferred_log_events::execute(Relay_log_info *rli) { bool res= false; - + DBUG_ENTER("Deferred_log_events::execute"); DBUG_ASSERT(rli->deferred_events_collecting); rli->deferred_events_collecting= false; @@ -1156,7 +1156,7 @@ bool Deferred_log_events::execute(Relay_log_info *rli) res= ev->apply_event(rli); } rli->deferred_events_collecting= true; - return res; + DBUG_RETURN(res); } void Deferred_log_events::rewind() |