File: rpl_gtid_until_before_after_gtids.test

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (375 lines) | stat: -rw-r--r-- 10,531 bytes parent folder | download | duplicates (3)
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#
# Helper file to run through test cases to validate that the replica will stop
# at the correct place when running STOP SLAVE UNTIL with options
# SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS.
#
# MTR Parameters:
#   ssu_before_gtids (Boolean): Indicates whether to test SQL_BEFORE_GTIDS,
#    (when true), or SQL_AFTER_GTIDS (when false).
#

--let $include_filename= rpl_gtid_until_before_after_gtids.inc
--source include/begin_include_file.inc

if ($ssu_before_gtids)
{
    --let $ssu_opt=SQL_BEFORE_GTIDS
}
if (!$ssu_before_gtids)
{
    --let $ssu_opt=SQL_AFTER_GTIDS
}

--echo #
--echo # Test Setup ($ssu_opt)

--echo # Clean primary and replica states
--connection master
--source include/save_master_gtid.inc
--connection slave
--source include/stop_slave.inc
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
--source include/stop_slave.inc
--source include/reset_slave.inc
--connection master
RESET MASTER;
set session gtid_domain_id=0;

--echo # Initialize test data
--connection master
create table t1 (a int);
create table t2 (a int);

# Set the value counters to use on insertions. Note they are only set once per
# test, subsequent invocations of this .inc file continue to increment the
# previous values.
if (!$t1_ctr)
{
    --let $t1_ctr= 100
    --let $t2_ctr= 200
}

--source include/save_master_gtid.inc

--connection slave
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc


--echo #
--echo #  Test Case 1 ($ssu_opt): For a single-dimensional binlog state and a
--echo # STOP SLAVE UNTIL gtid position with one GTID, the replica should
if ($ssu_before_gtids)
{
--echo # execute events up until the GTID is encountered, and immediately stop
}
if (!$ssu_before_gtids)
{
--echo # execute events up until the GTID is encountered, finish replicating
--echo # that event group, and then stop
}

--connection slave
--source include/stop_slave.inc
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1)

--connection master
set session gtid_domain_id=0;
--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr
if ($ssu_before_gtids)
{
    --let $expected_stop_gtid= `SELECT @@gtid_binlog_pos`
}
--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr
--let $until_gtid= `SELECT @@gtid_binlog_pos`
if (!$ssu_before_gtids)
{
    --let $expected_stop_gtid= `SELECT @@gtid_binlog_pos`
}
--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr

--connection slave
--eval START SLAVE UNTIL $ssu_opt="$until_gtid"

--echo # Ensure the slave started
--let $slave_param= Exec_Master_Log_Pos
--let $slave_param_comparison= !=
--let $slave_param_value= $initial_slave_pos
--source include/wait_for_slave_param.inc
--let $slave_param_comparison= =

--source include/wait_for_slave_to_stop.inc
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos`

if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`)
{
    --echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid)
    --die Expected stop gtid != actual stop gtid
}

--echo # Clean replica state
--connection master
--source include/save_master_gtid.inc
--connection slave
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc


--echo #
--echo #  Test Case 2 ($ssu_opt): If a provided until GTID doesn't exist in the
--echo # binary log due to a gap, once an event is seen that is beyond the
--echo # until GTID, the slave should immediately stop. Note the behavior of
--echo # this test case should be the same between SQL_BEFORE_GTIDS and
--echo # SQL_AFTER_GTIDS.

--connection slave
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1)
--source include/stop_slave.inc

--connection master
set session gtid_domain_id=0;
--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr
--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr


--echo # Skip a seq_no
--let $binlog_pos= `SELECT @@gtid_binlog_pos`
--let $domain_id= `SELECT @@gtid_domain_id`
--let $server_id= `SELECT @@server_id`
--let $last_seq_no=  `SELECT REGEXP_SUBSTR('$binlog_pos','[0-9]+\\\$')`

--let $skipped_seq_no=  `SELECT ($last_seq_no + 1)`
--let $new_seq_no=  `SELECT ($skipped_seq_no + 1)`
--eval set @@session.gtid_seq_no= $new_seq_no

--let $until_gtid= $domain_id-$server_id-$skipped_seq_no
--let $expected_stop_gtid= $binlog_pos

--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr

--connection slave
--eval START SLAVE UNTIL $ssu_opt="$until_gtid"

--echo # Ensure the slave started
--let $slave_param= Exec_Master_Log_Pos
--let $slave_param_comparison= !=
--let $slave_param_value= $initial_slave_pos
--source include/wait_for_slave_param.inc
--let $slave_param_comparison= =

--source include/wait_for_slave_to_stop.inc
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos`

if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`)
{
    --echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid)
    --die Expected stop gtid != actual stop gtid
}

--connection slave
--source include/start_slave.inc
--connection master
--sync_slave_with_master


--echo #
--echo #  Test Case 3 ($ssu_opt): For a multi-dimensional binlog state and a
--echo # STOP SLAVE UNTIL gtid position with one GTID, the replica should
--echo # execute events from only the specified domain until the provided GTID
if ($ssu_before_gtids)
{
--echo # is encountered, and immediately stop
}
if (!$ssu_before_gtids)
{
--echo # is encountered, finish replicating that event group, and then stop
}

--connection slave
--source include/stop_slave.inc
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1)

--connection master
set session gtid_domain_id=0;
--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr

