| 1 |
# |
| 2 |
# MDEV-34836: TOI transaction on FK-referenced parent table must BF abort |
| 3 |
# SR transaction in progress on a child table. |
| 4 |
# |
| 5 |
# Applied SR transaction on the child table was not BF aborted by TOI running |
| 6 |
# on the parent table for several reasons: |
| 7 |
# Although SR correctly collected FK-referenced keys to parent, TOI in Galera |
| 8 |
# disregards common certification index and simply sets itself to depend on the |
| 9 |
# latest certified write set seqno. |
| 10 |
# Since this write set was the fragment of SR transaction, TOI was allowed to run in |
| 11 |
# parallel with SR presuming it would BF abort the latter. |
| 12 |
# |
| 13 |
# At the same time, DML transactions in the server don't grab MDL locks on FK-referenced |
| 14 |
# tables, thus parent table wasn't protected by an MDL lock from SR and it couldn't |
| 15 |
# provoke MDL lock conflict for TOI to BF abort SR transaction. |
| 16 |
# In InnoDB, DDL transactions grab shared MDL locks on child tables, which is not enough |
| 17 |
# to trigger MDL conflict in Galera. |
| 18 |
# InnoDB-level Wsrep patch didn't contain correct conflict resolution logic due to the |
| 19 |
# fact that it was believed MDL locking should always produce conflicts correctly. |
| 20 |
# |
| 21 |
# The fix brings conflict resolution rules similar to MDL-level checks to InnoDB, thus |
| 22 |
# accounting for the problematic case. |
| 23 |
# |
| 24 |
|
| 25 |
--source include/galera_cluster.inc |
| 26 |
--source include/have_innodb.inc |
| 27 |
|
| 28 |
--connection node_1 |
| 29 |
CREATE TABLE parent (id INT AUTO_INCREMENT PRIMARY KEY, v INT) ENGINE=InnoDB; |
| 30 |
INSERT INTO parent VALUES (1, 1),(2, 2),(3, 3); |
| 31 |
|
| 32 |
CREATE TABLE child (id INT AUTO_INCREMENT PRIMARY KEY, parent_id INT, CONSTRAINT parent_fk |
| 33 |
FOREIGN KEY (parent_id) REFERENCES parent (id)) ENGINE=InnoDB; |
| 34 |
|
| 35 |
--connection node_2 |
| 36 |
# Start SR transaction and make it lock both parent and child tales. |
| 37 |
SET SESSION wsrep_trx_fragment_size = 1; |
| 38 |
START TRANSACTION; |
| 39 |
INSERT INTO child (parent_id) VALUES (1),(2),(3); |
| 40 |
|
| 41 |
--connection node_1 |
| 42 |
# Sync wait for SR transaction to replicate and apply fragments, thus |
| 43 |
# locking parent table as well. |
| 44 |
SET SESSION wsrep_sync_wait = 15; |
| 45 |
SELECT COUNT(*) FROM child; |
| 46 |
# Now run TOI on the parent, which BF-aborts the SR-transaction in progress. |
| 47 |
ALTER TABLE parent AUTO_INCREMENT = 100; |
| 48 |
|
| 49 |
--connection node_2 |
| 50 |
# Check that SR is BF-aborted. |
| 51 |
--error ER_LOCK_DEADLOCK |
| 52 |
COMMIT; |
| 53 |
|
| 54 |
# Cleanup |
| 55 |
DROP TABLE child, parent; |
| 56 |
--source include/galera_end.inc |