Debian Codegraph @

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

raw
1 # WL#6404 - Add rewrite-db option to mysqlbinlog on RBR
2 #
3 # The test checks that there is no leak of the global variables used
4 # to decide whether rewrite-db option is ON or OFF.
5 #
6 # The test checks this by creating two tables in two different databases.
7 # insert rows in both of them.
8 #
9 # Read the binlog file using the new option --rewrite-db="db1->db3" and
10 # writing in the .sql file.
11 #
12 # On applying the .sql file on database db3, we get an error since not
13 # all events are converted for database db3. Only DB1 is converted to db3.
14 # The db2 event cause the error.
15 #
16
17 --source include/have_binlog_format_row.inc
18 RESET MASTER;
19 CREATE DATABASE db1;
20 USE db1;
21 CREATE TABLE t1 (i INT);
22
23 # Get some INSERT, UPDATE and DELETE ROW events.
24 INSERT INTO db1.t1 VALUES(1);
25 INSERT INTO db1.t1 VALUES(2);
26 UPDATE t1 SET i= i+1;
27 DELETE FROM t1 WHERE i=2;
28
29 CREATE DATABASE db2;
30 CREATE TABLE db2.t1 (i INT);
31
32 # Get some INSERT, UPDATE and DELETE ROW events.
33 INSERT INTO db2.t1 VALUES(3);
34 INSERT INTO db2.t1 VALUES(4);
35 INSERT INTO db2.t1 VALUES(5);
36 UPDATE db2.t1 SET i= i+1;
37 DELETE FROM db2.t1 WHERE i=4;
38
39 --let $MYSQLD_DATADIR= `select @@datadir`
40
41 # Using the new option to apply the row event on some other database (from db1 -> db3 in the current case)
42
43 --exec $MYSQL_BINLOG --force-if-open --rewrite-db="db1->db3" $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/rewrite_noleak.sql
44 call mtr.add_suppression("Replica SQL: Error executing row event:*");
45
46 --echo Dropping the database db1 creating the new database db3.
47 DROP DATABASE db1;
48 CREATE DATABASE db3;
49
50 # The SQL file will be applied but only db1 events will be replayed on db3.
51 # Database db2 will not be applied on db3 confirming there is no leak.
52 DROP DATABASE db2;
53
54 # With gtid-mode=on we need purge gtid_executed, if not transactions
55 # replayed through mysqlbinlog will be skipped.
56 RESET MASTER;
57 --echo [The sql file will be applied on the current database]
58 --exec $MYSQL --database=db3 --local-infile=1 < $MYSQLTEST_VARDIR/tmp/rewrite_noleak.sql
59
60 --echo [The content of table db3.t1 and db2.t1 will be different confirming no leak]
61
62 --let $db3_max= `SELECT MAX(i) FROM db3.t1`
63 --let $db2_max= `SELECT MAX(i) FROM db2.t1`
64 --let $assert_text= The content of the table t1 in database db3 and db2 is different
65 --let $assert_cond= $db3_max <> $db2_max
66 --source include/assert.inc
67
68 --let $db3_count= `SELECT COUNT(*) FROM db3.t1`
69 --let $db2_count= `SELECT COUNT(*) FROM db2.t1`
70 --let $assert_text= Table t1 in db3 have different row count than t1 in db2
71 --let $assert_cond= $db3_count=1 AND $db2_count<>1
72 --source include/assert.inc
73
74 --echo CLEANUP
75
76 --remove_file $MYSQLTEST_VARDIR/tmp/rewrite_noleak.sql
77 DROP DATABASE db1;
78 DROP DATABASE db2;
79 DROP DATABASE db3;