set session gtid_domain_id=1;
--eval INSERT INTO t2 VALUES ($t2_ctr)
--inc $t2_ctr
--eval INSERT INTO t2 VALUES ($t2_ctr)
--inc $t2_ctr

if ($ssu_before_gtids)
{
    # Will have GTIDs for both domains 0 and 1
    --let $binlog_pos= `SELECT @@gtid_binlog_pos`
    --let $expected_stop_gtid= `SELECT REGEXP_SUBSTR('$binlog_pos','0-[0-9]+-[0-9]+')`
}

set session gtid_domain_id=0;
--eval INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr

--let $binlog_pos= `SELECT @@gtid_binlog_pos`

# Just the GTID for domain 0
--let $until_gtid=  `SELECT REGEXP_SUBSTR('$binlog_pos','0-[0-9]+-[0-9]+')`

if (!$ssu_before_gtids)
{
    --let $expected_stop_gtid= $until_gtid
}

set session gtid_domain_id=1;
--eval INSERT INTO t2 VALUES ($t2_ctr)
--inc $t2_ctr
set session gtid_domain_id=0;

--connection slave
--eval START SLAVE UNTIL $ssu_opt="$until_gtid"

--echo # Ensure the slave started
--let $slave_param= Exec_Master_Log_Pos
--let $slave_param_comparison= !=
--let $slave_param_value= $initial_slave_pos
--source include/wait_for_slave_param.inc
--let $slave_param_comparison= =

--source include/wait_for_slave_to_stop.inc
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos`

if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`)
{
    --echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid)
    --die Expected stop gtid != actual stop gtid
}

--connection slave
--source include/start_slave.inc
--connection master
--sync_slave_with_master


--echo #
--echo #  Test Case 4 ($ssu_opt): For a multi-dimensional binlog state and a
--echo # STOP SLAVE UNTIL gtid position with multiple GTIDs, the replica should
if ($ssu_before_gtids)
{
--echo # for each domain, execute events only up until its provided GTID, and
--echo # once all domains have hit their end point, immediately stop.
}
if (!$ssu_before_gtids)
{
--echo # stop executing events as soon as all listed GTIDs in the UNTIL list
--echo # have been executed.
}

--connection slave
--source include/stop_slave.inc
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1)

--connection master
--eval SET STATEMENT gtid_domain_id=0 FOR INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr

if ($ssu_before_gtids)
{
    # Save binlog pos for domain 0
    --let $expected_stop_gtid_d0= `SELECT REGEXP_SUBSTR(@@global.gtid_binlog_pos,'0-[0-9]+-[0-9]+')`
    --echo # Tagging domain 0 stop: $expected_stop_gtid_d0
}

--eval SET STATEMENT gtid_domain_id=0 FOR INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr

--eval SET STATEMENT gtid_domain_id=1 FOR INSERT INTO t2 VALUES ($t2_ctr)
--inc $t2_ctr

if ($ssu_before_gtids)
{
    # Save binlog pos for domain 1
    --let $expected_stop_gtid_d1= `SELECT REGEXP_SUBSTR(@@global.gtid_binlog_pos,'1-[0-9]+-[0-9]+')`
    --let $expected_stop_gtid= $expected_stop_gtid_d0,$expected_stop_gtid_d1
}

--eval SET STATEMENT gtid_domain_id=1 FOR INSERT INTO t2 VALUES ($t2_ctr)
--inc $t2_ctr

--let $until_gtid= `SELECT @@gtid_binlog_pos`
if (!$ssu_before_gtids)
{
    --let $expected_stop_gtid= $until_gtid
}

--eval SET STATEMENT gtid_domain_id=0 FOR INSERT INTO t1 VALUES ($t1_ctr)
--inc $t1_ctr
--eval SET STATEMENT gtid_domain_id=1 FOR INSERT INTO t2 VALUES ($t2_ctr)
--inc $t2_ctr

--connection slave
--eval START SLAVE UNTIL $ssu_opt="$until_gtid"

--echo # Ensure the slave started
--let $slave_param= Exec_Master_Log_Pos
--let $slave_param_comparison= !=
--let $slave_param_value= $initial_slave_pos
--source include/wait_for_slave_param.inc
--let $slave_param_comparison= =

--source include/wait_for_slave_to_stop.inc
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos`

if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`)
{
    --echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid)
    --die Expected stop gtid != actual stop gtid
}

--connection slave
--source include/start_slave.inc
--connection master
--sync_slave_with_master


--echo #
--echo # Error Case 1: Not providing a valid GTID should result in a syntax
--echo # error

--connection slave
--source include/stop_slave.inc

--error ER_INCORRECT_GTID_STATE
--eval START SLAVE UNTIL $ssu_opt="a"

--error ER_INCORRECT_GTID_STATE
--eval START SLAVE UNTIL $ssu_opt="0"

--error ER_INCORRECT_GTID_STATE
--eval START SLAVE UNTIL $ssu_opt="0-1"

--error ER_INCORRECT_GTID_STATE
--eval START SLAVE UNTIL $ssu_opt="0-1-"

--error ER_INCORRECT_GTID_STATE
--eval START SLAVE UNTIL $ssu_opt="a-b-c"

--source include/start_slave.inc

--echo #
--echo # Cleanup test data
--connection master
DROP TABLE t1, t2;
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc

--let $include_filename= rpl_gtid_until_before_after_gtids.inc
--source include/end_include_file.inc