| 1 |
# |
| 2 |
# MDEV-36360: Don't grab table-level X locks for applied inserts. |
| 3 |
# |
| 4 |
# It prevents a debug crash in wsrep_report_error() which happened when appliers would run |
| 5 |
# with FK and UK checks disabled and erroneously execute plain inserts as bulk inserts. |
| 6 |
# |
| 7 |
# Moreover, in release builds such a behavior could lead to deadlocks between two applier |
| 8 |
# threads if a thread waiting for a table-level lock was ordered before the lock holder. |
| 9 |
# In that case the lock holder would proceed to commit order and wait forever for the |
| 10 |
# now-blocked other applier thread to commit before. |
| 11 |
# |
| 12 |
|
| 13 |
--source include/galera_cluster.inc |
| 14 |
--source include/have_innodb.inc |
| 15 |
--source include/have_debug_sync.inc |
| 16 |
--source include/have_debug.inc |
| 17 |
|
| 18 |
--let $galera_connection_name = node_3 |
| 19 |
--let $galera_server_number = 3 |
| 20 |
--source include/galera_connect.inc |
| 21 |
|
| 22 |
# Save original auto_increment_offset values. |
| 23 |
--let $node_1=node_1 |
| 24 |
--let $node_2=node_2 |
| 25 |
--let $node_3=node_3 |
| 26 |
--source ../galera/include/auto_increment_offset_save.inc |
| 27 |
|
| 28 |
# Create parent and child tables. |
| 29 |
--connection node_1 |
| 30 |
CREATE TABLE parent ( |
| 31 |
id INT PRIMARY KEY |
| 32 |
) ENGINE=InnoDB; |
| 33 |
|
| 34 |
CREATE TABLE child ( |
| 35 |
id INT PRIMARY KEY, |
| 36 |
parent_id INT, |
| 37 |
KEY (parent_id), |
| 38 |
CONSTRAINT FOREIGN KEY (parent_id) REFERENCES parent(id) |
| 39 |
) ENGINE=InnoDB; |
| 40 |
|
| 41 |
# Fill the parent table with rows that will later be used by the child. |
| 42 |
INSERT INTO parent VALUES (1), (2); |
| 43 |
|
| 44 |
# Wait until the rows are replicated on node #3. |
| 45 |
--connection node_3 |
| 46 |
--let $wait_condition = SELECT COUNT(*) = 2 FROM parent |
| 47 |
--source include/wait_condition.inc |
| 48 |
|
| 49 |
# Delete one row from the parent table on node #3 and rejoin the cluster. |
| 50 |
SET SESSION wsrep_on = OFF; |
| 51 |
DELETE FROM parent WHERE id = 1; |
| 52 |
SET SESSION wsrep_on = ON; |
| 53 |
--echo Restarting server 3 with one applier thread having FK and UK checks disabled |
| 54 |
--source include/shutdown_mysqld.inc |
| 55 |
--let $start_mysqld_params = --wsrep_slave_FK_checks=0 --wsrep_slave_UK_checks=0 |
| 56 |
--source ../galera/include/start_mysqld.inc |
| 57 |
|
| 58 |
# Stop the applier after writing a row into the child table. |
| 59 |
SET GLOBAL DEBUG_DBUG = 'd,sync.wsrep_after_write_row'; |
| 60 |
|
| 61 |
# Insert a child row that will be applied on node #3, but should not |
| 62 |
# grab table-level X-lock. |
| 63 |
--connection node_1 |
| 64 |
INSERT INTO child VALUES (1, 2); |
| 65 |
|
| 66 |
--connection node_3 |
| 67 |
SET DEBUG_SYNC = 'now WAIT_FOR sync.wsrep_after_write_row_reached'; |
| 68 |
# Now that the applier has hit the global sync point wait, reset it |
| 69 |
# so that the upcoming insert avoids it. |
| 70 |
SET GLOBAL DEBUG_DBUG = ''; |
| 71 |
# Don't wait for applied insert to commit. |
| 72 |
SET wsrep_sync_wait = 0; |
| 73 |
SET DEBUG_SYNC = 'ib_after_row_insert SIGNAL signal.wsrep_after_write_row'; |
| 74 |
# The insert should pass the sync point, as otherwise if the applied insert |
| 75 |
# grabs table-level X-lock, they'll both deadlock forever. |
| 76 |
INSERT INTO child VALUES (2, 2); |
| 77 |
SET DEBUG_SYNC = 'RESET'; |
| 78 |
# Child row insert is applied even though there's no parent row. |
| 79 |
--echo Server 3 |
| 80 |
SELECT COUNT(*) AS EXPECT_1 FROM parent; |
| 81 |
SELECT COUNT(*) AS EXPECT_2 FROM child; |
| 82 |
|
| 83 |
# Check other nodes have both parent and child rows. |
| 84 |
--connection node_1 |
| 85 |
--echo Server 1 |
| 86 |
SET wsrep_sync_wait = 15; |
| 87 |
SELECT COUNT(*) AS EXPECT_2 FROM parent; |
| 88 |
SELECT COUNT(*) AS EXPECT_2 FROM child; |
| 89 |
|
| 90 |
--connection node_2 |
| 91 |
--echo Server 2 |
| 92 |
SET wsrep_sync_wait = 15; |
| 93 |
SELECT COUNT(*) AS EXPECT_2 FROM parent; |
| 94 |
SELECT COUNT(*) AS EXPECT_2 FROM child; |
| 95 |
|
| 96 |
DROP TABLE child; |
| 97 |
DROP TABLE parent; |
| 98 |
|
| 99 |
# Restore original auto_increment_offset values. |
| 100 |
--source ../galera/include/auto_increment_offset_restore.inc |
| 101 |
|
| 102 |
--source include/galera_end.inc |