MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Anurag Shekhar Date:February 16 2010 7:51am
Subject:bzr commit into mysql-5.5-next-mr-backup branch (anurag.shekhar:3096)
Bug#50678
View as plain text  
#At file:///home/anurag/mysqlsrc/mysql-next-mr-backup/ based on revid:anurag.shekhar@stripped

 3096 Anurag Shekhar	2010-02-16
      Bug #50678  Restore does not stop replication when server 
                  option --binlog-do-db is enabled.
      
      Binlog filtering depends on the default database 
      (set using "USE db"). Except for CREATE database, 
      ALTER database and DROP database the database in 
      the operations is not used for filtering. This causes 
      the INCIDENT event generation non intuitive, event 
      is generated if restore starts from a binlogged database 
      irrespective of whether the database being restored is 
      binlogged or not.
      
      To fix this problem changed restore to switch the default 
      database to a binlogged database, if one or more of the 
      database being restored is binloged, and unset the default 
      database (by setting it to NULL) if none of the database 
      is binlogged.
     @ mysql-test/suite/backup/r/backup_rpl_incident.result
        Result file for newly added test case.
     @ mysql-test/suite/backup/t/backup_rpl_incident-master.opt
        Option file to set binlog filtering for test case.
     @ mysql-test/suite/backup/t/backup_rpl_incident.test
        Test case to test incident event during restore.
     @ sql/backup/kernel.cc
        Added code to unset the default database if none 
        of the database being restored is binlogged and 
        set to a binlogged database if one or more database 
        being restored is binlogged.

    added:
      mysql-test/suite/backup/r/backup_rpl_incident.result
      mysql-test/suite/backup/t/backup_rpl_incident-master.opt
      mysql-test/suite/backup/t/backup_rpl_incident.test
    modified:
      sql/backup/kernel.cc
