File: ndb_binlog_variants.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (539 lines) | stat: -rw-r--r-- 16,812 bytes parent folder | download
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
########################################################
# Test binlog variants produced by Ndb
#
#  1) Updates logged as write_row events
#     Only primary key and updated columns included in the 
#     event
#  2) Updates logged as write_row_events
#     All columns included in the event
#  3) Updates logged as update_row events
#     Only primary key and updated columns included in the
#     event
#  4) Updates logged as update_row events
#     All columns included in the event
#
#  Format variant (1) is the Ndb default.
#
#  We use mysqlbinlog --verbose to check that the
#  generated binlog contents are as expected.
#
########################################################
-- source include/have_ndb.inc
-- source include/have_binlog_format_row.inc

# Setup connections
connect(mysqld1,127.0.0.1,root,,test,$MASTER_MYPORT);
connect(mysqld2,127.0.0.1,root,,test,$MASTER_MYPORT1);
connect(mysqld3,127.0.0.1,root,,test,$MASTER_MYPORT2);
connect(mysqld4,127.0.0.1,root,,test,$MASTER_MYPORT3);
connect(mysqld5,127.0.0.1,root,,test,$MASTER_MYPORT4);
connect(mysqld6,127.0.0.1,root,,test,$MASTER_MYPORT5);

connection mysqld1;

# Create the tables we're going to use
create table ab(a1 int, a2 int, a3 int, a4 int, a5 int, primary key(a2,a5)) engine = ndb;
create table ba(ks int primary key, st int, lp int) engine = ndb;
create table cpk(nonchar int, charone varchar(100), chartwo varchar(100),
                 other int,
                 primary key (nonchar, charone, chartwo)) engine=ndb;

# Wait for each mysqld to startup binlogging
--let $source_server=mysqld1
--let $dest_server=mysqld2
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=mysqld1
--let $dest_server=mysqld3
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=mysqld1
--let $dest_server=mysqld4
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=mysqld1
--let $dest_server=mysqld5
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=mysqld1
--let $dest_server=mysqld6
source suite/ndb_rpl/t/wait_schema_logging.inc;

--disable_query_log
connection mysqld1;
reset master;
connection mysqld2;
reset master;
connection mysqld3;
reset master;
connection mysqld4;
reset master;
connection mysqld5;
reset master;
connection mysqld6;
reset master;
--enable_query_log

connection mysqld1;

# Now make the inserts and update
insert into ab values (1,1,1,1,1), (2,2,2,2,2), (3,3,3,3,3), (4,4,4,4,4);
update ab set a3=111 where a2=1;
update ab set a1=222, a4=222 where a2=2;

insert into ba values (1, 1, 1), (2,2,2), (3,3,3), (4,4,4);
update ba set lp=40 where ks=4; # Update does not affect all columns
delete from ba where ks=2;      # Also a delete for fun

insert into cpk values(1, "ABCD", "WXYZ", 100);
insert into cpk values(2, "ABCD", "WXYZ", 100);
insert into cpk values(3, "ABCD", "WXYZ", 100);
insert into cpk values(4, "ABCD", "WXYZ", 100);
insert into cpk values(5, "ABCD", "WXYZ", 100);
insert into cpk values(6, "ABCD", "WXYZ", 100);

--echo Change one char key
update cpk set charone="abcd" where charone="ABCD" and nonchar=1 and chartwo="WXYZ";
--echo Change other char key
update cpk set chartwo="wxyz" where charone="ABCD" and nonchar=2 and chartwo="WXYZ";
--echo Change both char keys
update cpk set charone="abcd", chartwo="wxyz" where charone="ABCD" and nonchar=3 and chartwo="WXYZ";
--echo Null change
update cpk set charone="ABCD", chartwo="WXYZ" where charone="ABCD" and nonchar=4 and chartwo="WXYZ";
--echo Null change + data change
update cpk set charone="ABCD", chartwo="WXYZ", other=200 where charone="ABCD" and nonchar=5 and chartwo="WXYZ";
--echo Change both char keys + data
update cpk set charone="abcd", chartwo="wxyz", other=200 where charone="ABCD" and nonchar=6 and chartwo="WXYZ";



--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Now let's trim the Binlogs on each server

connection mysqld1;
--source include/wait_for_binlog_event.inc
flush logs;
connection mysqld2;
--source include/wait_for_binlog_event.inc
flush logs;
connection mysqld3;
--source include/wait_for_binlog_event.inc
flush logs;
connection mysqld4;
--source include/wait_for_binlog_event.inc
flush logs;
connection mysqld5;
--source include/wait_for_binlog_event.inc
flush logs;
connection mysqld6;
--source include/wait_for_binlog_event.inc
flush logs;

# Empty the table
delete from ba;

# Now let's examine the contents of the first binlog
# on each server
# We'll also apply the Binlog and check that the
# table contents are as expected in each case.
# As each server is recording in a new binlog, the
# new updates will go there.

connection mysqld1;

show variables like 'ndb_log_update%';
--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from ab order by a2,a4;
delete from ab;
select * from ba order by ks;
delete from ba;
select * from cpk order by nonchar;
delete from cpk;

connection mysqld2;

show variables like 'ndb_log_update%';
--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from ab order by a2,a4;
delete from ab;
select * from ba order by ks;
delete from ba;
select * from cpk order by nonchar;
delete from cpk;

connection mysqld3;

show variables like 'ndb_log_update%';
--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from ab order by a2,a4;
delete from ab;
select * from ba order by ks;
delete from ba;
select * from cpk order by nonchar;
delete from cpk;

connection mysqld4;

show variables like 'ndb_log_update%';
--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from ab order by a2,a4;
delete from ab;
select * from ba order by ks;
delete from ba;
select * from cpk order by nonchar;
delete from cpk;

connection mysqld5;

show variables like 'ndb_log_update%';
--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from ab order by a2,a4;
delete from ab;
select * from ba order by ks;
delete from ba;
select * from cpk order by nonchar;
delete from cpk;

connection mysqld6;

show variables like 'ndb_log_update%';
--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from ab order by a2,a4;
delete from ab;
select * from ba order by ks;
delete from ba;
select * from cpk order by nonchar;
delete from cpk;

drop table ab;
drop table ba;
drop table cpk;
--disable_query_log
flush logs;
--enable_query_log

connection mysqld1;
CREATE TABLE mysql.ndb_replication
  (db VARBINARY(63),
   table_name VARBINARY(63),
   server_id INT UNSIGNED,
   binlog_type INT UNSIGNED,
   conflict_fn VARBINARY(128),
   PRIMARY KEY USING HASH (db,table_name,server_id))
  ENGINE=NDB PARTITION BY KEY(db,table_name);

insert into mysql.ndb_replication values("test", "t1", 0, 6, NULL);
insert into mysql.ndb_replication values("test", "t2", 0, 7, NULL);
insert into mysql.ndb_replication values("test", "t3", 0, 8, NULL);
insert into mysql.ndb_replication values("test", "t4", 0, 9, NULL);

create table t1(a1 int, a2 int, a3 int, a4 int, a5 int, primary key(a2,a5)) engine=ndb;
create table t2(a1 int, a2 int, a3 int, a4 int, a5 int, primary key(a2,a5)) engine=ndb;
create table t3(a1 int, a2 int, a3 int, a4 int, a5 int, primary key(a2,a5)) engine=ndb;
create table t4(a1 int, a2 int, a3 int, a4 int, a5 int, primary key(a2,a5)) engine=ndb;

--disable_query_log
reset master;
--enable_query_log

# Now make the inserts and update
insert into t1 values (1,1,1,1,1), (2,2,2,2,2), (3,3,3,3,3), (4,4,4,4,4);
insert into t2 values (1,1,1,1,1), (2,2,2,2,2), (3,3,3,3,3), (4,4,4,4,4);
insert into t3 values (1,1,1,1,1), (2,2,2,2,2), (3,3,3,3,3), (4,4,4,4,4);
insert into t4 values (1,1,1,1,1), (2,2,2,2,2), (3,3,3,3,3), (4,4,4,4,4);
update t1 set a3=111 where a2=1;
update t1 set a1=222, a4=222 where a2=2;
update t2 set a3=111 where a2=1;
update t2 set a1=222, a4=222 where a2=2;
update t3 set a3=111 where a2=1;
update t3 set a1=222, a4=222 where a2=2;
update t4 set a3=111 where a2=1;
update t4 set a1=222, a4=222 where a2=2;

--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Now let's trim the Binlogs on each server
connection mysqld1;
--source include/wait_for_binlog_event.inc
flush logs;

--source suite/ndb_binlog/t/ndb_binlog_get_binlog_stmts.inc

# Clear the table
delete from t1;
delete from t2;
delete from t3;
delete from t4;

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from t1 order by a2,a5;
select * from t2 order by a2,a5;
select * from t3 order by a2,a5;
select * from t4 order by a2,a5;

drop table t1, t2, t3, t4;
drop table mysql.ndb_replication;

# Bug#46662
# Replicating changes to tables with unique indexes
# The fix to bug#27378 results in the slave using NdbApi's write()
# mechanism when applying WRITE_ROW events to tables with unique
# indices.
# 
# If this is not done then the slave attempts to partially use SQL 
# REPLACE semantics when applying WRITE_ROW events to tables with 
# unique indexes, which is not good and the slave fails with a 
# duplicate key error on the primary key.
#
# The fix to Bug#46662 aims to correct this, so that replicated
# updates to tables with unique indices can work.
# Note that other issues with replicating into tables with unique
# indexes remain.
# 

