summaryrefslogtreecommitdiff
path: root/mysql-test/suite/galera/t/galera_as_slave_replay.test
blob: 2e8f45a047bd19f1e0fd5ed3530ec5939baf03d9 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#
# This test tests the operation of transaction replay for async replication slave.
# If a potentially conflicting galera transaction arrives at
# just the right time during the commit and has lock conflict with async replication transaction
# applied by slave SQL thread, then the async replication transaction should either abort
# or rollback and replay (depending on the nature of lock conflict).
#

--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
--source include/galera_have_debug_sync.inc

--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2

--connection node_2a
--source include/galera_cluster.inc
#--source suite/galera/include/galera_have_debug_sync.inc

#
# node 3 is native MariaDB server operating as async replication master
#
--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3
--connection node_3
RESET MASTER;

--connection node_2a
#
# count the number of wsrep replay's done in the node
#
--let $wsrep_local_replays_old = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'`


#
# nodes 1 and 2 form a galera cluster, node 2 operates as slave for native MariaDB naster in node 3
#
--disable_query_log
--eval CHANGE MASTER TO  MASTER_HOST='127.0.0.1', MASTER_USER='root', MASTER_PORT=$NODE_MYPORT_3;
--enable_query_log
START SLAVE;

--connection node_3
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)) engine=innodb;
INSERT INTO t1 VALUES (1, 'a');
INSERT INTO t1 VALUES (3, 'a');

#
# use statement format replication to cause a false positive conflict with async replication transaction
# and galera replication. The conflict will be on GAP lock, and slave SQL thread should rollback
# and replay
#
set binlog_format=STATEMENT;

SET AUTOCOMMIT=ON;
START TRANSACTION;

SELECT * FROM t1  FOR UPDATE;
UPDATE t1 SET f2 = 'c' WHERE f1 > 1;

--connection node_2a
# wait for create table and inserts to be replicated from master
SET SESSION wsrep_sync_wait = 0;
--let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1;
--source include/wait_condition.inc

# wait for create table and inserts to be replicated in cluster
--connection node_1
SET SESSION wsrep_sync_wait = 0;
--let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1;
--source include/wait_condition.inc

--connection node_2a
# Block the future commit of async replication
--let $galera_sync_point = commit_monitor_master_enter_sync
--source include/galera_set_sync_point.inc

# block also the applier before applying begins
SET GLOBAL debug_dbug = "d,sync.wsrep_apply_cb";

#
# now inject a conflicting insert from node 3, it will replicate with
# earlier seqno (than async transaction) and pause before applying in node 2
#
--connection node_1
INSERT INTO test.t1 VALUES (2, 'b');

#
# send the update from master, this will succeed here, beceuase of async replication.
# async replication will apply this in node 2 and pause before commit phase,
--connection node_3
--error 0
COMMIT;

# Wait until async slave commit is blocked in node_2
--connection node_2a
--source include/galera_wait_sync_point.inc

#
# release the applier
# note: have to clear wsrep_apply_cb sync point first, as async replication will go for replay
# and as this sync point, after BF applier is released to progress
#
SET GLOBAL debug_dbug = "";
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";

# Unblock the async slave commit
--connection node_2a
--source include/galera_clear_sync_point.inc
--source include/galera_signal_sync_point.inc

--connection node_3

SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a';
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c';
SELECT * FROM t1;

--connection node_2a

# wsrep_local_replays has increased by 1
set session wsrep_sync_wait=15;
--let $wsrep_local_replays_new = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'`
set session wsrep_sync_wait=0;

--disable_query_log
--eval SELECT $wsrep_local_replays_new - $wsrep_local_replays_old = 1 AS wsrep_local_replays;
--enable_query_log

#
#  replaying of async transaction should be effective, and row 3 having 'c' in f2
#
SELECT *  FROM t1;
SET DEBUG_SYNC = "RESET";

#********************************************************************************
#	test phase 2
#********************************************************************************

--echo #
--echo # test phase with real abort
--echo #

--connection node_3

set binlog_format=ROW;

insert into t1 values (4, 'd');

SET AUTOCOMMIT=ON;
START TRANSACTION;

UPDATE t1 SET f2 = 'd' WHERE f1 = 3;

--connection node_2a
# wait for the last insert to be replicated from master
--let $wait_condition = SELECT COUNT(*) = 4 FROM test.t1;
--source include/wait_condition.inc

# Block the commit
--let $galera_sync_point = commit_monitor_enter_sync
--source include/galera_set_sync_point.inc

# block applier
SET GLOBAL debug_dbug = "d,sync.wsrep_apply_cb";

# Inject a conflicting update from node 3
--connection node_1
UPDATE test.t1 SET f2 = 'e' WHERE f1 = 3;

# send the update from master
--connection node_3
--error 0
COMMIT;

--connection node_2a

# release the applier
SET GLOBAL debug_dbug = "";
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";


# Unblock the async slave commit
--connection node_2a
--source include/galera_clear_sync_point.inc
--source include/galera_signal_sync_point.inc
SET DEBUG_SYNC = "RESET";

--connection node_2a
set session wsrep_sync_wait=0;
--let $wait_condition = SELECT COUNT(*) = 1 FROM test.t1 where f2 = 'e'
--source include/wait_condition.inc
SELECT * from test.t1;

--connection node_1
--let $wait_condition = SELECT COUNT(*) = 1 FROM test.t1 where f2 = 'e'
--source include/wait_condition.inc
SELECT * from test.t1;

--connection node_2a
STOP SLAVE;
RESET SLAVE;

DROP TABLE t1;

--connection node_3
DROP TABLE t1;
RESET MASTER;