Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CREATE, DROP, ALTER TABLE causes MDL BF-BF conflict #463

Open
wants to merge 1 commit into
base: 10.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions mysql-test/suite/galera/r/mwb-1789-alter.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
connection node_2;
connection node_1;
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 t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);
connection node_2;
SET GLOBAL DEBUG_DBUG = '+d,sync.wsrep_apply_toi';
connection node_1;
ALTER TABLE t3 ADD CONSTRAINT key_t2_id FOREIGN KEY (t2_id)
REFERENCES t2 (id) ON UPDATE CASCADE ON DELETE CASCADE;
connection node_2;
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_toi_reached";
SET SESSION wsrep_sync_wait = 0;
connection node_1;
UPDATE t1 SET f2 = 1 WHERE id=2;
connection node_2;
SET GLOBAL DEBUG_DBUG = '-d,sync.wsrep_apply_toi';
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_toi";
SET GLOBAL DEBUG_DBUG="RESET";
SET GLOBAL wsrep_slave_threads=DEFAULT;
DROP TABLE t3, t2, t1;
40 changes: 40 additions & 0 deletions mysql-test/suite/galera/r/mwb-1789-create.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
connection node_2;
connection node_1;
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 t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);
connection node_2;
SET GLOBAL DEBUG_DBUG = '+d,sync.wsrep_apply_toi';
connection node_1;
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
);
connection node_2;
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_toi_reached";
SET SESSION wsrep_sync_wait = 0;
connection node_1;
UPDATE t1 SET f2 = 1 WHERE id=2;
connection node_2;
SET GLOBAL DEBUG_DBUG = '-d,sync.wsrep_apply_toi';
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_toi";
SET GLOBAL DEBUG_DBUG="RESET";
SET GLOBAL wsrep_slave_threads=DEFAULT;
DROP TABLE t3, t2, t1;
43 changes: 43 additions & 0 deletions mysql-test/suite/galera/r/mwb-1789-drop-fk2.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
connection node_2;
connection node_1;
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),
CONSTRAINT key_t2_id 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 t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);
INSERT INTO t3 VALUES (1,1,1234);
INSERT INTO t3 VALUES (2,2,1234);
connection node_2;
SET GLOBAL DEBUG_DBUG = '+d,sync.wsrep_apply_toi';
connection node_1;
DROP TABLE t3;
connection node_2;
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_toi_reached";
SET SESSION wsrep_sync_wait = 0;
connection node_1;
UPDATE t1 SET f2 = 1 WHERE id=2;
connection node_2;
SET GLOBAL DEBUG_DBUG = '-d,sync.wsrep_apply_toi';
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_toi";
SET GLOBAL DEBUG_DBUG="RESET";
SET GLOBAL wsrep_slave_threads=DEFAULT;
DROP TABLE t2, t1;
32 changes: 32 additions & 0 deletions mysql-test/suite/galera/r/mwb-1789-drop.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
connection node_2;
connection node_1;
connection node_2;
SET GLOBAL wsrep_slave_threads=2;
CREATE TABLE t1 (
id INTEGER PRIMARY KEY,
f2 INTEGER);
CREATE TABLE t2 (
f1 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 t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);
connection node_2;
SET GLOBAL DEBUG_DBUG = '+d,sync.wsrep_apply_toi';
connection node_1;
DROP TABLE t2;
connection node_2;
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_toi_reached";
SET SESSION wsrep_sync_wait = 0;
connection node_1;
UPDATE t1 SET f2 = 1 WHERE id=2;
connection node_2;
SET GLOBAL DEBUG_DBUG = '-d,sync.wsrep_apply_toi';
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_toi";
SET GLOBAL DEBUG_DBUG="RESET";
SET GLOBAL wsrep_slave_threads=DEFAULT;
DROP TABLE t1;
94 changes: 94 additions & 0 deletions mysql-test/suite/galera/t/mwb-1789-alter.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#
# BF-BF conflict on MDL locks between:
# ALTER TABLE t3 (whose parent table are t3 -> t2 -> t1), and
# UPDATE on t1 with t2 referencing t1, and t3 referencing t2.
#

--source include/galera_cluster.inc
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc

#
# 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 t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);

