Commit 354f5f7b authored by Alfranio Correia's avatar Alfranio Correia

BUG#46864 Incorrect update of InnoDB table on slave when using trigger with myisam table

Slave does not correctly handle "expected errors" leading to inconsistencies
between the mater and slave. Specifically, when a statement changes both
transactional and non-transactional tables, the transactional changes are
automatically rolled back on the master but the slave ignores the error and
does not roll them back thus leading to inconsistencies.
      
To fix the problem, we automatically roll back a statement that fails on
the slave but note that the transaction is not rolled back unless a "rollback"
command is in the relay log file.

mysql-test/extra/rpl_tests/rpl_mixing_engines.test:
  Enabled item 13.e which was disabled because of the bug fixed by the
  current and removed item 14 which was introduced by mistake.
parent 51f4ccfa
...@@ -562,21 +562,21 @@ let $binlog_start= query_get_value("SHOW MASTER STATUS", Position, 1); ...@@ -562,21 +562,21 @@ let $binlog_start= query_get_value("SHOW MASTER STATUS", Position, 1);
--echo # There is a bug in the slave that needs to be fixed before enabling --echo # There is a bug in the slave that needs to be fixed before enabling
--echo # this part of the test. A bug report will be filed referencing this --echo # this part of the test. A bug report will be filed referencing this
--echo # test case. --echo # test case.
#
#BEGIN; BEGIN;
#INSERT INTO nt_3 VALUES ("new text -28", -28, ''); INSERT INTO nt_3 VALUES ("new text -28", -28, '');
#--error ER_DUP_ENTRY --error ER_DUP_ENTRY
#INSERT INTO tt_3 VALUES ("new text -27", -27, ''), ("new text -28", -28, ''); INSERT INTO tt_3 VALUES ("new text -27", -27, ''), ("new text -28", -28, '');
#INSERT INTO tt_1 VALUES ("new text -27", -27, ''); INSERT INTO tt_1 VALUES ("new text -27", -27, '');
#COMMIT; COMMIT;
#
#BEGIN; BEGIN;
#INSERT INTO tt_4 VALUES ("new text -28", -28, ''); INSERT INTO tt_4 VALUES ("new text -28", -28, '');
#--error ER_DUP_ENTRY --error ER_DUP_ENTRY
#INSERT INTO nt_4 VALUES ("new text -27", -27, ''), ("new text -28", -28, ''); INSERT INTO nt_4 VALUES ("new text -27", -27, ''), ("new text -28", -28, '');
#INSERT INTO tt_1 VALUES ("new text -28", -28, ''); INSERT INTO tt_1 VALUES ("new text -28", -28, '');
#COMMIT; COMMIT;
#
--source include/show_binlog_events.inc --source include/show_binlog_events.inc
--echo --echo
...@@ -683,23 +683,6 @@ ROLLBACK; ...@@ -683,23 +683,6 @@ ROLLBACK;
--source include/show_binlog_events.inc --source include/show_binlog_events.inc
--echo
--echo
--echo
--echo
let $binlog_start= query_get_value("SHOW MASTER STATUS", Position, 1);
--echo #
--echo #14) "B M T R" with error in M generates in the binlog the "B M T R" entries.
--echo #
BEGIN;
INSERT INTO tt_4 VALUES ("new text -32", -32, '');
TRUNCATE TABLE tt_4;
INSERT INTO tt_4 VALUES ("new text -33", -33, '');
ROLLBACK;
--source include/show_binlog_events.inc
connection master; connection master;
sync_slave_with_master; sync_slave_with_master;
......
...@@ -652,8 +652,30 @@ master-bin.000001 # Xid # # COMMIT /* XID */ ...@@ -652,8 +652,30 @@ master-bin.000001 # Xid # # COMMIT /* XID */
# There is a bug in the slave that needs to be fixed before enabling # There is a bug in the slave that needs to be fixed before enabling
# this part of the test. A bug report will be filed referencing this # this part of the test. A bug report will be filed referencing this
# test case. # test case.
BEGIN;
INSERT INTO nt_3 VALUES ("new text -28", -28, '');
INSERT INTO tt_3 VALUES ("new text -27", -27, ''), ("new text -28", -28, '');
ERROR 23000: Duplicate entry '-28' for key 'PRIMARY'
INSERT INTO tt_1 VALUES ("new text -27", -27, '');
COMMIT;
BEGIN;
INSERT INTO tt_4 VALUES ("new text -28", -28, '');
INSERT INTO nt_4 VALUES ("new text -27", -27, ''), ("new text -28", -28, '');
ERROR 23000: Duplicate entry '-28' for key 'PRIMARY'
INSERT INTO tt_1 VALUES ("new text -28", -28, '');
COMMIT;
show binlog events from <binlog_start>; show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # use `test`; INSERT INTO nt_3 VALUES ("new text -28", -28, '')
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_3 VALUES ("new text -27", -27, ''), ("new text -28", -28, '')
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1 VALUES ("new text -27", -27, '')
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_4 VALUES ("new text -28", -28, '')
master-bin.000001 # Query # # use `test`; INSERT INTO nt_4 VALUES ("new text -27", -27, ''), ("new text -28", -28, '')
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1 VALUES ("new text -28", -28, '')
master-bin.000001 # Xid # # COMMIT /* XID */
...@@ -832,29 +854,6 @@ master-bin.000001 # Query # # use `test`; INSERT INTO tt_4 VALUES ("new text -30 ...@@ -832,29 +854,6 @@ master-bin.000001 # Query # # use `test`; INSERT INTO tt_4 VALUES ("new text -30
master-bin.000001 # Query # # use `test`; INSERT INTO nt_4 VALUES ("new text -29", -29, ''), ("new text -30", -30, '') master-bin.000001 # Query # # use `test`; INSERT INTO nt_4 VALUES ("new text -29", -29, ''), ("new text -30", -30, '')
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1 VALUES ("new text -31", -31, '') master-bin.000001 # Query # # use `test`; INSERT INTO tt_1 VALUES ("new text -31", -31, '')
master-bin.000001 # Query # # ROLLBACK master-bin.000001 # Query # # ROLLBACK
#
#14) "B M T R" with error in M generates in the binlog the "B M T R" entries.
#
BEGIN;
INSERT INTO tt_4 VALUES ("new text -32", -32, '');
TRUNCATE TABLE tt_4;
INSERT INTO tt_4 VALUES ("new text -33", -33, '');
ROLLBACK;
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_4 VALUES ("new text -32", -32, '')
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; TRUNCATE TABLE tt_4
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_4 VALUES ("new text -33", -33, '')
master-bin.000001 # Xid # # COMMIT /* XID */
################################################################################### ###################################################################################
# CLEAN # CLEAN
################################################################################### ###################################################################################
......
...@@ -3202,6 +3202,15 @@ Default database: '%s'. Query: '%s'", ...@@ -3202,6 +3202,15 @@ Default database: '%s'. Query: '%s'",
DBUG_PRINT("info",("error ignored")); DBUG_PRINT("info",("error ignored"));
clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
thd->killed= THD::NOT_KILLED; thd->killed= THD::NOT_KILLED;
/*
When an error is expected and matches the actual error the
slave does not report any error and by consequence changes
on transactional tables are not rolled back in the function
close_thread_tables(). For that reason, we explicitly roll
them back here.
*/
if (expected_error && expected_error == actual_error)
ha_autocommit_or_rollback(thd, TRUE);
} }
/* /*
If we expected a non-zero error code and get nothing and, it is a concurrency If we expected a non-zero error code and get nothing and, it is a concurrency
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment