summaryrefslogtreecommitdiff
path: root/mysql-test/suite/binlog/t/binlog_row_mysqlbinlog_db_filter.test
blob: 2e3e53b86f115f089db106842d668b4bde997be5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# BUG#42941: --database parameter to mysqlbinlog fails with RBR
#
# WHAT
# ====
#
#  This test aims at checking whether a rows log event is printed or
#  not when --database parameter is used to filter events from one
#  given database.
#
# HOW
# ===
#
#  The test is implemented as follows: 
#
#    i) Some operations are done in two different databases:
#       'test' and 'b42941';
#   ii) mysqlbinlog is used to dump the contents of the binlog file
#       filtering only events from 'b42941'. The result of the dump is
#       stored in a temporary file. (This is done with and without
#       --verbose/hexdump flag);
#  iii) The contents of the dump are loaded into a session variable;
#   iv) The variable contents are searched for 'test' and 'b42941';
#    v) Should 'test' be found, an ERROR is reported. Should 'b42941' be
#       absent, an ERROR is reported.

-- source include/have_log_bin.inc
-- source include/have_binlog_format_row.inc
-- source include/have_innodb.inc

RESET MASTER;
-- let $MYSQLD_DATADIR= `select @@datadir`

CREATE TABLE t1 (id int);
CREATE TABLE t2 (id int);
CREATE TABLE t3 (txt TEXT);
CREATE TABLE t4 (a int) ENGINE= InnoDB;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
INSERT INTO t2 VALUES (1);
INSERT INTO t2 VALUES (2);
INSERT INTO t1 VALUES (3);
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
-- eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/std_data/words.dat' INTO TABLE t3
INSERT INTO t1 VALUES (4);

CREATE DATABASE b42941;
use b42941;
CREATE TABLE t1 (id int);
CREATE TABLE t2 (id int);
CREATE TABLE t3 (txt TEXT);
CREATE TABLE t4 (a int) ENGINE= InnoDB;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
INSERT INTO t2 VALUES (1);
INSERT INTO t2 VALUES (2);
INSERT INTO t1 VALUES (3);
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
-- eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/std_data/words.dat' INTO TABLE t3
INSERT INTO t1 VALUES (4);

INSERT INTO test.t1 VALUES (5);

FLUSH LOGS;

UPDATE test.t1 t11, b42941.t1 t12 SET t11.id=10, t12.id=100;

BEGIN;
INSERT INTO test.t4 VALUES (1);
INSERT INTO b42941.t4 VALUES (1);
UPDATE test.t4 tn4, b42941.t4 tt4 SET tn4.a= 10, tt4.a= 100;
COMMIT;

FLUSH LOGS;

-- let $log_file1= $MYSQLD_DATADIR/master-bin.000001
-- let $log_file2= $MYSQLD_DATADIR/master-bin.000002
-- let $outfile= $MYSQLTEST_VARDIR/tmp/b42941-mysqlbinlog
-- let $cmd= $MYSQL_BINLOG

let $i= 3;
while($i)
{
  -- let $flags=--database=b42941

  # construct CLI for mysqlbinlog
  if($i==3)
  {
    -- let $flags= $flags --verbose --hexdump
  }

  if($i==2)
  {
    -- let $flags= $flags --verbose
  }

#  if($i==1)
#  {
    # do nothing $flags is already set as it should be
#  }

  # execute mysqlbinlog on the two available master binlog files
  -- exec $cmd $flags $log_file1 > $outfile.1
  -- exec $cmd $flags $log_file2 > $outfile.2

  # load outputs into a variable
  -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  -- eval SET @b42941_output.1= LOAD_FILE('$outfile.1')

  -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  -- eval SET @b42941_output.2= LOAD_FILE('$outfile.2')

  # remove unecessary files
  -- remove_file $outfile.1
  -- remove_file $outfile.2
  
  #
  # The two tests are canceled since we introduced the patch of bug#46998,  
  # which will make mydsqlbinlog output the 'BEGIN', 'COMMIT' and 'ROLLBACK' 
  # in regardless of database filtering
  #
  # assertion: events for database test are filtered
  #if (`SELECT INSTR(@b42941_output.1, 'test')`)
  #{
    #-- echo **** ERROR **** Database name 'test' FOUND in mysqlbinlog output ($flags $outfile.1).
  #}

  #if (`SELECT INSTR(@b42941_output.2, 'test')`)
  #{
    #-- echo **** ERROR **** Database name 'test' FOUND in mysqlbinlog output ($flags $outfile.2).
  #}

  # assertion: events for database b42941 are not filtered
  if (!`SELECT INSTR(@b42941_output.1, 'b42941')`)
  {
    -- echo **** ERROR **** Database name 'b42941' NOT FOUND in mysqlbinlog output ($flags $outfile.1).
  }

  if (!`SELECT INSTR(@b42941_output.2, 'b42941')`)
  {
    -- echo **** ERROR **** Database name 'b42941' NOT FOUND in mysqlbinlog output ($flags $outfile.2).
  }

  dec $i;
}

DROP DATABASE b42941;
use test;
DROP TABLE t1, t2, t3, t4;