=== added file 'mysql-test/suite/backup/r/backup_rpl_incident.result'
--- a/mysql-test/suite/backup/r/backup_rpl_incident.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/r/backup_rpl_incident.result	2010-02-16 07:51:11 +0000
@@ -0,0 +1,229 @@
+# Test cases for incident event with binlog filter is on.
+stop slave;
+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;
+start slave;
+#
+# Bug #50678 Restore does not stop replication when server option --binlog-do-db is enabled.
+#
+# Following test cases uses two database db1 and db2.
+# binlog filter is enabled so db1 is binlogged but db2 is not.
+CREATE DATABASE db1;
+CREATE DATABASE db2;
+# Test Case Descriptions
+# Case 1: db2 is backed up and restored. It should have no effect on replication.
+# Case 2: db1 is backed up and restored. An incident event should be generated.
+# Connecting to master...
+USE db1;
+CREATE TABLE t1(id INT NOT NULL PRIMARY KEY, name VARCHAR(10));
+CREATE TABLE t12(a CHAR(5));
+INSERT INTO t1 VALUES(1,'jon'),(2,'jil'),(3,'jack'),(4,'ku');
+USE db2;
+CREATE TABLE t2 (id INT);
+INSERT INTO t2 VALUES (3), (4);
+# Remove all entries in the backup logs.
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+# connecting to slave...
+# Check the server option --binlog-do-db=db1 works
+# All 4 rows shows appear
+SELECT * FROM db1.t1;
+id	name
+1	jon
+2	jil
+3	jack
+4	ku
+# The selects from db2 will not work as they are ignored
+# for replication
+SELECT * FROM db2.t21;
+ERROR 42S02: Table 'db2.t21' doesn't exist
+SELECT * FROM db2.t22;
+ERROR 42S02: Table 'db2.t22' doesn't exist
+# Test Case 1
+# connecting to master
+# Perform backup
+BACKUP DATABASE db2 to 'db2.bak';
+backup_id
+#
+RESTORE FROM 'db2.bak' OVERWRITE;
+backup_id
+#
+SHOW SLAVE STATUS;;
+Slave_IO_State	#
+Master_Host	127.0.0.1
+Master_User	root
+Master_Port	MASTER_PORT
+Connect_Retry	1
+Master_Log_File	#
+Read_Master_Log_Pos	#
+Relay_Log_File	#
+Relay_Log_Pos	#
+Relay_Master_Log_File	master-bin.000002
+Slave_IO_Running	Yes
+Slave_SQL_Running	Yes
+Replicate_Do_DB	
+Replicate_Ignore_DB	
+Replicate_Do_Table	
+Replicate_Ignore_Table	
+Replicate_Wild_Do_Table	
+Replicate_Wild_Ignore_Table	
+Last_Errno	0
+Last_Error	
+Skip_Counter	0
+Exec_Master_Log_Pos	#
+Relay_Log_Space	#
+Until_Condition	None
+Until_Log_File	
+Until_Log_Pos	0
+Master_SSL_Allowed	No
+Master_SSL_CA_File	
+Master_SSL_CA_Path	
+Master_SSL_Cert	
+Master_SSL_Cipher	
+Master_SSL_Key	
+Seconds_Behind_Master	#
+Master_SSL_Verify_Server_Cert	No
+Last_IO_Errno	0
+Last_IO_Error	
+Last_SQL_Errno	0
+Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
+# See for any error that has occured because of incident event
+# There shouldn't be any
+Last_SQL_Error
+
+# Conencting to master again to check replication is ON
+USE db1;
+INSERT INTO db1.t1 VALUES(5,'pp'),(6,'kiy');
+USE db2;
+INSERT INTO db2.t2 VALUES(5),(6);
+SELECT * FROM db1.t1;
+id	name
+1	jon
+2	jil
+3	jack
+4	ku
+5	pp
+6	kiy
+SELECT * FROM db2.t2;
+id
+3
+4
+5
+6
+# All 6 rows shows appear
+SELECT * FROM db1.t1;
+id	name
+1	jon
+2	jil
+3	jack
+4	ku
+5	pp
+6	kiy
+SELECT * FROM db2.t2;
+ERROR 42S02: Table 'db2.t2' doesn't exist
+# Cleanup
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+# Case 2
+# Connecting to master...
+# Perform backup
+BACKUP DATABASE db1 to 'db1.bak';
+backup_id
+#
+# Restore
+# Connecting to master...
+RESTORE FROM 'db1.bak' OVERWRITE;
+backup_id
+#
+# Incident event will cause replication to stop.
+SHOW SLAVE STATUS;;
+Slave_IO_State	#
+Master_Host	127.0.0.1
+Master_User	root
+Master_Port	MASTER_PORT
+Connect_Retry	1
+Master_Log_File	#
+Read_Master_Log_Pos	#
+Relay_Log_File	#
+Relay_Log_Pos	#
+Relay_Master_Log_File	master-bin.000002
+Slave_IO_Running	Yes
+Slave_SQL_Running	No
+Replicate_Do_DB	
+Replicate_Ignore_DB	
+Replicate_Do_Table	
+Replicate_Ignore_Table	
+Replicate_Wild_Do_Table	
+Replicate_Wild_Ignore_Table	
+Last_Errno	1590
+Last_Error	The incident RESTORE_ON_MASTER occured on the master. Message: A restore operation was initiated on the master.
+Skip_Counter	0
+Exec_Master_Log_Pos	#
+Relay_Log_Space	#
+Until_Condition	None
+Until_Log_File	
+Until_Log_Pos	0
+Master_SSL_Allowed	No
+Master_SSL_CA_File	
+Master_SSL_CA_Path	
+Master_SSL_Cert	
+Master_SSL_Cipher	
+Master_SSL_Key	
+Seconds_Behind_Master	#
+Master_SSL_Verify_Server_Cert	No
+Last_IO_Errno	0
+Last_IO_Error	
+Last_SQL_Errno	1590
+Last_SQL_Error	The incident RESTORE_ON_MASTER occured on the master. Message: A restore operation was initiated on the master.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
+# See for any error that has occured because of incident event
+Last_SQL_Error
+The incident RESTORE_ON_MASTER occured on the master. Message: A restore operation was initiated on the master.
+# Checking if replication is off 
+INSERT INTO db1.t1 VALUES(7,'pp'),(8,'kiy');
+INSERT INTO db2.t2 VALUES(7),(8);
+SELECT * from db1.t1;
+id	name
+1	jon
+2	jil
+3	jack
+4	ku
+5	pp
+6	kiy
+7	pp
+8	kiy
+SELECT * from db2.t2;
+id
+3
+4
+5
+6
+7
+8
+# Shouldn't include rows with keys 7 and 8
+SELECT * from db1.t1;
+id	name
+1	jon
+2	jil
+3	jack
+4	ku
+5	pp
+6	kiy
+SELECT * from db2.t2;
+ERROR 42S02: Table 'db2.t2' doesn't exist
+# Cleanup
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+DROP DATABASE db1;
+DROP DATABASE db2;
+# Connecting to slave...
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+DROP DATABASE db1;

