Skip to content

Commit 98228aa

Browse files
committed
Improve ndb_rpl_circular_2ch_rep_status reliability.
Testcase synchronisation issue - needed to wait for slave-applied changes to be binlogged before replication cutover. Existing get_ndb_epochs.inc and wait_for_ndb_committed_to_binlog.inc backported and hacked to work in 7.1 to achieve this.
1 parent c9da4d9 commit 98228aa

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# ==== Purpose ====
2+
#
3+
# Extract the epoch values from SHOW ENGINE NDB STATUS.
4+
#
5+
# ==== Usage ====
6+
#
7+
# --source include/get_ndb_epochs.inc
8+
# --echo $ndb_latest_epoch
9+
# --echo $ndb_latest_trans_epoch
10+
# --echo $ndb_latest_received_binlog_epoch
11+
# --echo $ndb_latest_handled_binlog_epoch
12+
# --echo $ndb_latest_applied_binlog_epoch
13+
#
14+
# ==== Parameters ====
15+
#
16+
# $ndb_status_binlog_row
17+
# The row number of the output of SHOW ENGINE NDB STATUS
18+
# last was seen.
19+
# No need to set explictly, but used between sourcing this
20+
# include file several times, since it is highly probable
21+
# (but not certain) that same row number also applies next
22+
# time.
23+
24+
if (!$ndb_status_binlog_row)
25+
{
26+
let $ndb_status_binlog_row = 1;
27+
}
28+
29+
# Try two times, in case the row number of binlog state changes
30+
# between two invocations of SHOW ENGINE NDB STATUS.
31+
let $attempts= 20;
32+
let $found= 0;
33+
while ($attempts)
34+
{
35+
let $q= query_get_value(SHOW ENGINE NDB STATUS, Status, $ndb_status_binlog_row);
36+
if (`SELECT INSTR('$q', 'latest_epoch=')`)
37+
{
38+
let $attempts = 1;
39+
let $found = 1;
40+
}
41+
42+
dec $attempts;
43+
44+
if (!$attempts)
45+
{
46+
if (!$found)
47+
{
48+
echo ERROR IN TEST: No binlog row found in SHOW ENGINE NDB STATUS;
49+
die ERROR IN TEST: No binlog row found in SHOW ENGINE NDB STATUS;
50+
}
51+
}
52+
53+
if (!$found)
54+
{
55+
inc $ndb_status_binlog_row;
56+
}
57+
}
58+
59+
let $ndb_latest_epoch= `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING('$q', INSTR('$q', 'latest_epoch=')), ',', 1), '=', -1)`;
60+
let $ndb_latest_trans_epoch= `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING('$q', INSTR('$q', 'latest_trans_epoch=')), ',', 1), '=', -1)`;
61+
let $ndb_latest_received_binlog_epoch= `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING('$q', INSTR('$q', 'latest_received_binlog_epoch=')), ',', 1), '=', -1)`;
62+
let $ndb_latest_handled_binlog_epoch= `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING('$q', INSTR('$q', 'latest_handled_binlog_epoch=')), ',', 1), '=', -1)`;
63+
let $ndb_latest_applied_binlog_epoch= `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING('$q', INSTR('$q', 'latest_applied_binlog_epoch=')), ',', 1), '=', -1)`;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# ==== Purpose ====
2+
#
3+
# Several test primitives from mysql-test/extra/rpl_tests
4+
# are shared for test cases for MyISAM, InnoDB, NDB and
5+
# other engines.
6+
# For NDB engine all events will be added by NDB injector
7+
# so tests only can continue after injector is ready,
8+
# this file waits for all committed transactions (at start
9+
# of file) are injected into the binlog.
10+
#
11+
# ==== Usage ====
12+
#
13+
# let $wait_timeout= 150;
14+
# --source include/wait_for_ndb_committed_to_binlog.inc
15+
#
16+
# ==== Parameters =====
17+
#
18+
# $wait_timeout
19+
# Time to wait in seconds for epoch to be injected in binlog.
20+
# On timeout test dies.
21+
#
22+
23+
if (`SELECT 1 FROM information_schema.engines WHERE engine = 'ndbcluster' AND support IN ('YES', 'DEFAULT')`)
24+
{
25+
let $max_run_time= 150;
26+
if ($wait_timeout)
27+
{
28+
let $max_run_time= $wait_timeout;
29+
}
30+
# Reset $wait_timeout so that its value won't be used on subsequent
31+
# calls, and default will be used instead.
32+
let $wait_timeout= 0;
33+
34+
# The smallest timespan till UNIX_TIMESTAMP() gets incremented is ~0 seconds.
35+
# We add one second to avoid the case that somebody measures timespans on a
36+
# real clock with fractions of seconds, detects that n seconds are sufficient,
37+
# assigns n to this routine and suffers because he sometimes gets n - 1
38+
# seconds in reality.
39+
40+
let $max_end_time= `SELECT UNIX_TIMESTAMP() + $max_run_time + 1`;
41+
42+
source include/get_ndb_epochs.inc;
43+
44+
while (`SELECT $ndb_latest_trans_epoch > $ndb_latest_handled_binlog_epoch AND UNIX_TIMESTAMP() <= $max_end_time`)
45+
{
46+
# Sleep a bit to avoid too heavy load.
47+
sleep 0.1;
48+
49+
source include/get_ndb_epochs.inc;
50+
}
51+
52+
if (`SELECT $ndb_latest_trans_epoch > $ndb_latest_handled_binlog_epoch`)
53+
{
54+
echo ERROR IN TEST: Timeout in waiting for epoch $ndb_latest_trans_epoch to be handled, last handled is $ndb_latest_handled_binlog_epoch;
55+
die ERROR IN TEST: Timeout in waiting for epoch to be handled;
56+
}
57+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ select
7070

7171
--echo Now wait for all replication to quiesce
7272

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+
7382
--echo Now swap replication channels around
7483
--source include/rpl_stop_slaves.inc
7584
--let $rpl_topology= 2->1,3->4

0 commit comments

Comments
 (0)