MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Dao-Gang.Qu Date:December 7 2010 6:58am
Subject:bzr commit into mysql-5.1-bugteam branch (Dao-Gang.Qu:3521) Bug#50914
View as plain text  
#At file:///home/daogang/bzrwork/bug50914/mysql-5.1-bugteam/ based on revid:azundris@stripped

 3521 Dao-Gang.Qu@stripped	2010-12-07
      Bug #50914  	mysqlbinlog not handling drop of current default database
      
      mysqlbinlog only prints "use $database" statements to its output stream
      when the active default database changes between events. Which will cause
      "No Database Selected" error when dropping and recreating that database
      though.
      
      To fix the problem to clear print_event_info->db when printing an event
      with LOG_EVENT_SUPPRESS_USE flag, which will be set for CREATE/DROP/ALTER
      database statements, so that the Query_log_event after such statements
      will be printed with the use 'db' anyway.
     @ mysql-test/extra/binlog_tests/database.test
        Added test to verify if the approach of the mysqlbinlog prints
        "use $database"statements to its output stream will cause
        "No Database Selected" error when dropping and recreating
        that database though.
     @ mysql-test/r/mysqlbinlog.result
        Updated for the patch of Bug#50914.
     @ mysql-test/suite/binlog/r/binlog_database.result
        Test result for Bug#50914.
     @ sql/log_event.cc
        Updated code to make mysqlbinlog print "use $database" statements
        to its output stream for every query log event as long as the
        database is not suppressed expressly.

    modified:
      mysql-test/extra/binlog_tests/database.test
      mysql-test/r/mysqlbinlog.result
      mysql-test/suite/binlog/r/binlog_database.result
      sql/log_event.cc
=== modified file 'mysql-test/extra/binlog_tests/database.test'
--- a/mysql-test/extra/binlog_tests/database.test	2009-01-23 12:22:05 +0000
+++ b/mysql-test/extra/binlog_tests/database.test	2010-12-07 06:58:31 +0000
@@ -12,6 +12,7 @@ create function sf1 (a int) returns int
 create trigger tr1 before insert on t1 for each row insert into t2 values (2*new.a);
 create procedure sp1 (a int) insert into t1 values(a);
 drop database testing_1;
+let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
 source include/show_binlog_events.inc;
 
 # BUG#38773: DROP DATABASE cause switch to stmt-mode when there are
@@ -27,6 +28,34 @@ drop database if exists mysqltest1;
 enable_warnings;
 insert into t1 values (1);
 drop table tt1, t1;
+let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+source include/show_binlog_events.inc;
+
+#
+# BUG#50914
+# This test verifies if the approach of the mysqlbinlog prints
+# "use $database"statements to its output stream will cause
+# "No Database Selected" error when dropping and recreating
+# that database though.
+#
+RESET master;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP DATABASE test1;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP TABLE t1;
+DROP DATABASE test1;
+let $master_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
+FLUSH LOGS;
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+exec $MYSQL_BINLOG $MYSQLD_DATADIR/$master_binlog | $MYSQL test 2>&1;
+
+let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
 source include/show_binlog_events.inc;
 
 FLUSH STATUS;
+

=== modified file 'mysql-test/r/mysqlbinlog.result'
--- a/mysql-test/r/mysqlbinlog.result	2010-03-28 11:57:33 +0000
+++ b/mysql-test/r/mysqlbinlog.result	2010-12-07 06:58:31 +0000
@@ -499,6 +499,7 @@ create table t1(a int) engine= innodb
 SET TIMESTAMP=1253783037/*!*/;
 BEGIN
 /*!*/;
+use test/*!*/;
 SET TIMESTAMP=1253783037/*!*/;
 insert into t1 (a) values (1)
 /*!*/;
@@ -509,18 +510,21 @@ create table t3(a int) engine= innodb
 SET TIMESTAMP=1253783037/*!*/;
 BEGIN
 /*!*/;