connection mysqld1;
reset master;
show variables like 'ndb_log_update%';

create table bah (tst int primary key, cvy int, sqs int, unique(sqs)) engine=ndb;

insert into bah values (1,1,1);

# Wait for epoch to complete in Binlog
--disable_query_log
create table dummy (a int primary key) engine=ndb;
--enable_query_log

# Now perform update
# This will be logged as WRITE
# Without ability to use NdbApi write() for replace, mysqlbinlog
# application will fail with duplicate key error on insert.
update bah set cvy= 2 where tst=1;

select * from bah order by tst;

# Wait for epoch to complete in Binlog
--disable_query_log
drop table dummy;
flush logs;
--enable_query_log

drop table bah;

# Now let's re-apply the binlog
# Without fix, this fails with duplicate PK error
--echo Manually applying captured binlog
--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from bah order by tst;

drop table bah;

# Bug #14615095   ERROR 839 'ILLEGAL NULL ATTRIBUTE' WHEN REPLAYING BINLOG
# When applying WRITE_ROW events to tables where the rows are missing
# any errors should be ignored

connection mysqld1;
reset master;
show variables like '%log_update%';

CREATE TABLE `t1` (
   `charId` varchar(60) NOT NULL,
   `enumId` enum('A','B','C') NOT NULL,
   `val` bigint(20) NOT NULL,
   `version` int(11) NOT NULL,
   PRIMARY KEY (`charId`,`enumId`)
  ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;

INSERT INTO t1 VALUES ('', 'A', 0, 1);

--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Wait until the INSERT statement is confirmed to have made it into the current binary log
--source include/wait_for_binlog_event.inc
FLUSH LOGS;

UPDATE t1 SET val = val + 1 WHERE charId = '';

--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Wait until the UPDATE statement is confirmed to have made it into the current binary log
--let $wait_binlog_file=binlog.000002
--source include/wait_for_binlog_event.inc
FLUSH LOGS;

DELETE FROM t1 WHERE charId = '';

--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Wait until the DELETE statement is confirmed to have made it into the current binary log
--let $wait_binlog_file=binlog.000003
--source include/wait_for_binlog_event.inc
FLUSH LOGS;

# Now let's re-apply the binlog from the UPDATE
# Without fix, this fails with 'Illegal null attribute'
--echo Manually applying captured binlog
--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000002 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
# Check that the table is still empty
select * from t1;

drop table t1;

# Bug #14678088   CAN'T FIND RECORD IN
# We need to be idempotent when applying binlog
# test insert of existing row, update and delete
# of non-existing row

connection mysqld1;
reset master;
show variables like '%log_update%';

create table t1 (pk int not null primary key, name varchar(256)) engine = ndb;

--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Wait until all statements are confirmed to have made it into the current binary log
--let $wait_binlog_file=binlog.000001
--source include/wait_for_binlog_event.inc
FLUSH LOGS;

insert into t1 values (0, "zero"),(1,"one"),(2,"two"),(3,"three"),(4,"four"),(5,"five"),(6,"six"),(7,"seven"),(8,"eight"),(9,"nine");
select * from t1 order by pk;

update t1 set name = "even" where pk in (0,2,4,6,8);
update t1 set name = "odd" where pk in (1,3,5,7,9);

delete from t1 where name = "odd";

select * from t1 order by pk;

--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Wait until all statements are confirmed to have made it into the current binary log
--let $wait_binlog_file=binlog.000002
--source include/wait_for_binlog_event.inc
FLUSH LOGS;

truncate t1;
insert into t1 values (0, "zero"),(1,"one"),(2,"two"),(3,"three"),(4,"four"),(5,"five"),(6,"six"),(7,"seven"),(8,"eight"),(9,"nine");
select * from t1 order by pk;

--disable_query_log
# Add an event-stream marker
create table stream_marker(a int) engine=ndb;
drop table stream_marker;
--let $wait_binlog_event=stream_marker
--enable_query_log

# Wait until all statements are confirmed to have made it into the current binary log
--let $wait_binlog_file=binlog.000003
--source include/wait_for_binlog_event.inc
FLUSH LOGS;

# Now let's re-apply the binlog INSERT,UPDATE,DELETE
# Without fix, this fails with 'Illegal null attribute'
--echo Manually applying captured binlog
--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/binlog.000002 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
--exec $MYSQL -uroot < $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

--enable_query_log
select * from t1 order by pk;

drop table t1;
--remove_file $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql