File: binlog_mysqlbinlog_do_server_ids.test

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: 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 (477 lines) | stat: -rw-r--r-- 15,936 bytes parent folder | download | duplicates (4)
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#
# Purpose:
#
# This test validates that the option --do-server-ids for the mariadb-binlog
# command line tool correctly filters events by server id.
#
#
# Methodology:
#
# This test invokes mariadb-binlog using combinations of --do-server-ids with
# various combinations of other parameters to ensure it correctly filters by
# server id. Specifically, the following test cases are validated:
#   Test Case 1) --do-server-ids with a single server id limits output to that
#                single server
#   Test Case 2) --do-server-ids with multiple server ids limits output to the
#                provided servers
#   Test Case 3) --do-server-ids when combined with --do-domain-ids should
#                intersect the results
#   Test Case 4) --do-server-ids when combined with --ignore-domain-ids should
#                intersect the results
#   Test Case 5) --do-server-ids when combined with a GTID range should
#                intersect the results
#   Test Case 6) --do-server-ids when combined with both --ignore-domain-ids
#                and a GTID range should intersect all results
#   Test Case 7) --do-server-ids when combined with both --do-domain-ids and
#                a GTID range should intersect all results
#   Test Case 8) --do-server-ids and --offset=<n> skips n events after the
#                first GTID is found
#   Test Case 9) --do-server-ids with --start-datetime=<T> where T occurs
#                after the first GTID is found results in no events before T
#   Test Case 10) --do-server-ids works with --read-from-remote-server
#   Test Case 11) --do-server-ids works over multiple binary log input files
#   Test Case 12) --do-server-ids re-specifications should override previous
#                 ones
#   Test Case 13) --do-server-ids and --server-id should be aliases and a
#                 re-specification of one should override the former
#   Test Case 14) --ignore-server-ids re-specifications should override
#                 previous ones
#   Test Case 15) --do-domain-ids re-specifications should override previous
#                 ones
#   Test Case 16) --ignore-domain-ids re-specifications should override
#                 previous ones
#
# Additionally, this test validates the following error scenarios:
#   Error Case 1) --do-server-ids and --ignore-server-ids cannot be specified
#                 together
#   Error Case 2) Invalid server ID number provided
#
#
# References:
#
#   MDEV-20119: Implement the --do-domain-ids, --ignore-domain-ids, and
#               --ignore-server-ids options for mysqlbinlog
#

--source include/have_log_bin.inc

--echo ###############################
--echo #      Test Setup
--echo ###############################


# Save old state
let $ORIG_GTID_DOMAIN_ID = `select @@session.gtid_domain_id`;
let $ORIG_SERVER_ID = `select @@session.server_id`;

# Configure test variables
--let $MYSQLD_DATADIR=`select @@datadir`

--let table_inconsistent_err= "table data is inconsistent after replaying binlog events";
--let table_exists_error= "table exists but binlog playback should have excluded its creation";

# Initialize test data
set @a=UNIX_TIMESTAMP("1970-01-21 15:32:22");
SET timestamp=@a;
RESET MASTER;

SET @@session.gtid_domain_id= 0;
SET @@session.server_id= 1;
CREATE TABLE t1 (a int);

SET @@session.server_id= 2;
CREATE TABLE t2 (a int);
INSERT INTO t2 values (3);
--let t2_checksum= `CHECKSUM TABLE t2`

SET @@session.gtid_domain_id= 1;
SET @@session.server_id= 1;
CREATE TABLE t3 (a int);
INSERT INTO t3 values (4);
--let t3_checksum= `CHECKSUM TABLE t3`

SET @@session.server_id= 3;
SET timestamp=@a+1;
CREATE TABLE t4 (a int);
SET timestamp=@a+2;
INSERT INTO t4 values (5);
--let t4_checksum= `CHECKSUM TABLE t4`

SET @@session.gtid_domain_id= 0;
SET @@session.server_id= 1;
INSERT INTO t1 values (1);
--let t1_partial_checksum= `CHECKSUM TABLE t1`

SET @@session.gtid_domain_id= 2;
SET @@session.server_id= 1;
CREATE TABLE t5 (a int);
INSERT INTO t5 values (6);
--let t5_checksum= `CHECKSUM TABLE t5`

