Skip to content

Commit 6b4fd0a

Browse files
committed
Bug#34976028 Crashed NDB Cluster Fails in Phase4 due to index version error on Foreign Key
Backport to 7.5+ Schema objects in Ndb have a composite version, comprising major and minor subversions. When a schema object is created its major version is set. When an existing schema object is altered inplace, its minor subversion is incremented. At restart time each data node checks schema objects as part of recovery. For foreign key objects, the versions of referenced 'parent' and 'child' tables [and indexes] are checked for consistency. For foreign key references from or to a table's primary key, there are no (secondary) indexes involved and only table versions are checked. For foreign key references to or from a secondary index, there are secondary indexes involved which have their versions checked. The table version checks only compare major subversions, allowing tables to evolve. The index version checks also compare minor subversions, resulting in failure at restart time if an index has been altered. Many inplace ALTERs do not affect secondary ordered indexes, and so do not modify their minor subversions, but online table reorganisation and alters of a table's READBACKUP property do affect indexes and their minor subversions. This bug is fixed so that only major subversions are compared for indexes, and two tests are extended to give coverage. ndb_fk_restart nbk_fk_addnode Change-Id: Ic250e3100c9bcd114b1beb42132b3887f4ef1713
1 parent 03c11f6 commit 6b4fd0a

File tree

5 files changed

+536
-11
lines changed

5 files changed

+536
-11
lines changed

mysql-test/suite/ndb/r/ndb_fk_addnode.result

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
create table t1(id1 int NOT NULL PRIMARY KEY, data char(8)) engine=ndb
1+
create table t1(id1 int NOT NULL PRIMARY KEY, data char(8), id3 int not null, unique(id3)) engine=ndb
22
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
3-
create table t2(id2 int NOT NULL PRIMARY KEY, id1 int, data char(8)) engine=ndb
3+
create table t2(id2 int NOT NULL PRIMARY KEY, id1 int, data char(8), id3 int) engine=ndb
44
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
55
alter table t2 algorithm=inplace, add constraint id1 foreign key (id1) references t1(id1);
6-
load data local infile 'suite/ndb/data/table_data10000.dat' into table t1 fields terminated by ' ' lines terminated by '\n' ignore 900 lines;
7-
load data local infile 'suite/ndb/data/table_data10000.dat' into table t2 fields terminated by ' ' lines terminated by '\n' ignore 900 lines (@id, data) set id1 = @id, id2 = -@id;
6+
alter table t2 algorithm=inplace, add constraint id3 foreign key (id3) references t1(id3);
7+
load data local infile 'suite/ndb/data/table_data10000.dat' into table t1 fields terminated by ' ' lines terminated by '\n' ignore 900 lines (@id, data) set id1 = @id, id3 = -@id;
8+
load data local infile 'suite/ndb/data/table_data10000.dat' into table t2 fields terminated by ' ' lines terminated by '\n' ignore 900 lines (@id, data) set id1 = @id, id2 = -@id, id3=-@id;
89
PartitionCount 2
910
FragmentCount 2
1011
HashMap DEFAULT-HASHMAP-3840-2
@@ -14,6 +15,7 @@ PartitionCount 2
1415
FragmentCount 2
1516
HashMap DEFAULT-HASHMAP-3840-2
1617
... id1 (id1) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
18+
10/14/id3 id3 (id3) REFERENCES test.t1/id3$unique () on update noaction on delete noaction
1719

1820

1921
Nodegroup 1 created
@@ -30,8 +32,13 @@ PartitionCount 4
3032
FragmentCount 4
3133
HashMap DEFAULT-HASHMAP-3840-4
3234
... id1 (id1) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
35+
10/14/id3 id3 (id3) REFERENCES test.t1/id3$unique () on update noaction on delete noaction
3336

3437

38+
Check node restart after reorg with foreign keys
39+
--- Wait for node to stop
40+
--- Startup node again
41+
--- Wait for node to recover
3542
* 1006: Illegal reply from server
3643
* error: -2
3744
drop table t2,t1;

mysql-test/suite/ndb/r/ndb_fk_restart.result

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,125 @@ insert into p1(parent_id) select a from rows;
5656
set @n=0;
5757
insert into test.c1(c1,id) select @N:=@N+1,id from p1;
5858
delete from test.c1;
59+
Check interaction of inplace alters and restarts
60+
create table parent (parent_pk int,
61+
parent_uk int,
62+
b int,
63+
primary key (parent_pk),
64+
unique(parent_uk)
65+
) engine=ndb;
66+
create table child (child_pk int,
67+
child_uk int,
68+
child_ord int,
69+
data int,
70+
primary key(child_pk),
71+
unique(child_uk),
72+
key(child_ord),
73+
constraint pkpk foreign key (child_pk) references parent (parent_pk), # PK->PK
74+
constraint pkuk foreign key (child_pk) references parent (parent_uk), # PK->UK
75+
constraint ukpk foreign key (child_uk) references parent (parent_pk), # UK->PK
76+
constraint ukuk foreign key (child_uk) references parent (parent_uk), # UK->UK
77+
constraint ordpk foreign key (child_ord) references parent (parent_pk), # ORD -> PK
78+
constraint orduk foreign key (child_ord) references parent (parent_uk) # ORD -> UK
79+
) engine=ndb;
80+
insert into parent values
81+
(1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5), (6,6,6), (7,7,7), (8,8,8), (9,9,9), (10,10,10),
82+
(11,100,11),
83+
(200,12,200);
84+
Succesful inserts
85+
insert into child values
86+
(1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5), (6,6,6,6), (7,7,7,7), (8,8,8,8), (9,9,9,9);
87+
FK checks working
88+
insert into child values (20, 10, 10, 10);
89+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
90+
insert into child values (11, 11, 10, 10);
91+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
92+
insert into child values (10, 12, 10, 10);
93+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
94+
insert into child values (10, 200, 10, 10);
95+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
96+
insert into child values (10, 10, 12, 10);
97+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
98+
insert into child values (10, 10, 200, 10);
99+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
100+
Capture initial schema versions for parent
101+
and child tables and unique indices involved
102+
in foreign keys
103+
Now alter the tables and indices inplace
104+
Existing FKs should be unaffected.
105+
Alter parent
106+
Rename table x 2
107+
rename table parent to guardian;
108+
rename table guardian to parent;
109+
Parent metadata version diff
110+
Parent table version diff
111+
major_diff minor_diff
112+
0 2
113+
Parent unique version diff
114+
major_diff minor_diff
115+
0 0
116+
Add a column
117+
alter table parent add column extra int;
118+
Warnings:
119+
Warning 1478 Converted FIXED field 'extra' to DYNAMIC to enable online ADD COLUMN
120+
Parent metadata version diff
121+
Parent table version diff
122+
major_diff minor_diff
123+
0 3
124+
Parent unique version diff
125+
major_diff minor_diff
126+
0 0
127+
Fiddle with READ_BACKUP
128+
alter table parent comment='NDB_TABLE=READ_BACKUP=0';
129+
alter table parent comment='NDB_TABLE=READ_BACKUP=1';
130+
Parent metadata version diff
131+
Parent table version diff
132+
major_diff minor_diff
133+
0 5
134+
Parent unique version diff
135+
major_diff minor_diff
136+
0 1
137+
Alter child
138+
Rename table
139+
rename table child to junior;
140+
rename table junior to child;
141+
Child metadata diff
142+
Child table version diff
143+
major_diff minor_diff
144+
0 2
145+
Child unique version diff
146+
major_diff minor_diff
147+
0 0
148+
Child ordered version diff
149+
major_diff minor_diff
150+
0 0
151+
Add a column
152+
alter table child add column extra int;
153+
Warnings:
154+
Warning 1478 Converted FIXED field 'extra' to DYNAMIC to enable online ADD COLUMN
155+
Child metadata diff
156+
Child table version diff
157+
major_diff minor_diff
158+
0 3
159+
Child unique version diff
160+
major_diff minor_diff
161+
0 0
162+
Child ordered version diff
163+
major_diff minor_diff
164+
0 0
165+
Fiddle with readbackup
166+
alter table child comment='NDB_TABLE=READ_BACKUP=0';
167+
alter table child comment='NDB_TABLE=READ_BACKUP=1';
168+
Child metadata diff
169+
Child table version diff
170+
major_diff minor_diff
171+
0 5
172+
Child unique version diff
173+
major_diff minor_diff
174+
0 1
175+
Child ordered version diff
176+
major_diff minor_diff
177+
0 1
59178
-- Normal NR
60179
--- Wait for node to stop
61180
--- Show FKs working
@@ -70,6 +189,19 @@ insert into p1(parent_id) select a from rows;
70189
set @n=0;
71190
insert into test.c1(c1,id) select @N:=@N+1,id from p1;
72191
delete from test.c1;
192+
FK checks working
193+
insert into child values (20, 10, 10, 10, 10);
194+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
195+
insert into child values (11, 11, 10, 10, 10);
196+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
197+
insert into child values (10, 12, 10, 10, 10);
198+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
199+
insert into child values (10, 200, 10, 10, 10);
200+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
201+
insert into child values (10, 10, 12, 10, 10);
202+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
203+
insert into child values (10, 10, 200, 10, 10);
204+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
73205
--- Startup node again
74206
--- Wait for node to recover
75207
--- Show FKs working
@@ -84,6 +216,19 @@ insert into p1(parent_id) select a from rows;
84216
set @n=0;
85217
insert into test.c1(c1,id) select @N:=@N+1,id from p1;
86218
delete from test.c1;
219+
FK checks working
220+
insert into child values (20, 10, 10, 10, 10);
221+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
222+
insert into child values (11, 11, 10, 10, 10);
223+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
224+
insert into child values (10, 12, 10, 10, 10);
225+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
226+
insert into child values (10, 200, 10, 10, 10);
227+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
228+
insert into child values (10, 10, 12, 10, 10);
229+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
230+
insert into child values (10, 10, 200, 10, 10);
231+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
87232
-- Initial NR
88233
--- Wait for node to stop
89234
--- Show FKs working
@@ -98,6 +243,19 @@ insert into p1(parent_id) select a from rows;
98243
set @n=0;
99244
insert into test.c1(c1,id) select @N:=@N+1,id from p1;
100245
delete from test.c1;
246+
FK checks working
247+
insert into child values (20, 10, 10, 10, 10);
248+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
249+
insert into child values (11, 11, 10, 10, 10);
250+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
251+
insert into child values (10, 12, 10, 10, 10);
252+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
253+
insert into child values (10, 200, 10, 10, 10);
254+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
255+
insert into child values (10, 10, 12, 10, 10);
256+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
257+
insert into child values (10, 10, 200, 10, 10);
258+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
101259
--- Startup node again
102260
--- Wait for node to recover
103261
--- Show FKs working
@@ -112,6 +270,19 @@ insert into p1(parent_id) select a from rows;
112270
set @n=0;
113271
insert into test.c1(c1,id) select @N:=@N+1,id from p1;
114272
delete from test.c1;
273+
FK checks working
274+
insert into child values (20, 10, 10, 10, 10);
275+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
276+
insert into child values (11, 11, 10, 10, 10);
277+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
278+
insert into child values (10, 12, 10, 10, 10);
279+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
280+
insert into child values (10, 200, 10, 10, 10);
281+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
282+
insert into child values (10, 10, 12, 10, 10);
283+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
284+
insert into child values (10, 10, 200, 10, 10);
285+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
115286
-- System restart
116287
--- Wait for node to stop
117288
--- Startup nodes again
@@ -129,8 +300,23 @@ insert into p1(parent_id) select a from rows;
129300
set @n=0;
130301
insert into test.c1(c1,id) select @N:=@N+1,id from p1;
131302
delete from test.c1;
303+
FK checks working
304+
insert into child values (20, 10, 10, 10, 10);
305+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
306+
insert into child values (11, 11, 10, 10, 10);
307+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
308+
insert into child values (10, 12, 10, 10, 10);
309+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
310+
insert into child values (10, 200, 10, 10, 10);
311+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
312+
insert into child values (10, 10, 12, 10, 10);
313+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
314+
insert into child values (10, 10, 200, 10, 10);
315+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
132316
delete from test.p1;
133317
drop table test.c2;
134318
drop table test.c1;
135319
drop table test.p1;
136320
drop table test.rows;
321+
drop table test.child;
322+
drop table test.parent;

