| 1 |
# WL#6404 - Add rewrite-db option to mysqlbinlog on RBR |
| 2 |
# |
| 3 |
# The test checks the new rewrite-db option for the mysqlbinlog. |
| 4 |
# |
| 5 |
# The test checks the following aspects of the new option: |
| 6 |
|
| 7 |
# 1. The valid syntax for the use of the new option and the errors in |
| 8 |
# case the usage is not correct. |
| 9 |
# 2. Apply the new binlog file ( with database rewritten ) to a new database |
| 10 |
# and check if it works. |
| 11 |
# |
| 12 |
# Bug26117735: MYSQLBINLOG READ-FROM-REMOTE-SERVER NOT HONORING REWRITE_DB |
| 13 |
# FILTERING |
| 14 |
# |
| 15 |
# Problem: |
| 16 |
# When running mysqlbinlog with the --read-from-remote-server option, |
| 17 |
# the processing of the binlog entries accepts rewrite_db as an argument, but |
| 18 |
# ignores the rewrite rule. Therefore no filtering is done on the binlog |
| 19 |
# entries, resulting in failures to write data in the target DB. |
| 20 |
# |
| 21 |
# Test case1: |
| 22 |
# Verify that rewrite_db filter works fine when reading binary log from remote |
| 23 |
# server. |
| 24 |
# |
| 25 |
# Test case2: |
| 26 |
# Verify that error scenario is handled properly in a case where rewrite_db |
| 27 |
# filter fails to rewrite the databases. |
| 28 |
# |
| 29 |
# mysqlbinlog should be debug compiled. |
| 30 |
--source include/mysqlbinlog_have_debug.inc |
| 31 |
--source include/have_binlog_format_row.inc |
| 32 |
|
| 33 |
RESET MASTER; |
| 34 |
CREATE DATABASE db1; |
| 35 |
USE db1; |
| 36 |
CREATE TABLE t1 (i INT); |
| 37 |
|
| 38 |
# Get some INSERT, UPDATE and DELETE ROW events. |
| 39 |
INSERT INTO t1 VALUES(1); |
| 40 |
INSERT INTO t1 VALUES(2); |
| 41 |
UPDATE t1 SET i= i+1; |
| 42 |
DELETE FROM t1 WHERE i=2; |
| 43 |
|
| 44 |
--let $MYSQLD_DATADIR= `select @@datadir` |
| 45 |
--exec $MYSQL_BINLOG --force-if-open $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/row_event.sql |
| 46 |
|
| 47 |
# Using the new option to apply the row event on some other database (from db1 -> new_db1 in the current case) |
| 48 |
|
| 49 |
--echo [Syntax error in the use of the new option: The from database name is missing] |
| 50 |
--error 1 |
| 51 |
--exec $MYSQL_BINLOG --force-if-open --rewrite-db="->new_db1" $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql |
| 52 |
|
| 53 |
--echo [Syntax error in the use of the new option: The '->' is missing] |
| 54 |
--error 1 |
| 55 |
--exec $MYSQL_BINLOG --force-if-open --rewrite-db="db1 new_db1" $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql |
| 56 |
|
| 57 |
--echo [Syntax error in the use of the new option: The to database name is missing] |
| 58 |
--error 1 |
| 59 |
--exec $MYSQL_BINLOG --force-if-open --rewrite-db="db1->" $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql |
| 60 |
|
| 61 |
--echo [VALID SYNTAX,The from->to database names is correctly mentioned] |
| 62 |
--exec $MYSQL_BINLOG --force-if-open --rewrite-db="db1->new_db1" $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql |
| 63 |
|
| 64 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 65 |
|
| 66 |
# Bug26117735: MYSQLBINLOG READ-FROM-REMOTE-SERVER NOT HONORING REWRITE_DB FILTERING |
| 67 |
--echo [VALID SYNTAX read from remote server ,The from->to database names are correctly mentioned] |
| 68 |
--exec $MYSQL_BINLOG --force-if-open --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --rewrite-db="db1->new_db1" $binlog_file > $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite.sql |
| 69 |
|
| 70 |
# BUG26878022: MYSQLBINLOG: ASSERTION `(OLD_MH->M_KEY == KEY) || (OLD_MH->M_KEY == 0)' FAILED |
| 71 |
--echo [VALID SYNTAX read from remote server in raw mode, the from->to database names are correctly mentioned] |
| 72 |
--exec $MYSQL_BINLOG --raw --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --rewrite-db="db1->new_db1" $binlog_file --result-file=$MYSQLTEST_VARDIR/tmp/ |
| 73 |
--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/tmp/$binlog_file > $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite_raw.sql |
| 74 |
|
| 75 |
--echo [VALID SYNTAX, but during the application of rewrite_db filter an invalid event is found. Hence mysqlbinlog tool should exit with an appropriate error] |
| 76 |
--echo [ERROR: Got fatal error while applying rewrite db filter.] |
| 77 |
--error 1 |
| 78 |
--exec $MYSQL_BINLOG --force-if-open -#d,'simulate_corrupt_event_len' --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --rewrite-db="db1->new_db1" $binlog_file > $MYSQLTEST_VARDIR/tmp/tmp.sql |
| 79 |
|
| 80 |
--echo #Dropping the database db1 and creating the table in the new database new_db1. |
| 81 |
|
| 82 |
CREATE DATABASE new_db1; |
| 83 |
DROP DATABASE db1; |
| 84 |
|
| 85 |
# The SQL file will be applied but nothing is applied on Database new_db1 since the row event was |
| 86 |
# generated for database db1 and table t1. |
| 87 |
|
| 88 |
# With gtid-mode=on we need purge gtid_executed, if not transactions |
| 89 |
# replayed through mysqlbinlog will be skipped. |
| 90 |
RESET MASTER; |
| 91 |
--exec $MYSQL --database=new_db1 --local-infile=1 < $MYSQLTEST_VARDIR/tmp/row_event.sql |
| 92 |
--error ER_NO_SUCH_TABLE |
| 93 |
SELECT * FROM new_db1.t1; |
| 94 |
|
| 95 |
# The SQL file should be applied since the row event was extracted using the new mysqlbinlog option. |
| 96 |
|
| 97 |
DROP DATABASE db1; |
| 98 |
# With gtid-mode=on we need purge gtid_executed, if not transactions |
| 99 |
# replayed through mysqlbinlog will be skipped. |
| 100 |
RESET MASTER; |
| 101 |
--echo [The event of table db1.t1 has been successfully applied to new_db1.t1] |
| 102 |
--exec $MYSQL --database=new_db1 --local-infile=1 < $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql |
| 103 |
--let $assert_text= Assert that table new_db1.t1 has one row after applying the sql file. |
| 104 |
--let $assert_cond= `SELECT COUNT(*)=1 from new_db1.t1` |
| 105 |
--source include/assert.inc |
| 106 |
|
| 107 |
DROP DATABASE db1; |
| 108 |
DROP DATABASE new_db1; |
| 109 |
CREATE DATABASE new_db1; |
| 110 |
# With gtid-mode=on we need purge gtid_executed, if not transactions |
| 111 |
# replayed through mysqlbinlog will be skipped. |
| 112 |
RESET MASTER; |
| 113 |
--echo [The event of table db1.t1 has been successfully applied to new_db1.t1] |
| 114 |
--exec $MYSQL --database=new_db1 --local-infile=1 < $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite.sql |
| 115 |
--let $assert_text= Assert that table new_db1.t1 has one row after applying the sql file. |
| 116 |
--let $assert_cond= `SELECT COUNT(*)=1 from new_db1.t1` |
| 117 |
--source include/assert.inc |
| 118 |
|
| 119 |
DROP DATABASE db1; |
| 120 |
DROP DATABASE new_db1; |
| 121 |
CREATE DATABASE new_db1; |
| 122 |
# With gtid-mode=on we need purge gtid_executed, if not transactions |
| 123 |
# replayed through mysqlbinlog will be skipped. |
| 124 |
RESET MASTER; |
| 125 |
--echo [The event of table db1.t1 has been successfully applied to new_db1.t1 from raw mode] |
| 126 |
--exec $MYSQL --database=new_db1 --local-infile=1 < $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite_raw.sql |
| 127 |
--let $assert_text= Assert that table new_db1.t1 has one row after applying the sql file from raw binlog dump. |
| 128 |
--let $assert_cond= `SELECT COUNT(*)=1 from new_db1.t1` |
| 129 |
--source include/assert.inc |
| 130 |
|
| 131 |
--echo CLEANUP |
| 132 |
|
| 133 |
--remove_file $MYSQLTEST_VARDIR/tmp/row_event.sql |
| 134 |
--remove_file $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql |
| 135 |
--remove_file $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite.sql |
| 136 |
--remove_file $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite_raw.sql |
| 137 |
--remove_file $MYSQLTEST_VARDIR/tmp/tmp.sql |
| 138 |
--remove_file $MYSQLTEST_VARDIR/tmp/$binlog_file |
| 139 |
DROP DATABASE db1; |
| 140 |
DROP DATABASE new_db1; |