Debian Codegraph @

mysql-test/suite/ndb_rpl/t/ndb_rpl_circular_2ch_rep_status.test

raw
1 --source include/have_ndb.inc
2 --source suite/ndb_rpl/ndb_master-slave_2ch.inc
3 --source include/have_binlog_format_mixed_or_row.inc
4
5 #
6 # Test that the Maximum replicated epoch is maintained
7 # as expected in a circular, 2 channel configuration.
8 # The channels are swapped, and replication is restarted
9 # The MaxReplicatedEpoch is reloaded from ndb_apply_status
10 # for the Servers considered local (IGNORE_SERVER_IDS)
11 #
12 --connection master
13 --echo Cluster A servers have no epoch replication info
14 select count(1) from mysql.ndb_apply_status;
15
16 --echo Cluster A servers have no max replicated epoch value
17 --echo Master(1)
18 select variable_name, variable_value from performance_schema.global_status
19 where variable_name='Ndb_slave_max_replicated_epoch';
20 --connection master1
21 --echo Master1(3)
22 select variable_name, variable_value from performance_schema.global_status
23 where variable_name='Ndb_slave_max_replicated_epoch';
24
25 --echo Make a change originating at Cluster A
26 --connection master
27 --echo Master(1)
28 use test;
29 create table t1 (a int primary key, b varchar(100)) engine=ndb;
30 insert into t1 values (1, "Venice");
31
32 --echo Allow it to propagate to Cluster B
33 --sync_slave_with_master slave
34
35 --echo Originate a second unrelated change at Cluster B, to allow us to wait for
36 --echo reverse propagation in the testcase
37 --connection slave1
38 --echo Slave1 (4)
39 insert into t1 values (2, "Death");
40
41 --echo Allow it to propagate to Cluster A
42 --sync_slave_with_master master1
43
44 --echo Observe new entry in ndb_apply_status on Cluster A
45 --connection master
46 --echo Master (1)
47 select server_id from mysql.ndb_apply_status order by server_id;
48
49 --echo Non-slave server on Cluster A will have no value for Max Replicated Epoch
50 select variable_name, variable_value from performance_schema.global_status
51 where variable_name='Ndb_slave_max_replicated_epoch';
52
53 --echo Slave server on Cluster A has current value for Max Replicated Epoch
54 --connection master1
55 --echo Master1 (3)
56 --echo Expect count 1
57 # Here we join the max rep epoch with ndb_apply_status for server id 1
58 # (Our site's current master server)
59 select
60 count(1)
61 from
62 performance_schema.global_status,
63 mysql.ndb_apply_status
64 where
65 server_id = 1
66 and
67 variable_name='Ndb_slave_max_replicated_epoch'
68 and
69 variable_value = epoch;
70
71 --echo Now wait for all replication to quiesce
72
73 # Ensure that already slave-applied events from Cluster B
74 # are in-binlog before allowing the switchover.
75 # Otherwise we can setup replication from a binlog
76 # pos before the already-applied events.
77 # Symptom is that we get an extra ndb_apply_status line
78 # for server_id 3.
79 #
80 --source include/wait_for_ndb_committed_to_binlog.inc
81
82 --echo Now swap replication channels around
83 --source include/rpl_stop_slaves.inc
84 --let $rpl_topology= 2->1,3->4
85 --source include/rpl_change_topology.inc
86
87 # We've changed the direction, but need to set binlog filenames
88 # and positions
89
90 #
91 # 'Normally' we should use the ndb_apply_status max applied epoch,
92 # then lookup ndb_binlog_index etc.
93 # However, in this case (and probably in lots of real cases), no changes
94 # have been made after the last applied epoch, so there is no epoch
95 # after the current one, and therefore no entry in ndb_binlog_index
96 # to get the correct position from.
97 # We could just re-apply the last epoch applied, but that's imprecise,
98 # and causes us to create an ndb_apply_status entry for Server 3 when
99 # it has not really been master for those changes.
100 # So we just look at the Master status instead.
101 #
102 #--echo Get max applied epochs from a server on each cluster
103 #--connection slave
104 #let $max_applied_cluster_a_epoch = query_get_value("SELECT MAX(epoch) AS epoch FROM mysql.ndb_apply_status WHERE server_id IN (1,3)", epoch, 1);
105 #--connection master
106 #let $max_applied_cluster_b_epoch = query_get_value("SELECT MAX(epoch) AS epoch FROM mysql.ndb_apply_status WHERE server_id IN (2,4)", epoch, 1);
107 #
108 #--echo Get corresponding Binlog filename + pos from new Master servers
109 #--connection master1
110 #eval select * from mysql.ndb_binlog_index where epoch > $max_applied_cluster_a_epoch ;
111 #let $cluster_a_master_log_file = query_get_value("SELECT SUBSTRING_INDEX(File, '/', -1) as File from mysql.ndb_binlog_index WHERE epoch >= $max_applied_cluster_a_epoch", File, 1);
112 #let $cluster_a_master_log_pos = query_get_value("SELECT Position from mysql.ndb_binlog_index WHERE epoch >= $max_applied_cluster_a_epoch", Position, 1);
113 #--connection slave
114 #eval select * from mysql.ndb_binlog_index where epoch > $max_applied_cluster_b_epoch;
115 #let $cluster_b_master_log_file = query_get_value("SELECT SUBSTRING_INDEX(File, '/', -1) as File from mysql.ndb_binlog_index WHERE epoch >= $max_applied_cluster_b_epoch", File, 1);
116 #let $cluster_b_master_log_pos = query_get_value("SELECT Position from mysql.ndb_binlog_index WHERE epoch >= $max_applied_cluster_b_epoch", Position, 1);
117 #--echo Now change new Slave servers to new Master file + pos
118 #--connection master
119 #--echo Changing replication source to $cluster_b_master_log_file, $cluster_b_master_log_pos
120 #eval CHANGE MASTER TO MASTER_LOG_FILE="$cluster_b_master_log_file", MASTER_LOG_POS=$cluster_b_master_log_pos;
121 #--connection slave1
122 #--echo Changing replication source to $cluster_a_master_log_file, $cluster_a_master_log_pos
123 #eval CHANGE MASTER TO MASTER_LOG_FILE="$cluster_a_master_log_file", MASTER_LOG_POS=$cluster_a_master_log_pos;
124
125 --echo Get current master status on Cluster A new master (next pos in Binlog)
126 --connection master1
127 --echo Master1 (3)
128 --echo Flush logs to ensure any pending update (e.g. reflected apply_status write row)
129 --echo is skipped over.
130 flush logs;
131 let $cluster_a_master_log_file = query_get_value("SHOW MASTER STATUS", "File", 1);
132 let $cluster_a_master_log_pos = query_get_value("SHOW MASTER STATUS", "Position", 1);
133 --echo Setup slave on Cluster B to use it
134 --connection slave1
135 --echo Slave1 (4)
136 --disable_query_log
137 eval CHANGE REPLICATION SOURCE TO SOURCE_LOG_FILE="$cluster_a_master_log_file", SOURCE_LOG_POS=$cluster_a_master_log_pos;
138 --enable_query_log
139
140 --echo Get current master status on Cluster B new master (next pos in Binlog)
141 --connection slave
142 --echo Slave (2)
143 --echo Flush logs to ensure any pending update (e.g. reflected apply_status write row)
144 --echo is skipped over.
145 flush logs;
146 let $cluster_b_master_log_file = query_get_value("SHOW MASTER STATUS", "File", 1);
147 let $cluster_b_master_log_pos = query_get_value("SHOW MASTER STATUS", "Position", 1);
148 --echo Setup slave on Cluster A to use it
149 --connection master
150 --echo Master (1)
151 --disable_query_log
152 eval CHANGE REPLICATION SOURCE TO SOURCE_LOG_FILE="$cluster_b_master_log_file", SOURCE_LOG_POS=$cluster_b_master_log_pos;
153 --enable_query_log
154
155 --connection master
156 --echo Master (1)
157 --echo Show that Cluster A Slave server (old master) has no Max replicated epoch before receiving data
158 select variable_name, variable_value from performance_schema.global_status
159 where variable_name='Ndb_slave_max_replicated_epoch';
160
161 --connection master1
162 --echo Master1 (3)
163 --echo Cluster A Master server (old slave) has old Max replicated epoch
164 select
165 count(1)
166 from
167 performance_schema.global_status,
168 mysql.ndb_apply_status
169 where
170 server_id = 1
171 and
172 variable_name='Ndb_slave_max_replicated_epoch'
173 and
174 variable_value = epoch;
175
176 --echo Now start slaves up
177 --source include/rpl_start_slaves.inc
178
179 --echo Show that applying something from Cluster B causes the
180 --echo old Max Rep Epoch to be loaded from ndb_apply_status
181 --echo There is no new Max Rep Epoch from Cluster A as it has not changed
182 --echo anything yet
183
184 --connection slave
185 --echo Slave (2)
186 insert into test.t1 values (3, "From the Sea");
187
188 --echo Allow to propagate to Cluster A
189 --sync_slave_with_master master
190
191 --connection master
192 --echo Master (1)
193 --echo New Slave server on Cluster A has loaded old Max-Replicated-Epoch
194 select server_id from mysql.ndb_apply_status order by server_id;
195 select
196 count(1)
197 from
198 performance_schema.global_status,
199 mysql.ndb_apply_status
200 where
201 server_id = 1
202 and
203 variable_name='Ndb_slave_max_replicated_epoch'
204 and
205 variable_value = epoch into @result;
206 select @result;
207
208 # BEGIN TRANSIENT FAILURE DEBUGGING
209 --disable_query_log
210 --disable_result_log
211
212 --let $res=query_get_value("SELECT @result AS r", r, 1)
213
214 if (!$res)
215 {
216 --echo I GOT PROBLEMS
217 --echo IF IN DOUBT, USE BRUTE FORCE
218 --enable_result_log
219 show variables like 'server_id';
220 show status like 'Ndb_slave_max_replicated_epoch';
221 select * from mysql.ndb_apply_status order by server_id;
222 select * from mysql.ndb_binlog_index;
223 SHOW SLAVE STATUS;
224 SHOW BINARY LOGS;
225 SHOW BINLOG EVENTS IN 'master-bin.000001';
226 # SHOW BINLOG EVENTS IN 'master-bin.000002';
227 let $MYSQLD_DATADIR= `select @@datadir;`;
228 --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000001
229 # --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000002
230 --connection master1
231 show variables like 'server_id';
232 show status like 'Ndb_slave_max_replicated_epoch';
233 select * from mysql.ndb_apply_status order by server_id;
234 select * from mysql.ndb_binlog_index;
235 SHOW SLAVE STATUS;
236 SHOW BINARY LOGS;
237 SHOW BINLOG EVENTS IN 'master-bin.000001';
238 SHOW BINLOG EVENTS IN 'master-bin.000002';
239 let $MYSQLD_DATADIR= `select @@datadir;`;
240 --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000001
241 --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000002
242 --connection slave
243 show variables like 'server_id';
244 show status like 'Ndb_slave_max_replicated_epoch';
245 select * from mysql.ndb_apply_status order by server_id;
246 select * from mysql.ndb_binlog_index;
247 SHOW SLAVE STATUS;
248 SHOW BINARY LOGS;
249 SHOW BINLOG EVENTS IN 'master-bin.000001';
250 SHOW BINLOG EVENTS IN 'master-bin.000002';
251 let $MYSQLD_DATADIR= `select @@datadir;`;
252 --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000001
253 --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000002
254 --connection slave1
255 show variables like 'server_id';
256 show status like 'Ndb_slave_max_replicated_epoch';
257 select * from mysql.ndb_apply_status order by server_id;
258 select * from mysql.ndb_binlog_index;
259 SHOW SLAVE STATUS;
260 SHOW BINARY LOGS;
261 SHOW BINLOG EVENTS IN 'master-bin.000001';
262 # SHOW BINLOG EVENTS IN 'master-bin.000002';
263 let $MYSQLD_DATADIR= `select @@datadir;`;
264 --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000001
265 # --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/master-bin.000002
266 --connection master
267 --disable_result_log
268 }
269
270 --enable_result_log
271 --enable_query_log
272
273 # END TRANSIENT FAILURE DEBUGGING
274
275 --echo Now make a new Cluster A change and see that the Max Replicated Epoch advances
276 --echo once it has propagated
277
278 --connection master1
279 --echo Master1 (3)
280 insert into test.t1 values (4, "Brooke");
281
282 --echo Propagate to Cluster B
283 --sync_slave_with_master slave1
284
285 --echo Make change on Cluster B to allow waiting for reverse propagation
286 --connection slave
287 --echo Slave (2)
288 insert into test.t1 values (5, "Rupert");
289
290 --echo Wait for propagation back to Cluster A
291 --sync_slave_with_master master
292
293 --connection master
294 --echo Master (1)
295 --echo Show that Cluster A now has 2 different server_id entries in ndb_apply_status
296 --echo Those from the new master (server_id 3) are highest.
297 select server_id from mysql.ndb_apply_status order by server_id;
298 select
299 count(1)
300 from
301 performance_schema.global_status,
302 mysql.ndb_apply_status
303 where
304 server_id = 3
305 and
306 variable_name='Ndb_slave_max_replicated_epoch'
307 and
308 variable_value = epoch;
309
310 let $max_epoch = query_get_value("select max(epoch) as epoch from mysql.ndb_apply_status where server_id in (1,3)","epoch", 1);
311 --disable_query_log
312 # We have to constrain the search to master server ids 1,3 in case the
313 # Slave happens to have similar epoch values
314 eval select server_id as local_server_with_max_epoch from mysql.ndb_apply_status where epoch=$max_epoch and server_id in (1,3);
315 --enable_query_log
316
317 --echo Done
318
319 --connection master1
320 drop table t1;
321 --sync_slave_with_master slave1
322
323 --source suite/ndb_rpl/ndb_master-slave_2ch_end.inc
324