From 8a8d476453437b27df0bc7ff63d138c743df11f1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Feb 2005 18:39:33 +0100 Subject: [PATCH 1/2] Bug#8412: For replication to work correctly, the prologue and epilogue to an SQL statement should not have an error code even when the SQL statement itself has an error code. mysql-test/r/rpl_insert_id.result: Adding test to ensure that slave handles error statement gracefully. mysql-test/t/rpl_insert_id.test: Adding test to ensure that slave handles error statement gracefully. sql/log.cc: Setting error code to 0 for SQL statement prologue and epilogue. --- mysql-test/r/rpl_insert_id.result | 5 +++++ mysql-test/t/rpl_insert_id.test | 16 ++++++++++++++++ sql/log.cc | 15 ++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/rpl_insert_id.result b/mysql-test/r/rpl_insert_id.result index d2dfbb05675..da815241bbe 100644 --- a/mysql-test/r/rpl_insert_id.result +++ b/mysql-test/r/rpl_insert_id.result @@ -69,3 +69,8 @@ b c 9 13 drop table t1; drop table t2; +SET TIMESTAMP=1000000000; +CREATE TABLE t1 ( a INT UNIQUE ); +SET FOREIGN_KEY_CHECKS=0; +INSERT INTO t1 VALUES (1),(1); +Duplicate entry '1' for key 1 diff --git a/mysql-test/t/rpl_insert_id.test b/mysql-test/t/rpl_insert_id.test index a6da44de456..33d6516632a 100644 --- a/mysql-test/t/rpl_insert_id.test +++ b/mysql-test/t/rpl_insert_id.test @@ -62,3 +62,19 @@ drop table t2; save_master_pos; connection slave; sync_with_master; + +# +# Bug#8412: Error codes reported in binary log for CHARACTER SET, +# FOREIGN_KEY_CHECKS +# +connection master; +SET TIMESTAMP=1000000000; +CREATE TABLE t1 ( a INT UNIQUE ); +SET FOREIGN_KEY_CHECKS=0; +--error 1062 +INSERT INTO t1 VALUES (1),(1); +sync_slave_with_master; + + + + diff --git a/sql/log.cc b/sql/log.cc index b46a8de056e..18c644473f1 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1182,6 +1182,7 @@ bool MYSQL_LOG::write(Log_event* event_info) p= strmov(strmov(buf, "SET CHARACTER SET "), thd->variables.convert_set->name); Query_log_event e(thd, buf, (ulong) (p - buf), 0); + e.error_code = 0; // This statement cannot fail (see [1]). e.set_log_pos(this); if (e.write(file)) goto err; @@ -1199,12 +1200,22 @@ bool MYSQL_LOG::write(Log_event* event_info) { Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=0", 24, 0); e.set_log_pos(this); + e.error_code = 0; // This statement cannot fail (see [1]). if (e.write(file)) goto err; } } - /* Write the SQL command */ + /* + Write the SQL command + + [1] If this statement has an error code, the slave is required to fail + with the same error code or stop. The preamble and epilogue should + *not* have this error code since the execution of those is + guaranteed *not* to produce any error code. This would therefore + stop the slave even if the execution of the real statement can be + handled gracefully by the slave. + */ event_info->set_log_pos(this); if (event_info->write(file)) @@ -1218,6 +1229,7 @@ bool MYSQL_LOG::write(Log_event* event_info) { Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=1", 24, 0); e.set_log_pos(this); + e.error_code = 0; // This statement cannot fail (see [1]). if (e.write(file)) goto err; } @@ -1226,6 +1238,7 @@ bool MYSQL_LOG::write(Log_event* event_info) { Query_log_event e(thd, "SET CHARACTER SET DEFAULT", 25, 0); e.set_log_pos(this); + e.error_code = 0; // This statement cannot fail (see [1]). if (e.write(file)) goto err; } From 7f1384543202edfe2a16702a484502eb7dcbac67 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 23 Feb 2005 20:59:00 +0100 Subject: [PATCH 2/2] Bug#8412: Setting error code to 0 on statements that cannot fail. sql/log.cc: Setting error code to 0 on SQL statements that cannot fail. --- sql/log.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/log.cc b/sql/log.cc index 32574ca4a0d..c8a3b512b6d 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1322,6 +1322,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", (uint) thd->variables.collation_server->number); Query_log_event e(thd, buf, written, 0, FALSE); e.set_log_pos(this); + e.error_code = 0; // This statement cannot fail (see [1]). if (e.write(file)) goto err; } @@ -1338,6 +1339,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", "'", NullS); Query_log_event e(thd, buf, buf_end - buf, 0, FALSE); e.set_log_pos(this); + e.error_code = 0; // This statement cannot fail (see [1]). if (e.write(file)) goto err; } @@ -1389,8 +1391,8 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", p= strmov(strmov(buf, "SET CHARACTER SET "), thd->variables.convert_set->name); Query_log_event e(thd, buf, (ulong) (p - buf), 0); - e.error_code = 0; // This statement cannot fail (see [1]). e.set_log_pos(this); + e.error_code = 0; // This statement cannot fail (see [1]). if (e.write(file)) goto err; }