mysql-test/suite/ndb/t/ndb_fk_addnode.test

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
-- source include/have_ndb.inc
22
-- source include/not_embedded.inc
33

4-
create table t1(id1 int NOT NULL PRIMARY KEY, data char(8)) engine=ndb
4+
create table t1(id1 int NOT NULL PRIMARY KEY, data char(8), id3 int not null, unique(id3)) engine=ndb
55
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
6-
create table t2(id2 int NOT NULL PRIMARY KEY, id1 int, data char(8)) engine=ndb
6+
create table t2(id2 int NOT NULL PRIMARY KEY, id1 int, data char(8), id3 int) engine=ndb
77
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
88
alter table t2 algorithm=inplace, add constraint id1 foreign key (id1) references t1(id1);
9+
alter table t2 algorithm=inplace, add constraint id3 foreign key (id3) references t1(id3);
910

10-
load data local infile 'suite/ndb/data/table_data10000.dat' into table t1 fields terminated by ' ' lines terminated by '\n' ignore 900 lines;
11-
load data local infile 'suite/ndb/data/table_data10000.dat' into table t2 fields terminated by ' ' lines terminated by '\n' ignore 900 lines (@id, data) set id1 = @id, id2 = -@id;
11+
load data local infile 'suite/ndb/data/table_data10000.dat' into table t1 fields terminated by ' ' lines terminated by '\n' ignore 900 lines (@id, data) set id1 = @id, id3 = -@id;
12+
load data local infile 'suite/ndb/data/table_data10000.dat' into table t2 fields terminated by ' ' lines terminated by '\n' ignore 900 lines (@id, data) set id1 = @id, id2 = -@id, id3=-@id;
1213

