| 1 |
--source include/have_innodb.inc |
| 2 |
--source include/have_debug.inc |
| 3 |
--source include/have_debug_sync.inc |
| 4 |
--let $rpl_topology=1->2 |
| 5 |
--source include/rpl_init.inc |
| 6 |
|
| 7 |
call mtr.add_suppression("Slave: Commit failed due to failure of an earlier commit"); |
| 8 |
call mtr.add_suppression("Slave: Duplicate entry '99'"); |
| 9 |
|
| 10 |
--connection server_1 |
| 11 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 12 |
CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB; |
| 13 |
INSERT INTO t1 VALUES(1,1); # hit a dup entry on slave |
| 14 |
INSERT INTO t1 VALUES(2,1); # races to "win" the last exit |
| 15 |
INSERT INTO t1 VALUES(3,1); |
| 16 |
INSERT INTO t1 VALUES(4,1); # make W3 race over W1 |
| 17 |
--save_master_pos |
| 18 |
|
| 19 |
--connection server_2 |
| 20 |
--sync_with_master |
| 21 |
SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; |
| 22 |
--source include/stop_slave.inc |
| 23 |
SET @old_debug_dbug = @@global.debug_dbug; |
| 24 |
# In a group of W1,W2,W3 of the same batch W2 simulates slowness. |
| 25 |
SET @@global.debug_dbug = "d,hold_worker2_favor_worker3"; |
| 26 |
SET GLOBAL slave_parallel_threads=4; |
| 27 |
CHANGE MASTER TO master_use_gtid=slave_pos; |
| 28 |
SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode; |
| 29 |
SET GLOBAL slave_parallel_mode='optimistic'; |
| 30 |
|
| 31 |
# MDEV-30780 optimistic parallel slave hangs after hit an error |
| 32 |
# Test workers hang scenario to prove it's no more neither |
| 33 |
# out-of-order access to the active gco list. |
| 34 |
# |
| 35 |
# The test provides how to reproduce on the OLD version, false by default. |
| 36 |
# That branch approximates the original hang with an assert that |
| 37 |
# confirms the OLD version indeed could access already reclaimed gco. |
| 38 |
--let $old_version_regression=0 |
| 39 |
|
| 40 |
|
| 41 |
--connection server_1 |
| 42 |
|
| 43 |
# Let W1,W2,W3,W4 parallel workers that are going to execute |
| 44 |
# the following transaction. |
| 45 |
# W1 holds on with the 1st statement |
| 46 |
# then crashes W3 with the 2nd into retry, |
| 47 |
# finally hits with the 3rd a dup entry, on slave. |
| 48 |
SET @@gtid_seq_no = 2001; |
| 49 |
BEGIN; |
| 50 |
UPDATE t1 SET b = 11 WHERE a = 4; |
| 51 |
UPDATE t1 SET b = 11 WHERE a = 3; |
| 52 |
UPDATE t1 SET a = 99 WHERE a = 1; |
| 53 |
COMMIT; |
| 54 |
# In the buggy version W2 races to "win" the exit last (of W1..3) |
| 55 |
# and by that to access last a gco struct, garbage-collected. |
| 56 |
UPDATE t1 SET b = 2 WHERE a = 2; |
| 57 |
# W3 garbage-collects the gco struct in the buggy version. |
| 58 |
UPDATE t1 SET b = 3 WHERE a = 3; |
| 59 |
# W4 resides in following "singleton" batch to a W2 replacement |
| 60 |
# in the buggy version to allow W3 reclaim the batch's gco. |
| 61 |
DROP TABLE IF EXISTS phantom_1; |
| 62 |
|
| 63 |
--source include/save_master_gtid.inc |
| 64 |
|
| 65 |
--connect (slave_local_0, 127.0.0.1, root,, test, $SLAVE_MYPORT,) |
| 66 |
begin; |
| 67 |
UPDATE t1 set b = 11 where a = 4; |
| 68 |
--connect (slave_local_1, 127.0.0.1, root,, test, $SLAVE_MYPORT,) |
| 69 |
begin; |
| 70 |
INSERT INTO t1 VALUES (99, 11); |
| 71 |
|
| 72 |
--connect (slave_local_2, 127.0.0.1, root,, test, $SLAVE_MYPORT,) |
| 73 |
begin; |
| 74 |
UPDATE t1 SET b = 12 WHERE a = 2; |
| 75 |
|
| 76 |
--connect (slave_local_3, 127.0.0.1, root,, test, $SLAVE_MYPORT,) |
| 77 |
begin; |
| 78 |
UPDATE t1 SET b = 13 WHERE a = 3; |
| 79 |
|
| 80 |
--connection server_2 |
| 81 |
--source include/start_slave.inc |
| 82 |
|
| 83 |
--echo # W4 is waiting to start its DROP |
| 84 |
|
| 85 |
--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to start commit%" |
| 86 |
--source include/wait_condition.inc |
| 87 |
|
| 88 |
--connection slave_local_3 |
| 89 |
# make W3 to set E.cc <- 1 |
| 90 |
rollback; |
| 91 |
--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%" |
| 92 |
--source include/wait_condition.inc |
| 93 |
|
| 94 |
--connection slave_local_0 |
| 95 |
# make W3 into retry and delay it to let W1 hit a dupicate error first, |
| 96 |
# see 'commit' by slave_local_1. |
| 97 |
rollback; |
| 98 |
--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "debug sync point: now" |
| 99 |
--source include/wait_condition.inc |
| 100 |
SELECT count(*) = 0 as "W3 undid its commit state" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%"; |
| 101 |
|
| 102 |
|
| 103 |
--connection slave_local_2 |
| 104 |
rollback; |
| 105 |
# wait for W2 to start committing E.cc <- 2 |
| 106 |
--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state like "Waiting for prior transaction to commit" |
| 107 |
--source include/wait_condition.inc |
| 108 |
|
| 109 |
--connection slave_local_1 |
| 110 |
|
| 111 |
# W1 errors out |
| 112 |
# A. to alert W3 |
| 113 |
# B. W3 will *not* wake up W4 in the fixed version, having to wait for W2 demise. |
| 114 |
# C. W2 will notify W3 that releases W4 as it would do in normal cases. |
| 115 |
commit; |
| 116 |
|
| 117 |
if (!$old_version_regression) |
| 118 |
{ |
| 119 |
# A. In the fixed version show-processlist W4 is still in the ordered waiting |
| 120 |
SELECT COUNT(*) = 1 as "W4 remains with the same status" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to start commit%"; |
| 121 |
--let $status= query_get_value("show slave status", Slave_SQL_Running, 1) |
| 122 |
--echo # Slave_SQL_Running YES = $status |
| 123 |
|
| 124 |
# B. In the fixed version W3 is waiting for W2,... |
| 125 |
--let $wait_condition= SELECT count(*) = 1 as "W4 is waiting" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%" |
| 126 |
--source include/wait_condition.inc |
| 127 |
--echo # while W2 is held back ... |
| 128 |
--let $wait_condition= SELECT count(*) = 1 as "W2 simulates slowness" FROM information_schema.processlist WHERE state LIKE "debug sync point: now" |
| 129 |
--source include/wait_condition.inc |
| 130 |
|
| 131 |
# C. # ...until NOW. |
| 132 |
SET DEBUG_SYNC = 'now SIGNAL cont_worker2'; |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
# To reproduce the hang on the OLD version ... |
| 137 |
if ($old_version_regression) |
| 138 |
{ |
| 139 |
# replace the actual fixes block with checking W3,W4 have actually committed, |
| 140 |
# followed by signaling to W2 like on behalf of W4 which would end up in the hang. |
| 141 |
--let $wait_condition= SELECT COUNT(*) = 0 as "W4 has moved on" FROM information_schema.processlist WHERE state like "Waiting for prior transaction to start commit" |
| 142 |
--source include/wait_condition.inc |
| 143 |
--let $wait_condition= SELECT count(*) = 0 as "W3 does not wait on W2" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%" |
| 144 |
--source include/wait_condition.inc |
| 145 |
|
| 146 |
--let $wait_condition= SELECT count(*) = 1 as "W2 simulates slowness" FROM information_schema.processlist WHERE state LIKE "debug sync point: now" |
| 147 |
--source include/wait_condition.inc |
| 148 |
|
| 149 |
# Like above, but signaling is done after W4 is done to violate the commit order |
| 150 |
# that must fire a debug assert. |
| 151 |
SET DEBUG_SYNC = 'now SIGNAL cont_worker2'; |
| 152 |
} |
| 153 |
|
| 154 |
--let $slave_sql_errno= 1062 |
| 155 |
--source include/wait_for_slave_sql_error.inc |
| 156 |
|
| 157 |
# Restore the slave data and resume with replication |
| 158 |
DELETE FROM t1 WHERE a=99; |
| 159 |
--source include/start_slave.inc |
| 160 |
--source include/sync_with_master_gtid.inc |
| 161 |
|
| 162 |
# |
| 163 |
# Clean up. |
| 164 |
# |
| 165 |
--connection server_2 |
| 166 |
--source include/stop_slave.inc |
| 167 |
SET GLOBAL slave_parallel_mode=@old_parallel_mode; |
| 168 |
SET GLOBAL slave_parallel_threads=@old_parallel_threads; |
| 169 |
SET @@global.debug_dbug = @old_debug_dbug; |
| 170 |
SET debug_sync = RESET; |
| 171 |
--source include/start_slave.inc |
| 172 |
|
| 173 |
--connection server_1 |
| 174 |
DROP TABLE t1; |
| 175 |
--source include/save_master_gtid.inc |
| 176 |
|
| 177 |
--connection server_2 |
| 178 |
--source include/sync_with_master_gtid.inc |
| 179 |
|
| 180 |
--source include/rpl_end.inc |