+use test/*!*/;
 SET TIMESTAMP=1253783037/*!*/;
 insert into t3 (a) values (2)
 /*!*/;
 SET TIMESTAMP=1253783037/*!*/;
 ROLLBACK
 /*!*/;
+use test/*!*/;
 SET TIMESTAMP=1253783037/*!*/;
 create table t5(a int) engine= NDB
 /*!*/;
 SET TIMESTAMP=1253783037/*!*/;
 BEGIN
 /*!*/;
+use test/*!*/;
 SET TIMESTAMP=1253783037/*!*/;
 insert into t5 (a) values (3)
 /*!*/;

=== modified file 'mysql-test/suite/binlog/r/binlog_database.result'
--- a/mysql-test/suite/binlog/r/binlog_database.result	2009-05-31 05:44:41 +0000
+++ b/mysql-test/suite/binlog/r/binlog_database.result	2010-12-07 06:58:31 +0000
@@ -7,7 +7,7 @@ create function sf1 (a int) returns int
 create trigger tr1 before insert on t1 for each row insert into t2 values (2*new.a);
 create procedure sp1 (a int) insert into t1 values(a);
 drop database testing_1;
-show binlog events from <binlog_start>;
+show binlog events in 'master-bin.000001' from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	create database testing_1
 master-bin.000001	#	Query	#	#	use `testing_1`; create table t1 (a int)
@@ -25,7 +25,7 @@ insert into t1 values (1);
 drop database if exists mysqltest1;
 insert into t1 values (1);
 drop table tt1, t1;
-show binlog events from <binlog_start>;
+show binlog events in 'master-bin.000001' from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	use `test`; create temporary table tt1 (a int)
 master-bin.000001	#	Query	#	#	use `test`; create table t1 (a int)
@@ -33,6 +33,26 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	drop database if exists mysqltest1
 master-bin.000001	#	Query	#	#	use `test`; insert into t1 values (1)
 master-bin.000001	#	Query	#	#	use `test`; drop table tt1, t1
+RESET master;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP DATABASE test1;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP TABLE t1;
+DROP DATABASE test1;
+FLUSH LOGS;
+show binlog events in 'master-bin.000002' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000002	#	Query	#	#	CREATE DATABASE test1
+master-bin.000002	#	Query	#	#	use `test1`; CREATE TABLE t1(id int)
+master-bin.000002	#	Query	#	#	DROP DATABASE test1
+master-bin.000002	#	Query	#	#	CREATE DATABASE test1
+master-bin.000002	#	Query	#	#	use `test1`; CREATE TABLE t1(id int)
+master-bin.000002	#	Query	#	#	use `test1`; DROP TABLE t1
+master-bin.000002	#	Query	#	#	DROP DATABASE test1
 FLUSH STATUS;
 set binlog_format=mixed;
 reset master;
@@ -43,7 +63,7 @@ create function sf1 (a int) returns int
 create trigger tr1 before insert on t1 for each row insert into t2 values (2*new.a);
 create procedure sp1 (a int) insert into t1 values(a);
 drop database testing_1;
-show binlog events from <binlog_start>;
+show binlog events in 'master-bin.000001' from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	create database testing_1
 master-bin.000001	#	Query	#	#	use `testing_1`; create table t1 (a int)
@@ -61,7 +81,7 @@ insert into t1 values (1);
 drop database if exists mysqltest1;
 insert into t1 values (1);
 drop table tt1, t1;
-show binlog events from <binlog_start>;
+show binlog events in 'master-bin.000001' from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	use `test`; create temporary table tt1 (a int)
 master-bin.000001	#	Query	#	#	use `test`; create table t1 (a int)
@@ -69,6 +89,26 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	drop database if exists mysqltest1
 master-bin.000001	#	Query	#	#	use `test`; insert into t1 values (1)
 master-bin.000001	#	Query	#	#	use `test`; drop table tt1, t1
