From 78585a25ff19eb304185d50f864138e0b5f29106 Mon Sep 17 00:00:00 2001 From: Alfranio Correia Date: Thu, 13 Aug 2009 17:21:01 +0100 Subject: [PATCH] BUG#46130 Slave does not correctly handle "expected errors" In STATEMENT based replication, a statement that failed on the master but that updated non-transactional tables is written to binary log with the error code appended to it. On the slave, the statement is executed and the same error is expected. However, when an "expected error" did not happen on the slave and was either ignored or was related to a concurrency issue on the master, the slave did not rollback the effects of the statement and as such inconsistencies might happen. To fix the problem, we automatically rollback a statement that should have failed on a slave but succeded and whose expected failure is either ignored or stems from a concurrency issue on the master. --- mysql-test/suite/rpl/r/rpl_concurrency_error.result | 2 ++ mysql-test/suite/rpl/t/rpl_concurrency_error.test | 13 ++++++------- sql/log_event.cc | 13 +++++++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_concurrency_error.result b/mysql-test/suite/rpl/r/rpl_concurrency_error.result index 88ad3da6450..83e5f66a9c4 100644 --- a/mysql-test/suite/rpl/r/rpl_concurrency_error.result +++ b/mysql-test/suite/rpl/r/rpl_concurrency_error.result @@ -101,6 +101,8 @@ master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'dark blue 1' WHERE f master-bin.000001 # Query # # use `test`; INSERT INTO t VALUES (6 + (1 * 10),"brown") master-bin.000001 # Query # # use `test`; INSERT INTO n VALUES (now(),"brown") master-bin.000001 # Xid # # COMMIT /* XID */ +source include/diff_master_slave.inc; +source include/diff_master_slave.inc; ######################################################################## # Cleanup ######################################################################## diff --git a/mysql-test/suite/rpl/t/rpl_concurrency_error.test b/mysql-test/suite/rpl/t/rpl_concurrency_error.test index 816abb5739f..da2951afb1a 100644 --- a/mysql-test/suite/rpl/t/rpl_concurrency_error.test +++ b/mysql-test/suite/rpl/t/rpl_concurrency_error.test @@ -125,14 +125,13 @@ while ($type) connection master; sync_slave_with_master; -# Re-enable this after fixing BUG#46130 -#connection master; -#let $diff_statement= SELECT * FROM t order by i; -#source include/diff_master_slave.inc; +connection master; +let $diff_statement= SELECT * FROM t order by i; +source include/diff_master_slave.inc; -#connection master; -#let $diff_statement= SELECT * FROM n order by d, f; -#source include/diff_master_slave.inc; +connection master; +let $diff_statement= SELECT * FROM n order by d, f; +source include/diff_master_slave.inc; --echo ######################################################################## --echo # Cleanup diff --git a/sql/log_event.cc b/sql/log_event.cc index e7cbbaba38e..49d5478c3c4 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3160,7 +3160,7 @@ compare_errors: /* If we expected a non-zero error code, and we don't get the same error - code, and none of them should be ignored. + code, and it should be ignored or is related to a concurrency issue. */ actual_error= thd->is_error() ? thd->main_da.sql_errno() : 0; DBUG_PRINT("info",("expected_error: %d sql_errno: %d", @@ -3183,7 +3183,8 @@ Default database: '%s'. Query: '%s'", thd->is_slave_error= 1; } /* - If we get the same error code as expected, or they should be ignored. + If we get the same error code as expected and it is not a concurrency + issue, or should be ignored. */ else if ((expected_error == actual_error && !concurrency_error_code(expected_error)) || @@ -3193,6 +3194,14 @@ Default database: '%s'. Query: '%s'", clear_all_errors(thd, const_cast(rli)); thd->killed= THD::NOT_KILLED; } + /* + If we expected a non-zero error code and get nothing and, it is a concurrency + issue or should be ignored. + */ + else if (expected_error && !actual_error && + (concurrency_error_code(expected_error) || + ignored_error_code(expected_error))) + ha_autocommit_or_rollback(thd, TRUE); /* Other cases: mostly we expected no error and get one. */