Skip to content

Commit 1f0f447

Browse files
author
Sujatha Sivakumar
committed
Bug#26117735: MYSQLBINLOG READ-FROM-REMOTE-SERVER NOT
HONORING REWRITE_DB FILTERING Problem: ======= When running mysqlbinlog with the --read-from-remote-server option, the processing of the binlog entries accepts rewrite_db as an argument, but ignores the rewrite rule. Therefore no filtering is done on the binlog entries, resulting in failures to write data in the target DB. Analysis: ======== mysqlbinlog tool can read binary logs that are present locally or on a remote machine. At present rewrite filter is applied for binary logs that are read locally. This rewrite_db filter specific code is not invoked while dumping binary log from a remote machine. Hence the filtering is is not done on those binlog entries. Fix: === Invoke rewrite_db filter code while dumping remote log entries as well.
1 parent ff1ef50 commit 1f0f447

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

client/mysqlbinlog.cc

+12-3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ Query_log_event::rewrite_db_in_buffer(char **buf, ulong *event_len,
218218
char* ptr= *buf;
219219
uint sv_len= 0;
220220

221+
DBUG_EXECUTE_IF("simulate_corrupt_event_len", *event_len=0;);
221222
/* Error if the event content is too small */
222223
if (*event_len < (common_header_len + query_header_len))
223224
return true;
@@ -2532,7 +2533,8 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
25322533
char log_file_name[FN_REFLEN + 1];
25332534
Exit_status retval= OK_CONTINUE;
25342535
enum enum_server_command command= COM_END;
2535-
2536+
char *event_buf= NULL;
2537+
ulong event_len;
25362538
DBUG_ENTER("dump_remote_log_entries");
25372539

25382540
fname[0]= log_file_name[0]= 0;
@@ -2691,12 +2693,19 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
26912693
*/
26922694
if (type == binary_log::HEARTBEAT_LOG_EVENT)
26932695
continue;
2696+
event_buf= (char *) net->read_pos + 1;
2697+
event_len= len - 1;
2698+
if (rewrite_db_filter(&event_buf, &event_len, glob_description_event))
2699+
{
2700+
error("Got a fatal error while applying rewrite db filter.");
2701+
DBUG_RETURN(ERROR_STOP);
2702+
}
26942703

26952704
if (!raw_mode || (type == binary_log::ROTATE_EVENT) ||
26962705
(type == binary_log::FORMAT_DESCRIPTION_EVENT))
26972706
{
2698-
if (!(ev= Log_event::read_log_event((const char*) net->read_pos + 1 ,
2699-
len - 1, &error_msg,
2707+
if (!(ev= Log_event::read_log_event((const char*) event_buf,
2708+
event_len, &error_msg,
27002709
glob_description_event,
27012710
opt_verify_binlog_checksum)))
27022711
{

mysql-test/suite/binlog/r/binlog_mysqlbinlog_rewrite_db.result

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ DELETE FROM t1 WHERE i=2;
1010
[Syntax error in the use of the new option: The '->' is missing]
1111
[Syntax error in the use of the new option: The to database name is missing]
1212
[VALID SYNTAX,The from->to database names is correctly mentioned]
13+
[VALID SYNTAX read from remote server ,The from->to database names are correctly mentioned]
14+
[VALID SYNTAX, but during the application of rewrite_db filter an invalid event is found. Hence mysqlbinlog tool should exit with an appropriate error]
15+
[ERROR: Got fatal error while applying rewrite db filter.]
1316
#Dropping the database db1 and creating the table in the new database db2.
1417
CREATE DATABASE db2;
1518
DROP DATABASE db1;
@@ -20,6 +23,12 @@ DROP DATABASE db1;
2023
RESET MASTER;
2124
[The event of table db1.t1 has been successfully applied to db2.t1]
2225
include/assert.inc [Assert that table db2.t1 has one row after applying the sql file.]
26+
DROP DATABASE db1;
27+
DROP DATABASE db2;
28+
CREATE DATABASE db2;
29+
RESET MASTER;
30+
[The event of table db1.t1 has been successfully applied to db2.t1]
31+
include/assert.inc [Assert that table db2.t1 has one row after applying the sql file.]
2332
CLEANUP
2433
DROP DATABASE db1;
2534
DROP DATABASE db2;

mysql-test/suite/binlog/t/binlog_mysqlbinlog_rewrite_db.test

+44
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
# 2. Apply the new binlog file ( with database rewritten ) to a new database
1010
# and check if it works.
1111
#
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
1231
--source include/have_binlog_format_row.inc
1332

1433
RESET MASTER;
@@ -42,6 +61,17 @@ DELETE FROM t1 WHERE i=2;
4261
--echo [VALID SYNTAX,The from->to database names is correctly mentioned]
4362
--exec $MYSQL_BINLOG --force-if-open --rewrite-db="db1->db2" $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql
4463

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->db2" $binlog_file > $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite.sql
69+
70+
--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]
71+
--echo [ERROR: Got fatal error while applying rewrite db filter.]
72+
--error 1
73+
--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->db2" $binlog_file > $MYSQLTEST_VARDIR/tmp/tmp.sql
74+
4575
--echo #Dropping the database db1 and creating the table in the new database db2.
4676

4777
CREATE DATABASE db2;
@@ -69,9 +99,23 @@ RESET MASTER;
6999
--let $assert_cond= `SELECT COUNT(*)=1 from db2.t1`
70100
--source include/assert.inc
71101

102+
DROP DATABASE db1;
103+
DROP DATABASE db2;
104+
CREATE DATABASE db2;
105+
# With gtid-mode=on we need purge gtid_executed, if not transactions
106+
# replayed through mysqlbinlog will be skipped.
107+
RESET MASTER;
108+
--echo [The event of table db1.t1 has been successfully applied to db2.t1]
109+
--exec $MYSQL --database=db2 --local-infile=1 < $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite.sql
110+
--let $assert_text= Assert that table db2.t1 has one row after applying the sql file.
111+
--let $assert_cond= `SELECT COUNT(*)=1 from db2.t1`
112+
--source include/assert.inc
113+
72114
--echo CLEANUP
73115

74116
--remove_file $MYSQLTEST_VARDIR/tmp/row_event.sql
75117
--remove_file $MYSQLTEST_VARDIR/tmp/row_event_rewrite.sql
118+
--remove_file $MYSQLTEST_VARDIR/tmp/row_event_from_remote_server_rewrite.sql
119+
--remove_file $MYSQLTEST_VARDIR/tmp/tmp.sql
76120
DROP DATABASE db1;
77121
DROP DATABASE db2;

0 commit comments

Comments
 (0)