=== added file 'mysql-test/suite/backup/t/backup_rpl_incident-master.opt'
--- a/mysql-test/suite/backup/t/backup_rpl_incident-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_rpl_incident-master.opt	2010-02-16 07:51:11 +0000
@@ -0,0 +1 @@
+--binlog-do-db=db1

=== added file 'mysql-test/suite/backup/t/backup_rpl_incident.test'
--- a/mysql-test/suite/backup/t/backup_rpl_incident.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_rpl_incident.test	2010-02-16 07:51:11 +0000
@@ -0,0 +1,180 @@
+--echo # Test cases for incident event with binlog filter is on.
+
+--source include/master-slave.inc
+--source include/not_embedded.inc
+--source include/have_debug.inc
+
+--echo #
+--echo # Bug #50678 Restore does not stop replication when server option --binlog-do-db is enabled.
+--echo #
+
+--echo # Following test cases uses two database db1 and db2.
+--echo # binlog filter is enabled so db1 is binlogged but db2 is not.
+
+CREATE DATABASE db1;
+CREATE DATABASE db2;
+
+--echo # Test Case Descriptions
+--echo # Case 1: db2 is backed up and restored. It should have no effect on replication.
+--echo # Case 2: db1 is backed up and restored. An incident event should be generated.
+
+--echo # Connecting to master...
+connection master;
+
+let $MYSQLD_BACKUPDIR= `select @@backupdir`;
+
+USE db1;
+CREATE TABLE t1(id INT NOT NULL PRIMARY KEY, name VARCHAR(10));
+CREATE TABLE t12(a CHAR(5));
+
+INSERT INTO t1 VALUES(1,'jon'),(2,'jil'),(3,'jack'),(4,'ku');
+
+USE db2;
+CREATE TABLE t2 (id INT);
+
+INSERT INTO t2 VALUES (3), (4);
+
+--echo # Remove all entries in the backup logs.
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+
+--echo # connecting to slave...
+sync_slave_with_master;
+
+connection slave;
+
+--echo # Check the server option --binlog-do-db=db1 works
+
+--echo # All 4 rows shows appear
+SELECT * FROM db1.t1;
+
+--echo # The selects from db2 will not work as they are ignored
+--echo # for replication
+--error ER_NO_SUCH_TABLE
+SELECT * FROM db2.t21;
+--error ER_NO_SUCH_TABLE
+SELECT * FROM db2.t22;
+
+--echo # Test Case 1
+
+--echo # connecting to master
+Connection master;
+
+--echo # Perform backup
+--replace_column 1 #
+BACKUP DATABASE db2 to 'db2.bak';
+
+--replace_column 1 #
+RESTORE FROM 'db2.bak' OVERWRITE;
+
+sync_slave_with_master;
+
+Connection slave;
+
+
+--replace_result $MASTER_MYPORT MASTER_PORT
+--replace_column 1 # 6 # 7 # 8 # 9 # 22 # 23 # 33 #
+--query_vertical SHOW SLAVE STATUS;
+
+--echo # See for any error that has occured because of incident event
+--echo # There shouldn't be any
+
+LET $last_error = query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+disable_query_log;
+eval SELECT "$last_error" AS Last_SQL_Error;
+enable_query_log;
+
+--echo # Conencting to master again to check replication is ON
+
+connection master;
+USE db1;
+INSERT INTO db1.t1 VALUES(5,'pp'),(6,'kiy');
+USE db2;
+INSERT INTO db2.t2 VALUES(5),(6);
+
+SELECT * FROM db1.t1;
+SELECT * FROM db2.t2;
+
+sync_slave_with_master;
+
+connection slave;
+--echo # All 6 rows shows appear
+SELECT * FROM db1.t1;
+--error ER_NO_SUCH_TABLE
+SELECT * FROM db2.t2;
+
+--echo # Cleanup
+#--remove_file LET $MYSQLD_BACKUPDIR/db2.bk;
+
+connection master;
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+connection slave;
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+
+
+--echo # Case 2
+
+--echo # Connecting to master...
+connection master;
+
+--echo # Perform backup
+--replace_column 1 #
+BACKUP DATABASE db1 to 'db1.bak';
+
+--echo # Restore
+
+--echo # Connecting to master...
+connection master;
+
+--replace_column 1 #
+RESTORE FROM 'db1.bak' OVERWRITE;
+
+Connection slave;
+
+--echo # Incident event will cause replication to stop.
+
+#--source include/wait_for_slave_to_stop.inc
+
+--replace_result $MASTER_MYPORT MASTER_PORT
+--replace_column 1 # 6 # 7 # 8 # 9 # 22 # 23 # 33 #
+--query_vertical SHOW SLAVE STATUS;
+
+--echo # See for any error that has occured because of incident event
+
+LET $last_error = query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+disable_query_log;
+eval SELECT "$last_error" AS Last_SQL_Error;
+enable_query_log;
+
+--echo # Checking if replication is off 
+connection master;
+
+INSERT INTO db1.t1 VALUES(7,'pp'),(8,'kiy');
+INSERT INTO db2.t2 VALUES(7),(8);
+SELECT * from db1.t1;
+SELECT * from db2.t2;
+
+connection slave;
+--echo # Shouldn't include rows with keys 7 and 8
+SELECT * from db1.t1;
+--error ER_NO_SUCH_TABLE
+SELECT * from db2.t2;
+
+--echo # Cleanup
+
+connection master;
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+DROP DATABASE db1;
+DROP DATABASE db2;
+
+--echo # Connecting to slave...
+connection slave;
+FLUSH BACKUP LOGS;
+PURGE BACKUP LOGS;
+DROP DATABASE db1;
+
+remove_file $MYSQLD_BACKUPDIR/db1.bak;
+remove_file $MYSQLD_BACKUPDIR/db2.bak;

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2010-02-11 14:04:43 +0000
+++ b/sql/backup/kernel.cc	2010-02-16 07:51:11 +0000
@@ -118,6 +118,7 @@
 #include "be_snapshot.h"
 #include "be_nodata.h"
 #include "transaction.h"