SET @@session.gtid_domain_id= 0;
SET @@session.server_id= 1;
INSERT INTO t1 values (2);
--let t1_checksum= `CHECKSUM TABLE t1`

FLUSH LOGS;

SET @@session.gtid_domain_id= 0;
SET @@session.server_id= 2;
CREATE TABLE t6 (a int);
INSERT INTO t6 values (1);
--let t6_checksum= `CHECKSUM TABLE t6`
FLUSH LOGS;

--let BINLOG_FILENAME= query_get_value(SHOW BINARY LOGS, Log_name, 1)
--let BINLOG_FILENAME2= query_get_value(SHOW BINARY LOGS, Log_name, 2)
--let BINLOG_FILE_PARAM= $MYSQLD_DATADIR/$BINLOG_FILENAME.orig
--let BINLOG_FILE_PARAM2= $MYSQLD_DATADIR/$BINLOG_FILENAME2.orig
--copy_file $MYSQLD_DATADIR/$BINLOG_FILENAME $BINLOG_FILE_PARAM
--copy_file $MYSQLD_DATADIR/$BINLOG_FILENAME2 $BINLOG_FILE_PARAM2

DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
DROP TABLE t5;
DROP TABLE t6;
RESET MASTER;

--echo ###############################
--echo #      Test Cases
--echo ###############################

--echo #
--echo #   Test Case 1) --do-server-ids with a single server id limits output
--echo # to that single server
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=2 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=2 | $MYSQL
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t2;


