#At file:///home/anurag/mysqlsrc/mysql-next-mr-backup/ based on revid:charles.bell@stripped
3101 Anurag Shekhar 2010-02-19
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 binlogged, and unset the default
database (by setting it to NULL) if none of the database
is binlogged.
@ mysql-test/suite/binlog/r/binlog_backup_incident.result
Result file for newly added test case.
@ mysql-test/suite/binlog/t/binlog_backup_incident-master.opt
Option file to set binlog filtering for test case.
@ mysql-test/suite/binlog/t/binlog_backup_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/binlog/r/binlog_backup_incident.result
mysql-test/suite/binlog/t/binlog_backup_incident-master.opt
mysql-test/suite/binlog/t/binlog_backup_incident.test
modified:
sql/backup/kernel.cc
=== added file 'mysql-test/suite/binlog/r/binlog_backup_incident.result'
--- a/mysql-test/suite/binlog/r/binlog_backup_incident.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_backup_incident.result 2010-02-19 15:29:13 +0000
@@ -0,0 +1,113 @@
+# Test cases for incident event with binlog filter is on.
+#
+# 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;
+CREATE TABLE db1.t1 (i INTEGER);
+CREATE TABLE db2.t1 (i INTEGER);
+# Check if db1 is being binlogged
+USE db1;
+# Remember binlog position and log file
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+# Limiting output to 3 rows to avoid failure in
+# different binlog modes
+SHOW BINLOG EVENTS IN '<binlog_file>' FROM <start_pos> LIMIT 3;
+Log_name Pos Event_type Server_id End_log_pos Info
+<binlog_file> # # # # #
+<binlog_file> # # # # #
+<binlog_file> # # # # #
+# Ensure db2 is not binlogged
+USE db2;
+# Remember binlog position and log file
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+SHOW BINLOG EVENTS IN '<binlog_file>' FROM <start_pos>;
+Log_name Pos Event_type Server_id End_log_pos Info
+# Take backup of all combination to use latter
+# Backup of db1
+BACKUP DATABASE db1 TO 'db1.bk';
+backup_id
+#
+# Backup of db2
+BACKUP DATABASE db2 TO 'db2.bk';
+backup_id
+#
+# Backup of both db1 and db2
+BACKUP DATABASE db1, db2 TO 'db1-db2.bk';
+backup_id
+#
+# Restore operations from non binlogged database
+# Remember binlog position and log file
+# to check events logged after this position
+# Restore db2
+RESTORE FROM 'db2.bk' OVERWRITE;
+backup_id
+#
+# There shouldn't be any binlogged event
+SHOW BINLOG EVENTS IN '<binlog_file>' FROM <start_pos>;
+Log_name Pos Event_type Server_id End_log_pos Info
+<binlog_file> # Rotate # # master-bin.000002;pos=4
+USE db2;
+# Restore might have caused a binlog rotation
+# Remember binlog position and log file
+# Restore db1
+RESTORE FROM 'db1.bk' OVERWRITE;
+backup_id
+#
+# There should be an incident event
+SHOW BINLOG EVENTS IN '<binlog_file>' FROM <start_pos>;
+Log_name Pos Event_type Server_id End_log_pos Info
+<binlog_file> # Incident # # #2 (RESTORE_ON_MASTER)
+<binlog_file> # Rotate # # master-bin.000003;pos=4
+USE db2;
+# Restore might have caused a binlog rotation
+# Remember binlog position and log file
+# Restore both db1 and db2
+RESTORE FROM 'db1-db2.bk' OVERWRITE;
+backup_id
+#
+# There should be an incident event
+SHOW BINLOG EVENTS IN '<binlog_file>' FROM <start_pos>;
+Log_name Pos Event_type Server_id End_log_pos Info
+<binlog_file> # Incident # # #2 (RESTORE_ON_MASTER)
+<binlog_file> # Rotate # # master-bin.000004;pos=4
+# Try restores from binlogged database
+USE db1;
+# Remember binlog position and log file
+# Restore db2
+RESTORE FROM 'db2.bk' OVERWRITE;
+backup_id
+#
+# There shouldn't be an incident event
+Log_name Pos Event_type Server_id End_log_pos Info
+<binlog_file> # Rotate # # master-bin.000005;pos=4
+USE db1;
+# Restore might have caused a binlog rotation
+# Remember binlog position and log file
+# Restore db1
+RESTORE FROM 'db1.bk' OVERWRITE;
+backup_id
+#
+# There should be an incident event
+SHOW BINLOG EVENTS IN '<binlog_file>' FROM <start_pos>;
+Log_name Pos Event_type Server_id End_log_pos Info
+<binlog_file> # Incident # # #2 (RESTORE_ON_MASTER)
+<binlog_file> # Rotate # # master-bin.000006;pos=4
+USE db1;
+# Restore might have caused a binlog rotation
+# Remember binlog position and log file
+# Restore both db1 and db2
+backup_id
+#
+# There should be an incident event
+SHOW BINLOG EVENTS IN '<binlog_file>' FROM <start_pos>;
+Log_name Pos Event_type Server_id End_log_pos Info
+<binlog_file> # Incident # # #2 (RESTORE_ON_MASTER)
+<binlog_file> # Rotate # # master-bin.000007;pos=4
+# Clean-up
+DROP DATABASE db1;
+DROP DATABASE db2;
=== added file 'mysql-test/suite/binlog/t/binlog_backup_incident-master.opt'
--- a/mysql-test/suite/binlog/t/binlog_backup_incident-master.opt 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_backup_incident-master.opt 2010-02-19 15:29:13 +0000
@@ -0,0 +1 @@
+--binlog-do-db=db1
=== added file 'mysql-test/suite/binlog/t/binlog_backup_incident.test'
--- a/mysql-test/suite/binlog/t/binlog_backup_incident.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_backup_incident.test 2010-02-19 15:29:13 +0000
@@ -0,0 +1,173 @@
+--echo # Test cases for incident event with binlog filter is on.
+
+--source include/have_log_bin.inc
+--source include/not_embedded.inc
+--source include/have_debug.inc
+
+--echo #
+--echo # Bug #50678 Restore does not stop replication when server
+--echo # 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.
+--echo #
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+CREATE DATABASE db1;
+CREATE DATABASE db2;
+
+CREATE TABLE db1.t1 (i INTEGER);
+CREATE TABLE db2.t1 (i INTEGER);
+
+--echo # Check if db1 is being binlogged
+
+USE db1;
+
+--echo # Remember binlog position and log file
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+
+--echo # Limiting output to 3 rows to avoid failure in
+--echo # different binlog modes
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 3 # 4 # 5 # 6 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos LIMIT 3;
+
+--echo # Ensure db2 is not binlogged
+
+USE db2;
+
+--echo # Remember binlog position and log file
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 4 # 5 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos;
+
+--echo # Take backup of all combination to use latter
+
+--echo # Backup of db1
+--replace_column 1 #
+BACKUP DATABASE db1 TO 'db1.bk';
+
+--echo # Backup of db2
+--replace_column 1 #
+BACKUP DATABASE db2 TO 'db2.bk';
+
+--echo # Backup of both db1 and db2
+--replace_column 1 #
+BACKUP DATABASE db1, db2 TO 'db1-db2.bk';
+
+--echo # Restore operations from non binlogged database
+
+--echo # Remember binlog position and log file
+--echo # to check events logged after this position
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+--echo # Restore db2
+--replace_column 1 #
+RESTORE FROM 'db2.bk' OVERWRITE;
+
+--echo # There shouldn't be any binlogged event
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 4 # 5 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos;
+
+USE db2;
+
+--echo # Restore might have caused a binlog rotation
+--echo # Remember binlog position and log file
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+--echo # Restore db1
+--replace_column 1 #
+RESTORE FROM 'db1.bk' OVERWRITE;
+
+--echo # There should be an incident event
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 4 # 5 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos;
+
+USE db2;
+
+--echo # Restore might have caused a binlog rotation
+--echo # Remember binlog position and log file
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+--echo # Restore both db1 and db2
+--replace_column 1 #
+RESTORE FROM 'db1-db2.bk' OVERWRITE;
+
+--echo # There should be an incident event
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 4 # 5 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos;
+
+--echo # Try restores from binlogged database
+USE db1;
+
+--echo # Remember binlog position and log file
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+--echo # Restore db2
+--replace_column 1 #
+RESTORE FROM 'db2.bk' OVERWRITE;
+
+--echo # There shouldn't be an incident event
+--disable_query_log
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 4 # 5 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos;
+--enable_query_log
+
+USE db1;
+
+--echo # Restore might have caused a binlog rotation
+--echo # Remember binlog position and log file
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+--echo # Restore db1
+--replace_column 1 #
+RESTORE FROM 'db1.bk' OVERWRITE;
+
+--echo # There should be an incident event
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 4 # 5 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos;
+
+USE db1;
+
+--echo # Restore might have caused a binlog rotation
+--echo # Remember binlog position and log file
+let $pos = query_get_value("SHOW MASTER STATUS", Position, 1);
+let $file = query_get_value("SHOW MASTER STATUS", File, 1);
+
+--echo # Restore both db1 and db2
+--disable_query_log
+--replace_column 1 #
+RESTORE FROM 'db1-db2.bk' OVERWRITE;
+--enable_query_log
+
+--echo # There should be an incident event
+--replace_result $file <binlog_file> $pos <start_pos>
+--replace_column 2 # 4 # 5 #
+eval SHOW BINLOG EVENTS IN '$file' FROM $pos;
+
+--echo # Clean-up
+DROP DATABASE db1;
+DROP DATABASE db2;
+
+remove_file $MYSQLD_DATADIR/db1.bk;
+remove_file $MYSQLD_DATADIR/db2.bk;
+remove_file $MYSQLD_DATADIR/db1-db2.bk;
=== 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-19 15:29:13 +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->set_db(NULL, 0);
+ 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->set_db(mydb->name().ptr(), mydb->name().length());
+ 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-20100219152913-xsj05obur2ffghxd.bundle
Thread |
---|
• bzr commit into mysql-next-mr-backup branch (anurag.shekhar:3101)Bug#50678 | Anurag Shekhar | 19 Feb |