Debian Codegraph @

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

raw
1 --source include/have_debug.inc
2
3 # make the test only run once (STMT is actually needed because we rely
4 # on SHOW PROCESS LIST output in some of the tests)
5 --source include/have_binlog_format_statement.inc
6
7 --source include/master-slave.inc
8
9 call mtr.add_suppression('Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT');
10
11 #
12 # BUG#29309 test case
13 #
14 # What to test?
15 #
16 # We want to check that issuing FLUSH LOGS on the slave does not cause
17 # transient, incorrect calculation of Seconds_Behind_Master while SQL
18 # thread is executing an event.
19 #
20 # How to test?
21 #
22 # 1. let slave start 3 seconds after an insert on table t1 is issued
23 # on the master
24 # 2. while locking t1 for write (SQL thread is on-hold) assert that
25 # slave is 3 seconds behind the master
26 # 3. sleep 3 more seconds
27 # 4. repeat step #2, but before checking Seconds_Behind_Master, issue
28 # a FLUSH LOGS.
29 # 5. assert that Seconds_Behind_Master is within the expected time window
30
31 connection master;
32 create table t1 (f1 int);
33 --source include/sync_slave_sql_with_master.inc
34 source include/stop_slave.inc;
35 connection master;
36 let $start= `SELECT UNIX_TIMESTAMP()`;
37 insert into t1 values (1);
38 let $stop_exec= `SELECT UNIX_TIMESTAMP()`;
39
40 sleep 3;
41
42 connection slave;
43 lock table t1 write;
44 source include/start_slave.inc;
45
46 # ok, now wait for the SQL thread to start the insert
47 let $wait_timeout= 60; # Override default of 30 seconds with 60.
48 let $show_statement= SHOW PROCESSLIST;
49 let $field= Info;
50 let $condition= = 'insert into t1 values (1)';
51 source include/wait_show_condition.inc;
52
53 # While the SQL thread executes an event, the following should hold:
54 # Seconds_Behind_Master = NOW - the event timestamp set by the master
55 # (for query log events it's event creation time + exec_time).
56 #
57 # ASSERTION: check that SBM shows at least 3 seconds
58
59 let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1);
60 # We need to deduct execution time on master to SBM lower_bound.
61 # SBM= now - (ev.when + ev.exec_time)
62 # Also deduct a second to handle rounding differences.
63 let $lower_bound= `SELECT 3 - ($stop_exec - $start) - 1`;
64 let $stop= `SELECT UNIX_TIMESTAMP()`;
65 let $upper_bound= `SELECT $stop - $start`;
66 let $assert_text= Seconds_Behind_Master must be between 'lower_bound' and 'upper_bound';
67 let $assert_cond= $lower_bound <= $sbm AND $sbm <= $upper_bound;
68 source include/assert.inc;
69
70 unlock tables;
71 connection master;
72 --source include/sync_slave_sql_with_master.inc
73 lock table t1 write;
74 connection master;
75 let $start= `SELECT UNIX_TIMESTAMP()`;
76 insert into t1 values (2);
77 let $stop_exec= `SELECT UNIX_TIMESTAMP()`;
78
79 sleep 3;
80
81 connection slave;
82 # ok, now wait for the SQL thread to start the insert
83 let $wait_timeout= 60; # Override default of 30 seconds with 60.
84 let $show_statement= SHOW PROCESSLIST;
85 let $field= Info;
86 let $condition= = 'insert into t1 values (2)';
87 source include/wait_show_condition.inc;
88
89 # If FLUSH LOGS is executed while the slave is executing an event, it
90 # should not affect Seconds_Behind_Master.
91 #
92 # ASSERTION: flush logs will not reset the sbm value
93 flush logs;
94
95 sleep 3;
96
97 let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1);
98 # We need to deduct execution time on master to SBM lower_bound.
99 # SBM= now - (ev.when + ev.exec_time)
100 # Also deduct a second to handle rounding differences.
101 let $lower_bound= `SELECT 6 - ($stop_exec - $start) - 1`;
102 let $stop= `SELECT UNIX_TIMESTAMP()`;
103 let $upper_bound= `SELECT $stop - $start`;
104 let $assert_text= Seconds_Behind_Master must be between 'lower_bound' and 'upper_bound';
105 let $assert_cond= $lower_bound <= $sbm AND $sbm <= $upper_bound;
106 source include/assert.inc;
107
108 unlock tables;
109 connection master;
110 drop table t1;
111 --source include/sync_slave_sql_with_master.inc
112
113 #
114 # BUG#52166 test case
115 #
116 # What to test?
117 #
118 # We want to test that Seconds_Behind_Master does not spike when SQL
119 # thread awakes to process a newly arrived event (queued by IO
120 # thread). Additionally, we want to assert that while SQL thread is
121 # waiting Seconds_Behind_Master will show zero.
122 #
123 # How to test?
124 #
125 # 1. Check that seconds behind master is set to 0 when SQL thread
126 # waits for more events. We do this by first waiting for process
127 # list to show SQL thread is indeed waiting and then inspect
128 # Seconds_Behind_Master value.
129 #
130 # 2. Check that seconds behind master is updated once after a newly
131 # received event starts to be processed. We do this by putting SQL
132 # thread on hold by locking explicitly table t1. We then wait for
133 # process list to show that SQL thread started processing the
134 # desired query. At that time we inspect the Seconds_Behind_Master
135 # and assert that it is in the desired time window.
136
137 -- source include/rpl_reset.inc
138 -- connection master
139
140 # this will increase the timestamp +3600, so it becomes
141 # clear at the slave that it must show 0 and not 3600
142 --let $debug_point= dec_event_time_by_1_hour
143 --source include/add_debug_point.inc
144 CREATE TABLE t1 (a INT);
145 --source include/sync_slave_sql_with_master.inc
146
147 # ok, now wait for the SQL thread to sleep
148 let $wait_timeout= 60; # Override default of 30 seconds with 60.
149 let $show_statement= SHOW PROCESSLIST;
150 let $field= State;
151 let $condition= = 'Replica has read all relay log; waiting for more updates';
152 -- source include/wait_show_condition.inc
153
154 -- let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1)
155 let $assert_text= Seconds_Behind_Master must be 0;
156 let $assert_cond= $sbm = 0;
157 source include/assert.inc;
158
159 -- connection slave
160 LOCK TABLE t1 WRITE;
161
162 -- connection master
163
164 # Now we will be testing that seconds behind master
165 # is set correctly once the event is dequeued and is executing.
166 # To achieve this goal we will make the event timestamp
167 # to be shifted 3600 seconds (so that time difference
168 # becomes clear).
169 #
170 # 10 seconds, this will give us time at the slave to
171 # show that Seconds_Behind_Master will increase when
172 # this query starts to execute.
173 #
174 let $start= `SELECT UNIX_TIMESTAMP()`;
175 -- disable_warnings
176 INSERT INTO t1 VALUES (3);
177 -- enable_warnings
178 let $stop_exec= `SELECT UNIX_TIMESTAMP()`;
179
180 -- connection slave
181
182 # ok, now wait for the SQL thread to start the insert
183 let $wait_timeout= 60; # Override default of 30 seconds with 60.
184 let $show_statement= SHOW PROCESSLIST;
185 let $field= Info;
186 let $condition= = 'INSERT INTO t1 VALUES (3)';
187 -- source include/wait_show_condition.inc
188
189 -- let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1)
190 # We need to deduct execution time on master to SBM lower_bound.
191 # SBM= now - (ev.when + ev.exec_time)
192 # Also deduct 5 seconds to have a safety margin.
193 let $lower_bound= `SELECT 3600 - ($stop_exec - $start) - 5`;
194 let $assert_text= Seconds_Behind_Master must be greater or equal than 'lower_bound';
195 let $assert_cond= $lower_bound <= $sbm;
196 source include/assert.inc;
197
198 UNLOCK TABLES;
199
200 -- connection master
201 --let $debug_point= dec_event_time_by_1_hour
202 --source include/remove_debug_point.inc
203 --source include/sync_slave_sql_with_master.inc
204
205
206 # Check that Seconds_behind_master is greater than or equal to the delay when
207 # the slave has not yet applied the event
208
209 --let $delay= 10
210 --source include/stop_slave.inc
211 --eval CHANGE REPLICATION SOURCE TO SOURCE_DELAY= $delay
212
213 --source include/rpl_connection_master.inc
214 --let $start= `SELECT UNIX_TIMESTAMP()`
215 INSERT INTO t1 VALUES (47);
216 --let $stop_exec= `SELECT UNIX_TIMESTAMP()`
217
218 --source include/rpl_connection_slave.inc
219 LOCK TABLE t1 WRITE;
220 --source include/start_slave.inc
221
222 # now wait for the SQL thread to start the insert
223 # override default wait_timeout of 30 seconds with 60.
224 --let $wait_timeout= 60
225 --let $show_statement= SHOW PROCESSLIST
226 --let $field= Info
227 --let $condition= = 'INSERT INTO t1 VALUES (47)'
228 --source include/wait_show_condition.inc
229
230 # While the SQL thread executes an event, the following should hold:
231 # Seconds_Behind_Master = NOW - the event timestamp set by the master
232 # (for query log events it's event creation time + exec_time).
233 #
234 # ASSERTION: check that SBM shows at least the delay
235
236 --let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1)
237 # We need to deduct execution time on master to SBM lower_bound.
238 # SBM= now - (ev.when + ev.exec_time)
239 # Also deduct a second to handle rounding differences.
240 --let $lower_bound= `SELECT $delay - ($stop_exec - $start) - 1`
241 --let $stop= `SELECT UNIX_TIMESTAMP()`
242 # Also add a second to handle rounding differences.
243 --let $upper_bound= `SELECT $stop - $start +1`
244 --let $assert_text= Seconds_Behind_Master must be between 'lower_bound' and 'upper_bound'
245 --let $assert_cond= $lower_bound <= $sbm AND $sbm <= $upper_bound
246 --source include/assert.inc
247
248 UNLOCK TABLES;
249 --source include/rpl_connection_master.inc
250 --source include/sync_slave_sql_with_master.inc
251
252 # clean up
253 --source include/stop_slave.inc
254 CHANGE REPLICATION SOURCE TO SOURCE_DELAY= 0;
255 --source include/start_slave.inc
256 --source include/rpl_connection_master.inc
257 DROP TABLE t1;
258 --source include/sync_slave_sql_with_master.inc
259 --source include/rpl_end.inc