From 7d883c0defe80a210a4b3cb2a9d1b2195497f5b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Feb 2007 15:25:43 +0400 Subject: [PATCH 1/6] Bug#24478 DROP TRIGGER is not caught by replicate-*-table filters Problem: DROP TRIGGER was not properly handled in combination with slave filters, which made replication stop Fix: loading table name before checking slave filters when dropping a trigger. mysql-test/r/rpl_replicate_do.result: Adding test case mysql-test/t/rpl_replicate_do.test: Adding test case sql/sql_parse.cc: Loading table name when dropping a trigger before checking slave filtering rules. sql/sql_trigger.cc: Making add_table_for_trigger() public sql/sql_trigger.h: Making add_table_for_trigger() public --- mysql-test/r/rpl_replicate_do.result | 34 ++++++++++++++++++++++++++++ mysql-test/t/rpl_replicate_do.test | 32 ++++++++++++++++++++++++++ sql/sql_parse.cc | 25 ++++++++++++++++++++ sql/sql_trigger.cc | 6 +---- sql/sql_trigger.h | 4 ++++ 5 files changed, 96 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/rpl_replicate_do.result b/mysql-test/r/rpl_replicate_do.result index f79f6305342..9bacffb0609 100644 --- a/mysql-test/r/rpl_replicate_do.result +++ b/mysql-test/r/rpl_replicate_do.result @@ -41,3 +41,37 @@ select * from t1; ts 2005-08-12 00:00:00 drop table t1; +*** master *** +create table t1 (a int, b int); +create trigger trg1 before insert on t1 for each row set new.b=2; +create table t2 (a int, b int); +create trigger trg2 before insert on t2 for each row set new.b=2; +show tables; +Tables_in_test +t1 +t2 +show triggers; +Trigger Event Table Statement Timing Created sql_mode Definer +trg1 INSERT t1 set new.b=2 BEFORE NULL root@localhost +trg2 INSERT t2 set new.b=2 BEFORE NULL root@localhost +*** slave *** +show tables; +Tables_in_test +t1 +show triggers; +Trigger Event Table Statement Timing Created sql_mode Definer +trg1 INSERT t1 set new.b=2 BEFORE NULL root@localhost +*** master *** +drop trigger trg1; +drop trigger trg2; +show triggers; +Trigger Event Table Statement Timing Created sql_mode Definer +*** slave *** +show tables; +Tables_in_test +t1 +show triggers; +Trigger Event Table Statement Timing Created sql_mode Definer +*** master *** +drop table t1; +drop table t2; diff --git a/mysql-test/t/rpl_replicate_do.test b/mysql-test/t/rpl_replicate_do.test index 9dec8c06c79..0e95d71514b 100644 --- a/mysql-test/t/rpl_replicate_do.test +++ b/mysql-test/t/rpl_replicate_do.test @@ -59,3 +59,35 @@ drop table t1; sync_slave_with_master; # End of 4.1 tests + +# +# Bug#24478 DROP TRIGGER is not caught by replicate-*-table filters +# +--echo *** master *** +connection master; +create table t1 (a int, b int); +create trigger trg1 before insert on t1 for each row set new.b=2; +create table t2 (a int, b int); +create trigger trg2 before insert on t2 for each row set new.b=2; +show tables; +show triggers; +sync_slave_with_master; +--echo *** slave *** +connection slave; +show tables; +show triggers; +--echo *** master *** +connection master; +drop trigger trg1; +drop trigger trg2; +show triggers; +sync_slave_with_master; +--echo *** slave *** +connection slave; +show tables; +show triggers; +--echo *** master *** +connection master; +drop table t1; +drop table t2; +sync_slave_with_master; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b0b7afc6528..7226a8e3c86 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -33,6 +33,7 @@ #include "sp_head.h" #include "sp.h" #include "sp_cache.h" +#include "sql_trigger.h" #ifdef HAVE_OPENSSL /* @@ -2485,6 +2486,30 @@ mysql_execute_command(THD *thd) #ifdef HAVE_REPLICATION if (unlikely(thd->slave_thread)) { + if (lex->sql_command == SQLCOM_DROP_TRIGGER) + { + /* + When dropping a trigger, we need to load its table name + before checking slave filter rules. + */ + add_table_for_trigger(thd, thd->lex->spname, 1, &all_tables); + + if (!all_tables) + { + /* + If table name cannot be loaded, + it means the trigger does not exists possibly because + CREATE TRIGGER was previously skipped for this trigger + according to slave filtering rules. + Returning success without producing any errors in this case. + */ + DBUG_RETURN(0); + } + + // force searching in slave.cc:tables_ok() + all_tables->updating= 1; + } + /* Check if statment should be skipped because of slave filtering rules diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 3569733d064..0b648570b86 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -107,10 +107,6 @@ const LEX_STRING trg_event_type_names[]= }; -static int -add_table_for_trigger(THD *thd, sp_name *trig, bool if_exists, - TABLE_LIST ** table); - class Handle_old_incorrect_sql_modes_hook: public Unknown_key_hook { private: @@ -1183,7 +1179,7 @@ bool Table_triggers_list::get_trigger_info(THD *thd, trg_event_type event, 1 Error */ -static int +int add_table_for_trigger(THD *thd, sp_name *trig, bool if_exists, TABLE_LIST **table) { diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h index 7e0fadfa677..8970986b931 100644 --- a/sql/sql_trigger.h +++ b/sql/sql_trigger.h @@ -139,3 +139,7 @@ private: extern const LEX_STRING trg_action_time_type_names[]; extern const LEX_STRING trg_event_type_names[]; + +int +add_table_for_trigger(THD *thd, sp_name *trig, bool if_exists, + TABLE_LIST **table); From d93c7f39f8ff8db3a6106a474a3791d7b1b9e9c7 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Mar 2007 11:23:12 +0400 Subject: [PATCH 2/6] Additional fix for bug N 15126 Replacing local directory. mysql-test/r/mysqlbinlog.result: Additional fix for bug N 15126 mysql-test/t/mysqlbinlog.test: Additional fix for bug N 15126 --- mysql-test/r/mysqlbinlog.result | 14 +++++++------- mysql-test/t/mysqlbinlog.test | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index 8ca2422443d..0664cc73608 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -307,23 +307,23 @@ SET @@session.sql_mode=0/*!*/; SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/; create table t1 (a varchar(64) character set utf8)/*!*/; SET TIMESTAMP=1000000000/*!*/; -load data LOCAL INFILE '/home/bar/mysql-5.0.b15126/mysql-test/var/tmp/SQL_LOAD_MB-6-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-6-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=7/*!*/; -load data LOCAL INFILE '/home/bar/mysql-5.0.b15126/mysql-test/var/tmp/SQL_LOAD_MB-7-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-7-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=DEFAULT/*!*/; -load data LOCAL INFILE '/home/bar/mysql-5.0.b15126/mysql-test/var/tmp/SQL_LOAD_MB-8-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-8-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; -load data LOCAL INFILE '/home/bar/mysql-5.0.b15126/mysql-test/var/tmp/SQL_LOAD_MB-9-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-9-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=7/*!*/; -load data LOCAL INFILE '/home/bar/mysql-5.0.b15126/mysql-test/var/tmp/SQL_LOAD_MB-a-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-a-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=DEFAULT/*!*/; -load data LOCAL INFILE '/home/bar/mysql-5.0.b15126/mysql-test/var/tmp/SQL_LOAD_MB-b-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-b-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; -load data LOCAL INFILE '/home/bar/mysql-5.0.b15126/mysql-test/var/tmp/SQL_LOAD_MB-c-0' INTO table t1 character set koi8r/*!*/; +load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-c-0' INTO table t1 character set koi8r/*!*/; SET TIMESTAMP=1000000000/*!*/; drop table t1/*!*/; DELIMITER ; diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index fe86d850267..f992729d2be 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -211,6 +211,7 @@ load data infile '../std_data_ln/loaddata6.dat' into table t1 character set koi8 select hex(a) from t1; drop table t1; flush logs; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000011 # End of 5.0 tests From b3fafa40fc839141ba525466e0c98d3db01631f8 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Mar 2007 08:41:13 +0100 Subject: [PATCH 3/6] Fixes of compilation warnings and errors. sql/mysql_priv.h: Removing compiler warning "NULL used in arithmetic" sql/mysqld.cc: First argument to WARN_DEPRECATED is supposed to be a pointer (to THD structure) sql/sql_insert.cc: Removing compiler warning "unused variable". Apparently query is not used when compiling libmysqld. sql/sql_yacc.yy: Removing compiler error "Macro already defined" --- sql/mysql_priv.h | 2 +- sql/mysqld.cc | 2 +- sql/sql_insert.cc | 2 ++ sql/sql_yacc.yy | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 97f56c83b4f..7ca0d567253 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -100,7 +100,7 @@ void net_set_read_timeout(NET *net, uint timeout); #define WARN_DEPRECATED(Thd,Ver,Old,New) \ do { \ DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) > 0); \ - if (Thd != NULL) \ + if (((gptr)Thd) != NULL) \ push_warning_printf(((THD *)Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \ ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX), \ (Old), (Ver), (New)); \ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 5709a12c03d..f8fbbee5644 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -6957,7 +6957,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), if (!slave_warning_issued) //only show the warning once { slave_warning_issued = true; - WARN_DEPRECATED(0, "5.2", "for replication startup options", + WARN_DEPRECATED(NULL, "5.2", "for replication startup options", "'CHANGE MASTER'"); } break; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 613b28faf63..b44cbf46a31 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -381,7 +381,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, List_item *values; Name_resolution_context *context; Name_resolution_context_state ctx_state; +#ifndef EMBEDDED_LIBRARY char *query= thd->query; +#endif bool log_on= (thd->options & OPTION_BIN_LOG) || (!(thd->security_ctx->master_access & SUPER_ACL)); thr_lock_type lock_type = table_list->lock_type; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index efe8d85d8f5..933fa839e71 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -46,6 +46,7 @@ const LEX_STRING null_lex_str={0,0}; #define yyoverflow(A,B,C,D,E,F) {ulong val= *(F); if (my_yyoverflow((B), (D), &val)) { yyerror((char*) (A)); return 2; } else { *(F)= (YYSIZE_T)val; }} +#undef WARN_DEPRECATED /* this macro is also defined in mysql_priv.h */ #define WARN_DEPRECATED(A,B) \ push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, \ ER_WARN_DEPRECATED_SYNTAX, \ From ef02cb6305cab784573a8a607889bf3420c946b3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Mar 2007 11:52:25 +0400 Subject: [PATCH 4/6] Renaming recenly added test case, because of name conflict when merging into 5.1. mysql-test/t/rpl_loaddata_charset.test: Rename: mysql-test/t/rpl_loaddata2.test -> mysql-test/t/rpl_loaddata_charset.test mysql-test/r/rpl_loaddata_charset.result: Rename: mysql-test/r/rpl_loaddata2.result -> mysql-test/r/rpl_loaddata_charset.result --- .../r/{rpl_loaddata2.result => rpl_loaddata_charset.result} | 0 mysql-test/t/{rpl_loaddata2.test => rpl_loaddata_charset.test} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename mysql-test/r/{rpl_loaddata2.result => rpl_loaddata_charset.result} (100%) rename mysql-test/t/{rpl_loaddata2.test => rpl_loaddata_charset.test} (100%) diff --git a/mysql-test/r/rpl_loaddata2.result b/mysql-test/r/rpl_loaddata_charset.result similarity index 100% rename from mysql-test/r/rpl_loaddata2.result rename to mysql-test/r/rpl_loaddata_charset.result diff --git a/mysql-test/t/rpl_loaddata2.test b/mysql-test/t/rpl_loaddata_charset.test similarity index 100% rename from mysql-test/t/rpl_loaddata2.test rename to mysql-test/t/rpl_loaddata_charset.test From 30ece9b060bc141becd5ead9f67058ecfda21bec Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Mar 2007 12:26:07 +0400 Subject: [PATCH 5/6] Fix for wrong replace command. --- mysql-test/r/mysqlbinlog.result | 14 +++++++------- mysql-test/t/mysqlbinlog.test | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index 0664cc73608..9ee2a1e769a 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -307,23 +307,23 @@ SET @@session.sql_mode=0/*!*/; SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/; create table t1 (a varchar(64) character set utf8)/*!*/; SET TIMESTAMP=1000000000/*!*/; -load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-6-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQL_TMP_DIR/SQL_LOAD_MB-6-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=7/*!*/; -load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-7-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQL_TMP_DIR/SQL_LOAD_MB-7-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=DEFAULT/*!*/; -load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-8-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQL_TMP_DIR/SQL_LOAD_MB-8-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; -load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-9-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQL_TMP_DIR/SQL_LOAD_MB-9-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=7/*!*/; -load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-a-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQL_TMP_DIR/SQL_LOAD_MB-a-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.collation_database=DEFAULT/*!*/; -load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-b-0' INTO table t1/*!*/; +load data LOCAL INFILE 'MYSQL_TMP_DIR/SQL_LOAD_MB-b-0' INTO table t1/*!*/; SET TIMESTAMP=1000000000/*!*/; -load data LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-c-0' INTO table t1 character set koi8r/*!*/; +load data LOCAL INFILE 'MYSQL_TMP_DIR/SQL_LOAD_MB-c-0' INTO table t1 character set koi8r/*!*/; SET TIMESTAMP=1000000000/*!*/; drop table t1/*!*/; DELIMITER ; diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index f992729d2be..d35bd16c1f9 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -211,7 +211,7 @@ load data infile '../std_data_ln/loaddata6.dat' into table t1 character set koi8 select hex(a) from t1; drop table t1; flush logs; ---replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR --exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000011 # End of 5.0 tests From 8fa0d1b98e701f3643093696ffe6e6ea02481a82 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Mar 2007 10:40:48 +0100 Subject: [PATCH 6/6] Removing two more compilation warnings. sql/slave.cc: Guard declaration of variable to avoid "unused variable" warning. sql/sql_repl.cc: Guard declaration of variable to avoid "unused variable" warning. --- sql/slave.cc | 2 ++ sql/sql_repl.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sql/slave.cc b/sql/slave.cc index 572fafd58b5..9d466ce5dad 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -52,7 +52,9 @@ ulonglong relay_log_space_limit = 0; int disconnect_slave_event_count = 0, abort_slave_event_count = 0; int events_till_abort = -1; +#ifndef DBUG_OFF static int events_till_disconnect = -1; +#endif typedef enum { SLAVE_THD_IO, SLAVE_THD_SQL} SLAVE_THD_TYPE; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 1702783b5b7..b451c612398 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -22,7 +22,9 @@ int max_binlog_dump_events = 0; // unlimited my_bool opt_sporadic_binlog_dump_fail = 0; +#ifndef DBUG_OFF static int binlog_dump_count = 0; +#endif /* fake_rotate_event() builds a fake (=which does not exist physically in any