+RESET master;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP DATABASE test1;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP TABLE t1;
+DROP DATABASE test1;
+FLUSH LOGS;
+show binlog events in 'master-bin.000002' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000002	#	Query	#	#	CREATE DATABASE test1
+master-bin.000002	#	Query	#	#	use `test1`; CREATE TABLE t1(id int)
+master-bin.000002	#	Query	#	#	DROP DATABASE test1
+master-bin.000002	#	Query	#	#	CREATE DATABASE test1
+master-bin.000002	#	Query	#	#	use `test1`; CREATE TABLE t1(id int)
+master-bin.000002	#	Query	#	#	use `test1`; DROP TABLE t1
+master-bin.000002	#	Query	#	#	DROP DATABASE test1
 FLUSH STATUS;
 set binlog_format=row;
 reset master;
@@ -79,7 +119,7 @@ create function sf1 (a int) returns int
 create trigger tr1 before insert on t1 for each row insert into t2 values (2*new.a);
 create procedure sp1 (a int) insert into t1 values(a);
 drop database testing_1;
-show binlog events from <binlog_start>;
+show binlog events in 'master-bin.000001' from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	create database testing_1
 master-bin.000001	#	Query	#	#	use `testing_1`; create table t1 (a int)
@@ -97,7 +137,7 @@ insert into t1 values (1);
 drop database if exists mysqltest1;
 insert into t1 values (1);
 drop table tt1, t1;
-show binlog events from <binlog_start>;
+show binlog events in 'master-bin.000001' from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	use `test`; create table t1 (a int)
 master-bin.000001	#	Query	#	#	BEGIN
@@ -110,6 +150,26 @@ master-bin.000001	#	Table_map	#	#	table_
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	use `test`; DROP TABLE `t1` /* generated by server */
+RESET master;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP DATABASE test1;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP TABLE t1;
+DROP DATABASE test1;
+FLUSH LOGS;
+show binlog events in 'master-bin.000002' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000002	#	Query	#	#	CREATE DATABASE test1
+master-bin.000002	#	Query	#	#	use `test1`; CREATE TABLE t1(id int)
+master-bin.000002	#	Query	#	#	DROP DATABASE test1
+master-bin.000002	#	Query	#	#	CREATE DATABASE test1
+master-bin.000002	#	Query	#	#	use `test1`; CREATE TABLE t1(id int)
+master-bin.000002	#	Query	#	#	use `test1`; DROP TABLE t1
+master-bin.000002	#	Query	#	#	DROP DATABASE test1
 FLUSH STATUS;
 show databases;
 Database

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2010-10-23 12:55:44 +0000
+++ b/sql/log_event.cc	2010-12-07 06:58:31 +0000
@@ -2894,7 +2894,9 @@ void Query_log_event::print_query_header
                 error_code);
   }
 
-  if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
+  if (flags & LOG_EVENT_SUPPRESS_USE_F)
+    print_event_info->db[0]= '\0';
+  else if (db)
   {
     different_db= memcmp(print_event_info->db, db, db_len + 1);
     if (different_db)


Attachment: [text/bzr-bundle] bzr/dao-gang.qu@sun.com-20101207065831-74g6z9vqezkpdve8.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (Dao-Gang.Qu:3521) Bug#50914Dao-Gang.Qu7 Dec
  • Re: bzr commit into mysql-5.1-bugteam branch (Dao-Gang.Qu:3521)Bug#50914Libing Song10 Dec
    • Re: bzr commit into mysql-5.1-bugteam branch (Dao-Gang.Qu:3521)Bug#50914Daogang Qu13 Dec
      • Re: bzr commit into mysql-5.1-bugteam branch (Dao-Gang.Qu:3521)Bug#50914Libing Song13 Dec
        • Re: bzr commit into mysql-5.1-bugteam branch (Dao-Gang.Qu:3521)Bug#50914Daogang Qu14 Dec
    • Re: bzr commit into mysql-5.1-bugteam branch (Dao-Gang.Qu:3521)Bug#50914Daogang Qu13 Dec