--echo #
--echo #   Test Case 2) --do-server-ids with multiple server ids limits output
--echo # to the provided servers
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=2,3 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=2,3 | $MYSQL
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if ($t4_checksum != `CHECKSUM TABLE t4`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t2;
DROP TABLE t4;


--echo #
--echo #   Test Case 3) --do-server-ids when combined with --do-domain-ids should
--echo # intersect the results
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --do-domain-ids=0 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=1 --do-domain-ids=0 | $MYSQL
if ($t1_checksum != `CHECKSUM TABLE t1`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t2','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t1;


--echo #
--echo #   Test Case 4) --do-server-ids when combined with --ignore-domain-ids should
--echo # intersect the results
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --ignore-domain-ids=0 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=1 --ignore-domain-ids=0 | $MYSQL
if ($t3_checksum != `CHECKSUM TABLE t3`)
{
    die $table_inconsistent_err;
}
if ($t5_checksum != `CHECKSUM TABLE t5`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t2','t4','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t3;
DROP TABLE t5;


--echo #
--echo #   Test Case 5) --do-server-ids when combined with a GTID range should
--echo #  intersect the results
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --stop-position=0-1-4 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=1 --stop-position=0-1-4 | $MYSQL
if ($t1_partial_checksum != `CHECKSUM TABLE t1`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t2','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t1;


--echo #
--echo #   Test Case 6) --do-server-ids when combined with both --ignore-domain-ids
--echo # and a GTID range should intersect all results
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --ignore-domain-ids=0 --start-position=1-1-0 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=1 --ignore-domain-ids=0 --start-position=1-1-0 | $MYSQL
if ($t3_checksum != `CHECKSUM TABLE t3`)
{
    die $table_inconsistent_err;
}
if ($t5_checksum != `CHECKSUM TABLE t5`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t2','t4','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t3;
DROP TABLE t5;


--echo #
--echo #   Test Case 7) --do-server-ids when combined with both --do-domain-ids and
--echo # a GTID range should intersect all results
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=2 --do-domain-ids=0 --start-position=0-1-0 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=2 --do-domain-ids=0 --start-position=0-1-0 | $MYSQL
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t2;



--echo #
--echo #   Test Case 8) --do-server-ids and --offset=<n> skips n events after the
--echo # first GTID is found

# t4 needs to be specified because its creation should be skipped from
# --offset specification
CREATE TABLE t4 (a int);

--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --offset=5 --do-server-ids=3 --do-domain-ids=1 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --offset=5 --do-server-ids=3 --do-domain-ids=1 | $MYSQL
if ($t4_checksum != `CHECKSUM TABLE t4`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t2','t3','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t4;


--echo #
--echo #   Test Case 9) --do-server-ids with --start-datetime=<T> where T occurs
--echo # after the first GTID is found results in no events before T

# t4 needs to be specified because its creation should be skipped from
# --start-datetime specification
CREATE TABLE t4 (a int);

--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --start-datetime="1970-01-21 15:32:24" --do-server-ids=3 --do-domain-ids=1 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --start-datetime="1970-01-21 15:32:24" --do-server-ids=3 --do-domain-ids=1 | $MYSQL
if ($t4_checksum != `CHECKSUM TABLE t4`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t2','t3','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t4;


--echo #
--echo #   Test Case 10) --do-server-ids works with --read-from-remote-server

--echo # Setup test specific data
RESET MASTER;

SET @@session.gtid_domain_id= 0;
SET @@session.server_id= 1;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1);

SET @@session.server_id= 2;
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (1);
--let t11_t2_checksum= `CHECKSUM TABLE t2`

SET @@session.server_id= 1;
DROP TABLE t1;
DROP TABLE t2;

--echo # MYSQL_BINLOG BINLOG_FILENAME --read-from-remote-server --do-server-ids=2  | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILENAME --read-from-remote-server --do-server-ids=2  | $MYSQL
if ($t11_t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t2;


--echo #
--echo #   Test Case 11) --do-server-ids works over multiple binary log input
--echo # files
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM BINLOG_FILE_PARAM2 --do-server-ids=2  | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM $BINLOG_FILE_PARAM2 --do-server-ids=2  | $MYSQL
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if ($t6_checksum != `CHECKSUM TABLE t6`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t4','t5')`)
{
    die $table_exists_error;
}
DROP TABLE t2;
DROP TABLE t6;

--echo #
--echo #   Test Case 12) --do-server-ids re-specifications should override
--echo #                 previous ones
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --do-server-ids=2 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=1 --do-server-ids=2 | $MYSQL
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t2;

--echo #
--echo #   Test Case 13) --do-server-ids and --server-id should be aliases and
--echo #                 a re-specification of one should override the former
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --server-id=2 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=1 --server-id=2 | $MYSQL
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t2;

--echo #
--echo #   Test Case 14) --ignore-server-ids re-specifications should override
--echo #                 previous ones
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --ignore-server-ids=2 --ignore-server-ids=1,3 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --ignore-server-ids=2 --ignore-server-ids=1,3 | $MYSQL
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t1','t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t2;

--echo #
--echo #   Test Case 15) --do-domain-ids re-specifications should override
--echo #                 previous ones
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-domain-ids=1 --do-domain-ids=0 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-domain-ids=1 --do-domain-ids=0 | $MYSQL
if ($t1_checksum != `CHECKSUM TABLE t1`)
{
    die $table_inconsistent_err;
}
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t1,t2;

--echo #
--echo #   Test Case 16) --ignore-domain-ids re-specifications should override
--echo #                 previous ones
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --ignore-domain-ids=0 --ignore-domain-ids=1,2 | MYSQL
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --ignore-domain-ids=0 --ignore-domain-ids=1,2 | $MYSQL
if ($t1_checksum != `CHECKSUM TABLE t1`)
{
    die $table_inconsistent_err;
}
if ($t2_checksum != `CHECKSUM TABLE t2`)
{
    die $table_inconsistent_err;
}
if (`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name IN ('t3','t4','t5','t6')`)
{
    die $table_exists_error;
}
DROP TABLE t1,t2;

--echo ##############################
--echo #      Error Cases
--echo ##############################

--echo #
--echo #   Error Case 1:
--echo #   --ignore-server-ids and --do-server-ids both specified
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --ignore-server-ids=2
--error 1
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=1 --ignore-server-ids=2

--echo #
--echo #   Error Case 2:
--echo #   Invalid server ID number provided
--echo # MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=-1
--error 1
--exec $MYSQL_BINLOG $BINLOG_FILE_PARAM --do-server-ids=-1

--echo ##############################
--echo #      Cleanup
--echo ##############################
--eval SET @@global.gtid_domain_id= $ORIG_GTID_DOMAIN_ID
--eval SET @@global.server_id= $ORIG_SERVER_ID

--remove_file $BINLOG_FILE_PARAM
--remove_file $BINLOG_FILE_PARAM2

--echo # End of tests