1314
## Check details of partitioning
1415
--replace_regex /FragmentCount:/FragmentCount/ /PartitionCount:/PartitionCount/ /HashMap:/HashMap/ /.*[=:#].*// /.*- .*// /[0-9]*\/[0-9]*\/id1/.../
@@ -36,6 +37,18 @@ alter table t1 algorithm=inplace, reorganize partition;
3637
--replace_regex /FragmentCount:/FragmentCount/ /PartitionCount:/PartitionCount/ /HashMap:/HashMap/ /.*[=:#].*// /.*- .*// /[0-9]*\/[0-9]*\/id1/.../
3738
--exec $NDB_DESC -dtest t2
3839

40+
--echo Check node restart after reorg with foreign keys
41+
--exec $NDB_MGM -e "1 RESTART -n" >> $NDB_TOOLS_OUTPUT
42+
43+
--echo --- Wait for node to stop
44+
--exec $NDB_WAITER --not-started -w1 >> $NDB_TOOLS_OUTPUT
45+
46+
--echo --- Startup node again
47+
--exec $NDB_MGM -e "1 START" >> $NDB_TOOLS_OUTPUT
48+
49+
--echo --- Wait for node to recover
50+
--exec $NDB_WAITER >> $NDB_TOOLS_OUTPUT
51+
3952
## Drop nodegroup with "new" nodes is not allowed with data one those nodes
4053
# NOTE: --error=0 is due to return codes doesnt work on windoze
4154
--replace_regex /Connected to Management Server at: .*//
@@ -49,3 +62,4 @@ drop table t2,t1;
4962
--exec $NDB_MGM -e "drop nodegroup 1"
5063

5164
# Cleanup
65+
--remove_file $NDB_TOOLS_OUTPUT

0 commit comments

Comments
 (0)