From cf8dbcc683b94b6e7f6c44d51b7241c45813decd Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 17 Jul 2004 16:58:16 +0200 Subject: [PATCH] Fixes for BUG#4506 "mysqlbinlog --position --read-from-remote-server has wrong "# at" lines", BUG#4553 "Multi-table DROP TABLE replicates improperly for nonexistent table" with a test file. It was not possible to add a test for BUG#4506 as in the test suite we must use --short-form which does not display the "# at" lines. client/mysqlbinlog.cc: Fix for BUG#4506 "mysqlbinlog --position --read-from-remote-server has wrong "# at" lines" when reading a remote binlog, the start position is not always BIN_LOG_HEADER_SIZE (4). sql/sql_table.cc: Fix for BUG#4553 "Multi-table DROP TABLE replicates improperly for nonexistent table" we must my_error() _before_ we write to the binlog, so that a meaningful error code is available in thd->net.last_errno for storage of the DROP TABLE statement into the binlog. --- client/mysqlbinlog.cc | 4 ++-- mysql-test/r/rpl_drop.result | 10 ++++++++++ mysql-test/t/rpl_drop.test | 10 ++++++++++ sql/sql_table.cc | 35 +++++++++++++++++++---------------- 4 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 mysql-test/r/rpl_drop.result create mode 100644 mysql-test/t/rpl_drop.test diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 7bceedea4fe..7c3d22c4900 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -723,8 +723,8 @@ static int dump_remote_log_entries(const char* logname) */ if (old_off) old_off+= len-1; - else - old_off= BIN_LOG_HEADER_SIZE; + else // first event, so it's a fake Rotate event + old_off= position; } return 0; } diff --git a/mysql-test/r/rpl_drop.result b/mysql-test/r/rpl_drop.result new file mode 100644 index 00000000000..ce1f5b6ee81 --- /dev/null +++ b/mysql-test/r/rpl_drop.result @@ -0,0 +1,10 @@ +slave stop; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +slave start; +drop table if exists t1, t2; +create table t1 (a int); +drop table t1, t2; +Unknown table 't2' diff --git a/mysql-test/t/rpl_drop.test b/mysql-test/t/rpl_drop.test new file mode 100644 index 00000000000..6fc2500fc97 --- /dev/null +++ b/mysql-test/t/rpl_drop.test @@ -0,0 +1,10 @@ +# Testcase for BUG#4552 (DROP on two tables, one of which does not +# exist, must be binlogged with a non-zero error code) +source include/master-slave.inc; +drop table if exists t1, t2; +create table t1 (a int); +--error 1051; +drop table t1, t2; +save_master_pos; +connection slave; +sync_with_master; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1b956779832..9ab4859bc13 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -230,23 +230,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, wrong_tables.append(String(table->real_name)); } } - if (some_tables_deleted || tmp_table_deleted) - { - query_cache_invalidate3(thd, tables, 0); - if (!dont_log_query) - { - mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - Query_log_event qinfo(thd, thd->query, thd->query_length, - tmp_table_deleted && !some_tables_deleted); - mysql_bin_log.write(&qinfo); - } - } - } - unlock_table_names(thd, tables); error= 0; if (wrong_tables.length()) { @@ -256,6 +240,25 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, my_error(ER_ROW_IS_REFERENCED,MYF(0)); error= 1; } + + if (some_tables_deleted || tmp_table_deleted) + { + query_cache_invalidate3(thd, tables, 0); + if (!dont_log_query) + { + mysql_update_log.write(thd, thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + if (!error) + thd->clear_error(); + Query_log_event qinfo(thd, thd->query, thd->query_length, + tmp_table_deleted && !some_tables_deleted); + mysql_bin_log.write(&qinfo); + } + } + } + + unlock_table_names(thd, tables); DBUG_RETURN(error); }