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
|
#
# BF-BF conflict on MDL locks between DDL and delete query
# when multi-level foreign key like t3 -> t2 -> t1
# are present.
#
# If bug is present, expect the wait condition
# to timeout and when the DELETE applies, it
# will be granted a MDL lock of type SHARED_READ
# for table t1. When resumed, the DROP TABLE will
# also try to MDL lock t1, causing a BF-BF conflict
# on that MDL lock.
--source include/galera_cluster.inc
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
--echo #
--echo # 1. BF-BF conflict on MDL locks between: DROP TABLE t6 and DELETE on t1
--echo # with foreign key references as below:
--echo # - t1<-t2<-t3<-t4
--echo # - t3<-t5
--echo # - t2<-t6
--echo #
#
# Setup
#
--connection node_2
SET GLOBAL wsrep_slave_threads=2;
CREATE TABLE t1 (
id INTEGER PRIMARY KEY,
f2 INTEGER
);
CREATE TABLE t2 (
id INT PRIMARY KEY,
t1_id INT NOT NULL,
t5_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t1_id(t1_id),
CONSTRAINT key_t1_id FOREIGN KEY (t1_id) REFERENCES t1 (id) ON UPDATE CASCADE ON DELETE CASCADE,
KEY key_t5_id(t5_id)
);
CREATE TABLE t3 (
id INT PRIMARY KEY,
t2_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t2_id(t2_id),
CONSTRAINT key_t2_id FOREIGN KEY (t2_id) REFERENCES t2 (id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE t4 (
id INT PRIMARY KEY,
t3_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t3_id(t3_id),
CONSTRAINT key_t3_id FOREIGN KEY (t3_id) REFERENCES t3 (id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE t5 (
id INT PRIMARY KEY,
t3_id_1 INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t3_id_1(t3_id_1),
CONSTRAINT key_t3_id_1 FOREIGN KEY (t3_id_1) REFERENCES t3 (id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE t6 (
id INT PRIMARY KEY,
t2_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t2_id_1(t2_id),
CONSTRAINT key_t2_id_1 FOREIGN KEY (t2_id) REFERENCES t2 (id) ON UPDATE CASCADE ON DELETE CASCADE
);
INSERT INTO t1 VALUES (1,0);
INSERT INTO t1 VALUES (2,0);
INSERT INTO t1 VALUES (3,0);
INSERT INTO t2 VALUES (1,1,1,1234);
INSERT INTO t2 VALUES (2,2,2,1234);
INSERT INTO t3 VALUES (1,1,1234);
INSERT INTO t3 VALUES (2,2,1234);
INSERT INTO t4 VALUES (1,1,1234);
INSERT INTO t4 VALUES (2,2,1234);
INSERT INTO t5 VALUES (1,1,1234);
INSERT INTO t5 VALUES (2,2,1234);
ALTER TABLE t2 ADD CONSTRAINT key_t5_id FOREIGN KEY (t5_id)
REFERENCES t5 (id) ON UPDATE CASCADE ON DELETE CASCADE;
--connection node_1
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = "t2" AND CONSTRAINT_TYPE = "FOREIGN KEY" AND CONSTRAINT_NAME="key_t5_id"
--source include/wait_condition.inc
--let $fk_parent_query = DROP TABLE t6
--let $fk_child_query = DELETE FROM t1 WHERE id = 3
--let $fk_mdl_lock_num = 5
--source galera_multi_level_foreign_key.inc
#
# Verify Foreign key for referenced table added.
#
--connection node_1
--let assert_text= Foreign key referenced table found: 4 tables
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 4
--let assert_select= Foreign key referenced table found:
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t2
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 1
--let assert_select= Foreign key referenced table found: test.t2
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t3
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 1
--let assert_select= Foreign key referenced table found: test.t3
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t4
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 1
--let assert_select= Foreign key referenced table found: test.t4
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t5
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 1
--let assert_select= Foreign key referenced table found: test.t5
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
#
# Verify delete and drop table has succeded.
#
--connection node_2
--let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1
--source include/wait_condition.inc
select * from t1;
select * from t2;
select * from t3;
select * from t4;
select * from t5;
--error ER_NO_SUCH_TABLE
select * from t6;
--connection node_1
select * from t1;
select * from t2;
select * from t3;
select * from t4;
select * from t5;
--error ER_NO_SUCH_TABLE
select * from t6;
#
# Cleanup
#
ALTER TABLE t2 DROP FOREIGN KEY key_t5_id;
DROP TABLE t5, t4, t3, t2, t1;
--echo #
--echo # 2. BF-BF conflict on MDL locks between:
--echo # ALTER TABLE t3 (whose parent table are t3 -> t2 -> t1), and
--echo # DELETE on t1 with t2 referencing t1, and t3 referencing t2.
--echo #
#
# Setup
#
--connection node_2
SET GLOBAL wsrep_slave_threads=2;
CREATE TABLE t1 (
id INTEGER PRIMARY KEY,
f2 INTEGER
);
CREATE TABLE t2 (
id INT PRIMARY KEY,
t1_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t1_id(t1_id),
CONSTRAINT key_t1_id FOREIGN KEY (t1_id) REFERENCES t1 (id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE t3 (
id INT PRIMARY KEY,
t2_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t2_id(t2_id)
);
INSERT INTO t1 VALUES (1,0);
INSERT INTO t1 VALUES (2,0);
INSERT INTO t1 VALUES (3,0);
INSERT INTO t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);
#
# ALTER TABLE t3 and wait for it to reach node_2
#
--let $fk_parent_query = ALTER TABLE t3 ADD CONSTRAINT key_t2_id FOREIGN KEY (t2_id) REFERENCES t2 (id) ON UPDATE CASCADE ON DELETE CASCADE
#
# Issue a DELETE to table that references t1
#
--let $fk_child_query = DELETE FROM t1 WHERE id = 3
--let $fk_mdl_lock_num = 3
--source galera_multi_level_foreign_key.inc
#
# Verify Foreign key for referenced table added.
#
--connection node_1
--let assert_text= Foreign key referenced table found: 2 tables
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 6
--let assert_select= Foreign key referenced table found:
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t2
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 2
--let assert_select= Foreign key referenced table found: test.t2
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t3
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 2
--let assert_select= Foreign key referenced table found: test.t3
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
#
# Verify delete and alter table has succeded.
#
--connection node_2
--let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1
--source include/wait_condition.inc
select * from t1;
select * from t2;
select * from t3;
--connection node_1
select * from t1;
select * from t2;
select * from t3;
#
# Cleanup
#
DROP TABLE t3, t2, t1;
--echo #
--echo # 3. BF-BF conflict on MDL locks between:
--echo # CREATE TABLE t3 (whose parent table are t3 -> t2 -> t1), and
--echo # DELETE on t1 with t2 referencing t1, and t3 referencing t2.
--echo #
#
# Setup
#
--connection node_2
SET GLOBAL wsrep_slave_threads=2;
CREATE TABLE t1 (
id INTEGER PRIMARY KEY,
f2 INTEGER
);
CREATE TABLE t2 (
id INT PRIMARY KEY,
t1_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t1_id(t1_id),
CONSTRAINT key_t1_id FOREIGN KEY (t1_id) REFERENCES t1 (id) ON UPDATE CASCADE ON DELETE CASCADE
);
INSERT INTO t1 VALUES (1,0);
INSERT INTO t1 VALUES (2,0);
INSERT INTO t1 VALUES (3,0);
INSERT INTO t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);
--let $fk_parent_query = CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT NOT NULL, f2 INTEGER NOT NULL, KEY key_t2_id(t2_id), CONSTRAINT key_t2_id FOREIGN KEY (t2_id) REFERENCES t2 (id) ON UPDATE CASCADE ON DELETE CASCADE)
--let $fk_child_query = DELETE FROM t1 WHERE id = 3
--let $fk_mdl_lock_num = 3
--source galera_multi_level_foreign_key.inc
#
# Verify Foreign key for referenced table added.
#
--connection node_1
--let assert_text= Foreign key referenced table found: 2 tables
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 8
--let assert_select= Foreign key referenced table found:
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t2
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 3
--let assert_select= Foreign key referenced table found: test.t2
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t3
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 3
--let assert_select= Foreign key referenced table found: test.t3
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
#
# Verify delete and create table has succeded.
#
--connection node_2
--let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1
--source include/wait_condition.inc
select * from t1;
select * from t2;
select * from t3;
--connection node_1
select * from t1;
select * from t2;
select * from t3;
#
# Cleanup
#
DROP TABLE t3, t2, t1;
--echo #
--echo # 4. BF-BF conflict on MDL locks between:
--echo # OPTIMIZE TABLE t2 (whose parent table are t2 -> t1), and
--echo # DELETE on t1.
--echo #
#
# Setup
#
--connection node_2
SET GLOBAL wsrep_slave_threads=2;
CREATE TABLE t1 (
id INTEGER PRIMARY KEY,
f2 INTEGER
);
CREATE TABLE t2 (
id INT PRIMARY KEY,
t1_id INT NOT NULL,
f2 INTEGER NOT NULL,
KEY key_t1_id(t1_id),
CONSTRAINT key_t1_id FOREIGN KEY (t1_id) REFERENCES t1 (id) ON UPDATE CASCADE ON DELETE CASCADE
);
INSERT INTO t1 VALUES (1,0);
INSERT INTO t1 VALUES (2,0);
INSERT INTO t1 VALUES (3,0);
INSERT INTO t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);
--let $fk_parent_query = OPTIMIZE TABLE t2
--let $fk_child_query = DELETE FROM t1 WHERE id = 3
--let $fk_mdl_lock_num = 2
--source galera_multi_level_foreign_key.inc
#
# Verify Foreign key for referenced table added.
#
--connection node_1
--let assert_text= Foreign key referenced table found: 1 tables
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 9
--let assert_select= Foreign key referenced table found:
--let $assert_only_after = CURRENT_TEST:
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
--let assert_text= Foreign key referenced table found: test.t2
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let assert_count= 4
--let assert_select= Foreign key referenced table found: test.t2
--let assert_only_after= CURRENT_TEST: galera.galera_multi_level_fk_ddl_delete
--source include/assert_grep.inc
#
# Verify delete and create table has succeded.
#
--connection node_2
--let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1
--source include/wait_condition.inc
select * from t1;
select * from t2;
--connection node_1
select * from t1;
select * from t2;
#
# Cleanup
#
DROP TABLE t2, t1;
|