Debian Codegraph @

mysql-test/suite/rpl/t/rpl_stm_until.test

raw
1 # ==== Purpose ====
2 #
3 # Verify that START SLAVE UNTIL replicates until the given binlog
4 # position but not longer. Verify that START SLAVE UNTIL with various
5 # incorrect arguments gives an error.
6 #
7 # ==== Method ====
8 #
9 # On master, create a table and insert some rows. On slave, START
10 # SLAVE UNTIL so that it reads one event at a time, and check the
11 # table and the slave status each time.
12 #
13 # Then, on slave, run START SLAVE UNTIL with incorrect arguments and
14 # verify that it gives an error.
15 #
16 # ==== Related bugs ====
17 #
18 # Bug in this test: BUG#37717: rpl.rpl_stm_until 'stmt' fails sporadically on pushbuild
19
20 -- source include/have_binlog_format_mixed_or_statement.inc
21 -- source include/master-slave.inc
22 --let $master_use_gtid_option= No
23 -- source include/rpl_reset.inc
24
25 # Test is dependent on binlog positions
26 call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
27
28 # prepare version for substitutions
29 let $VERSION=`select version()`;
30
31 # Stop slave before it starts replication. Also sync with master
32 # to avoid nondeterministic behaviour.
33 sync_slave_with_master;
34 --source include/stop_slave.inc
35
36 --echo ==== Create some events on master ====
37
38 connection master;
39 create table t1(n int not null auto_increment primary key);
40 insert into t1 values (1),(2),(3),(4);
41 let $master_log_pos_1= query_get_value(SHOW MASTER STATUS, Position, 1);
42 let $master_log_file= query_get_value(SHOW MASTER STATUS, File, 1);
43 drop table t1;
44 create table t2(n int not null auto_increment primary key);
45 insert into t2 values (1),(2);
46 let $master_log_pos_2= query_get_value(SHOW MASTER STATUS, Position, 1);
47 insert into t2 values (3),(4);
48 drop table t2;
49
50 --echo ==== Replicate one event at a time on slave ====
51
52 # try to replicate all queries until drop of t1
53 connection slave;
54 --replace_result $master_log_file MASTER_LOG_FILE $master_log_pos_1 MASTER_LOG_POS
55 eval start slave until master_log_file='$master_log_file', master_log_pos=$master_log_pos_1;
56 --source include/wait_for_slave_io_to_start.inc
57 --source include/wait_for_slave_sql_to_stop.inc
58 # here table should be still not deleted
59 select * from t1;
60 --let $slave_param= Exec_Master_Log_Pos
61 --let $slave_param_value= $master_log_pos_1
62 --source include/check_slave_param.inc
63
64 # this should fail right after start
65 start slave until master_log_file='master-no-such-bin.000001', master_log_pos=291;
66 --source include/wait_for_slave_io_to_start.inc
67 --source include/wait_for_slave_sql_to_stop.inc
68 # again this table should be still not deleted
69 select * from t1;
70 --let $slave_param= Exec_Master_Log_Pos
71 --let $slave_param_value= $master_log_pos_1
72 --source include/check_slave_param.inc
73
74 let $relay_log_file= slave-relay-bin.000003;
75 let $master_log_pos= $master_log_pos_2;
76 source include/get_relay_log_pos.inc;
77 # try replicate all up to and not including the second insert to t2;
78 --replace_result $relay_log_pos RELAY_LOG_POS
79 eval start slave until relay_log_file='$relay_log_file', relay_log_pos=$relay_log_pos;
80 --source include/wait_for_slave_io_to_start.inc
81 --source include/wait_for_slave_sql_to_stop.inc
82 select * from t2;
83 --let $slave_param= Exec_Master_Log_Pos
84 --let $slave_param_value= $master_log_pos
85 --source include/check_slave_param.inc
86
87 # clean up
88 start slave;
89 connection master;
90 sync_slave_with_master;
91 --source include/stop_slave.inc
92
93 --let $exec_log_pos_1= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1)
94 # this should stop immediately as we are already there
95 --replace_result $master_log_file MASTER_LOG_FILE $master_log_pos_2 MASTER_LOG_POS
96 eval start slave until master_log_file='$master_log_file', master_log_pos=$master_log_pos_2;
97 --source include/wait_for_slave_io_to_start.inc
98 --source include/wait_for_slave_sql_to_stop.inc
99 --let $slave_param= Exec_Master_Log_Pos
100 --let $slave_param_value= $exec_log_pos_1
101 --source include/check_slave_param.inc
102
103 --echo ==== Test various error conditions ====
104
105 --error 1277
106 start slave until master_log_file='master-bin', master_log_pos=561;
107 --error 1277
108 start slave until master_log_file='master-bin.000001', master_log_pos=561, relay_log_pos=12;
109 --error 1277
110 start slave until master_log_file='master-bin.000001';
111 --error 1277
112 start slave until relay_log_file='slave-relay-bin.000002';
113 --error 1277
114 start slave until relay_log_file='slave-relay-bin.000002', master_log_pos=561;
115 # Warning should be given for second command
116 start slave sql_thread;
117 start slave until master_log_file='master-bin.000001', master_log_pos=776;
118
119 #
120 # bug#47210 first execution of "start slave until" stops too early
121 #
122 # testing that a slave rotate event that is caused by stopping the slave
123 # does not intervene anymore in UNTIL condition.
124 #
125
126 connection slave;
127 source include/stop_slave.inc;
128 --disable_warnings
129 drop table if exists t1;
130 --enable_warnings
131 --source include/reset_slave.inc
132 --replace_result $MASTER_MYPORT MASTER_PORT
133 eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
134
135 connection master;
136 --disable_warnings
137 drop table if exists t1;
138 --enable_warnings
139 reset master;
140 create table t1 (a int primary key auto_increment);
141 save_master_pos;
142 let $master_pos= query_get_value(SHOW MASTER STATUS, Position, 1);
143
144 connection slave;
145 start slave;
146 sync_with_master;
147
148 # at this point slave will close the relay log stamping it with its own
149 # Rotate log event. This event won't be examined on matter of the master
150 # UNTIL pos anymore.
151 source include/stop_slave.inc;
152 let $slave_exec_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1);
153
154 --echo master and slave are in sync now
155 let $diff_pos= `select $master_pos - $slave_exec_pos`;
156 eval select $diff_pos as zero;
157
158 connection master;
159 insert into t1 set a=null;
160 let $until_pos= query_get_value(SHOW MASTER STATUS, Position, 1);
161 insert into t1 set a=null;
162 select count(*) as two from t1;
163
164 connection slave;
165 --replace_result $master_log_file MASTER_LOG_FILE $until_pos UNTIL_POS;
166 eval start slave until master_log_file='$master_log_file', master_log_pos= $until_pos;
167 source include/wait_for_slave_sql_to_stop.inc;
168 let $slave_exec_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1);
169 --echo slave stopped at the prescribed position
170 let $diff_pos= `select $until_pos - $slave_exec_pos`;
171 eval select $diff_pos as zero;
172 select count(*) as one from t1;
173
174
175 connection master;
176 drop table t1;
177
178 connection slave;
179 start slave;
180 sync_with_master;
181
182 # End of tests
183 --let $rpl_only_running_threads= 1
184 --source include/rpl_end.inc