+#include "rpl_filter.h"
 
 
 /**
@@ -1033,9 +1034,28 @@ Backup_restore_ctx::prepare_for_restore(
     obs::disable_slave_connections(TRUE);
 
     DEBUG_SYNC(m_thd, "after_disable_slave_connections");
-
     if (!skip_gap_event)
+    {
+      Image_info::Db_iterator *dbit=info->get_dbs();
+      Image_info::Db *mydb;
+      /*
+        Unset default database.
+       */
+      m_thd->db=NULL;
+      while ((mydb=static_cast<Image_info::Db*> ((*dbit)++)))
+      {
+        if (binlog_filter->db_ok(mydb->name().ptr()))
+        {
+          /*
+            Found one binglogged database set it as default database
+            to ensure that the incident event raised gets binlogged
+           */
+          m_thd->db=my_strdup(mydb->name().ptr(), MYF(0));
+          break;
+        }
+      }
       obs::write_incident_event(m_thd, obs::RESTORE_EVENT);
+    }
     m_engage_binlog= TRUE;
     obs::engage_binlog(FALSE);
   }


Attachment: [text/bzr-bundle] bzr/anurag.shekhar@sun.com-20100216075111-74wqxfaiwu913gzy.bundle
Thread
bzr commit into mysql-5.5-next-mr-backup branch (anurag.shekhar:3096)Bug#50678Anurag Shekhar16 Feb
  • Re: bzr commit into mysql-5.5-next-mr-backup branch(anurag.shekhar:3096) Bug#50678Ingo Strüwing18 Feb
  • Re: bzr commit into mysql-5.5-next-mr-backup branch(anurag.shekhar:3096) Bug#50678Rafal Somla18 Feb
    • Re: bzr commit into mysql-5.5-next-mr-backup branch(anurag.shekhar:3096) Bug#50678Ingo Strüwing18 Feb
      • Re: bzr commit into mysql-5.5-next-mr-backup branch(anurag.shekhar:3096) Bug#50678Rafal Somla18 Feb