#
# ALTER TABLE t3 and wait for it to reach node_2
#
--connection node_2
SET GLOBAL DEBUG_DBUG = '+d,sync.wsrep_apply_toi';

--connection node_1
ALTER TABLE t3 ADD CONSTRAINT key_t2_id FOREIGN KEY (t2_id)
REFERENCES t2 (id) ON UPDATE CASCADE ON DELETE CASCADE;

--connection node_2
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_toi_reached";

SET SESSION wsrep_sync_wait = 0;
--let $expected_apply_waits = `SELECT VARIABLE_VALUE+1 FROM performance_schema.global_status WHERE VARIABLE_NAME = 'wsrep_apply_waits'`

#
# Issue a UPDATE to table that references t1
# Notice that we update field f2, not the primary key,
# and not foreign key. Bug does not manifest if we update
# one of those fields (because FK keys appended in those cases).
#
--connection node_1
UPDATE t1 SET f2 = 1 WHERE id=2;


#
# Expect the UPDATE to depend on the ALTER TABLE,
# therefore it should wait for the CREAT TABLE to
# finish before it can be applied.
# If bug is present, expect the wait condition
# to timeout and when the UPDATE applies, it
# will be granted a MDL lock of type SHARED_READ
# for table t1. When resumed, the ALTER TABLE will
# also try to MDL lock t1, causing a BF-BF conflict
# on that MDL lock.
#
--connection node_2
--let $wait_condition = SELECT VARIABLE_VALUE = $expected_apply_waits FROM performance_schema.global_status WHERE VARIABLE_NAME = 'wsrep_apply_waits';
--source include/wait_condition.inc
SET GLOBAL DEBUG_DBUG = '-d,sync.wsrep_apply_toi';
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_toi";


#
# Cleanup
#
SET GLOBAL DEBUG_DBUG="RESET";
SET GLOBAL wsrep_slave_threads=DEFAULT;

DROP TABLE t3, t2, t1;
93 changes: 93 additions & 0 deletions mysql-test/suite/galera/t/mwb-1789-create.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#
# BF-BF conflict on MDL locks between:
# CREATE TABLE t3 (whose parent table are t3 -> t2 -> t1), and
# UPDATE on t1 with t2 referencing t1, and t3 referencing t2.
#

--source include/galera_cluster.inc
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc

#
# 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 t2 VALUES (1,1,1234);
INSERT INTO t2 VALUES (2,2,1234);

#
# CREATE TABLE t3 and wait for it to reach node_2
#
--connection node_2
SET GLOBAL DEBUG_DBUG = '+d,sync.wsrep_apply_toi';

--connection node_1
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
);

--connection node_2
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_toi_reached";

SET SESSION wsrep_sync_wait = 0;
--let $expected_apply_waits = `SELECT VARIABLE_VALUE+1 FROM performance_schema.global_status WHERE VARIABLE_NAME = 'wsrep_apply_waits'`

#
# Issue a UPDATE to table that references t1
# Notice that we update field f2, not the primary key,
# and not foreign key. Bug does not manifest if we update
# one of those fields (because FK keys appended in those cases).
#
--connection node_1
UPDATE t1 SET f2 = 1 WHERE id=2;


#
# Expect the UPDATE to depend on the CREATE TABLE,
# therefore it should wait for the CREAT TABLE to
# finish before it can be applied.
# If bug is present, expect the wait condition
# to timeout and when the UPDATE applies, it
# will be granted a MDL lock of type SHARED_READ
# for table t1. When resumed, the CREATE TABLE will
# also try to MDL lock t1, causing a BF-BF conflict
# on that MDL lock.
#
--connection node_2
--let $wait_condition = SELECT VARIABLE_VALUE = $expected_apply_waits FROM performance_schema.global_status WHERE VARIABLE_NAME = 'wsrep_apply_waits';
--source include/wait_condition.inc
SET GLOBAL DEBUG_DBUG = '-d,sync.wsrep_apply_toi';
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_toi";


#
# Cleanup
#
SET GLOBAL DEBUG_DBUG="RESET";
SET GLOBAL wsrep_slave_threads=DEFAULT;

DROP TABLE t3, t2, t1;
Loading