| 1 |
--echo *** Test killing thread that is waiting to start transaction until previous transaction commits *** |
| 2 |
|
| 3 |
--source include/have_innodb.inc |
| 4 |
--source include/have_debug.inc |
| 5 |
--source include/have_debug_sync.inc |
| 6 |
--source include/have_binlog_format_statement.inc |
| 7 |
--source include/master-slave.inc |
| 8 |
|
| 9 |
--connection server_2 |
| 10 |
SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; |
| 11 |
SET @old_parallel_mode= @@GLOBAL.slave_parallel_mode; |
| 12 |
--source include/stop_slave.inc |
| 13 |
SET sql_log_bin=0; |
| 14 |
CALL mtr.add_suppression("Query execution was interrupted"); |
| 15 |
CALL mtr.add_suppression("Slave: Connection was killed"); |
| 16 |
CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); |
| 17 |
SET sql_log_bin=1; |
| 18 |
SET GLOBAL slave_parallel_threads=10; |
| 19 |
SET GLOBAL slave_parallel_mode= 'conservative'; |
| 20 |
CHANGE MASTER TO master_use_gtid=slave_pos; |
| 21 |
--source include/start_slave.inc |
| 22 |
|
| 23 |
--connection server_1 |
| 24 |
--connect (con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 25 |
--connect (con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 26 |
--connect (con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 27 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 28 |
CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; |
| 29 |
# MDEV-515 takes X-lock on the table for the first insert. |
| 30 |
# So concurrent insert won't happen on the table |
| 31 |
INSERT INTO t3 VALUES(100, 100); |
| 32 |
--save_master_pos |
| 33 |
|
| 34 |
--connection server_2 |
| 35 |
--sync_with_master |
| 36 |
|
| 37 |
--connection server_1 |
| 38 |
# Use a stored function to inject a debug_sync into the appropriate THD. |
| 39 |
# The function does nothing on the master, and on the slave it injects the |
| 40 |
# desired debug_sync action(s). |
| 41 |
SET sql_log_bin=0; |
| 42 |
--delimiter || |
| 43 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 44 |
RETURNS INT DETERMINISTIC |
| 45 |
BEGIN |
| 46 |
RETURN x; |
| 47 |
END |
| 48 |
|| |
| 49 |
--delimiter ; |
| 50 |
SET sql_log_bin=1; |
| 51 |
|
| 52 |
--connection server_2 |
| 53 |
SET sql_log_bin=0; |
| 54 |
--delimiter || |
| 55 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 56 |
RETURNS INT DETERMINISTIC |
| 57 |
BEGIN |
| 58 |
IF d1 != '' THEN |
| 59 |
SET debug_sync = d1; |
| 60 |
END IF; |
| 61 |
IF d2 != '' THEN |
| 62 |
SET debug_sync = d2; |
| 63 |
END IF; |
| 64 |
RETURN x; |
| 65 |
END |
| 66 |
|| |
| 67 |
--delimiter ; |
| 68 |
SET sql_log_bin=1; |
| 69 |
# We need to restart all parallel threads for the new global setting to |
| 70 |
# be copied to the session-level values. |
| 71 |
--source include/stop_slave.inc |
| 72 |
SET GLOBAL slave_parallel_threads=0; |
| 73 |
SET GLOBAL slave_parallel_threads=4; |
| 74 |
--source include/start_slave.inc |
| 75 |
|
| 76 |
|
| 77 |
# We set up four transactions T1, T2, T3, and T4 on the master. T2, T3, and T4 |
| 78 |
# can run in parallel with each other (same group commit and commit id), |
| 79 |
# but not in parallel with T1. |
| 80 |
# |
| 81 |
# We use four worker threads, each Ti will be queued on each their own |
| 82 |
# worker thread. We will delay T1 commit, T3 will wait for T1 to begin |
| 83 |
# commit before it can start. We will kill T3 during this wait, and |
| 84 |
# check that everything works correctly. |
| 85 |
# |
| 86 |
# It is rather tricky to get the correct thread id of the worker to kill. |
| 87 |
# We start by injecting four dummy transactions in a debug_sync-controlled |
| 88 |
# manner to be able to get known thread ids for the workers in a pool with |
| 89 |
# just 4 worker threads. Then we let in each of the real test transactions |
| 90 |
# T1-T4 one at a time in a way which allows us to know which transaction |
| 91 |
# ends up with which thread id. |
| 92 |
|
| 93 |
--connection server_1 |
| 94 |
SET gtid_domain_id=2; |
| 95 |
BEGIN; |
| 96 |
# This debug_sync will linger on and be used to control T4 later. |
| 97 |
INSERT INTO t3 VALUES (70, foo(70, |
| 98 |
'rpl_parallel_start_waiting_for_prior SIGNAL t4_waiting', '')); |
| 99 |
INSERT INTO t3 VALUES (60, foo(60, |
| 100 |
'ha_write_row_end SIGNAL d2_query WAIT_FOR d2_cont2', |
| 101 |
'rpl_parallel_end_of_group SIGNAL d2_done WAIT_FOR d2_cont')); |
| 102 |
COMMIT; |
| 103 |
SET gtid_domain_id=0; |
| 104 |
|
| 105 |
--connection server_2 |
| 106 |
SET debug_sync='now WAIT_FOR d2_query'; |
| 107 |
--let $d2_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(60%' AND INFO NOT LIKE '%LIKE%'` |
| 108 |
|
| 109 |
--connection server_1 |
| 110 |
SET gtid_domain_id=1; |
| 111 |
BEGIN; |
| 112 |
# These debug_sync's will linger on and be used to control T3 later. |
| 113 |
INSERT INTO t3 VALUES (61, foo(61, |
| 114 |
'rpl_parallel_start_waiting_for_prior SIGNAL t3_waiting', |
| 115 |
'rpl_parallel_start_waiting_for_prior_killed SIGNAL t3_killed')); |
| 116 |
INSERT INTO t3 VALUES (62, foo(62, |
| 117 |
'ha_write_row_end SIGNAL d1_query WAIT_FOR d1_cont2', |
| 118 |
'rpl_parallel_end_of_group SIGNAL d1_done WAIT_FOR d1_cont')); |
| 119 |
COMMIT; |
| 120 |
SET gtid_domain_id=0; |
| 121 |
|
| 122 |
--connection server_2 |
| 123 |
SET debug_sync='now WAIT_FOR d1_query'; |
| 124 |
--let $d1_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(62%' AND INFO NOT LIKE '%LIKE%'` |
| 125 |
|
| 126 |
--connection server_1 |
| 127 |
SET gtid_domain_id=0; |
| 128 |
INSERT INTO t3 VALUES (63, foo(63, |
| 129 |
'ha_write_row_end SIGNAL d0_query WAIT_FOR d0_cont2', |
| 130 |
'rpl_parallel_end_of_group SIGNAL d0_done WAIT_FOR d0_cont')); |
| 131 |
|
| 132 |
--connection server_2 |
| 133 |
SET debug_sync='now WAIT_FOR d0_query'; |
| 134 |
--let $d0_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(63%' AND INFO NOT LIKE '%LIKE%'` |
| 135 |
|
| 136 |
--connection server_1 |
| 137 |
SET gtid_domain_id=3; |
| 138 |
BEGIN; |
| 139 |
# These debug_sync's will linger on and be used to control T2 later. |
| 140 |
INSERT INTO t3 VALUES (68, foo(68, |
| 141 |
'rpl_parallel_start_waiting_for_prior SIGNAL t2_waiting', '')); |
| 142 |
INSERT INTO t3 VALUES (69, foo(69, |
| 143 |
'ha_write_row_end SIGNAL d3_query WAIT_FOR d3_cont2', |
| 144 |
'rpl_parallel_end_of_group SIGNAL d3_done WAIT_FOR d3_cont')); |
| 145 |
COMMIT; |
| 146 |
SET gtid_domain_id=0; |
| 147 |
|
| 148 |
--connection server_2 |
| 149 |
SET debug_sync='now WAIT_FOR d3_query'; |
| 150 |
--let $d3_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(69%' AND INFO NOT LIKE '%LIKE%'` |
| 151 |
|
| 152 |
SET debug_sync='now SIGNAL d2_cont2'; |
| 153 |
SET debug_sync='now WAIT_FOR d2_done'; |
| 154 |
SET debug_sync='now SIGNAL d1_cont2'; |
| 155 |
SET debug_sync='now WAIT_FOR d1_done'; |
| 156 |
SET debug_sync='now SIGNAL d0_cont2'; |
| 157 |
SET debug_sync='now WAIT_FOR d0_done'; |
| 158 |
SET debug_sync='now SIGNAL d3_cont2'; |
| 159 |
SET debug_sync='now WAIT_FOR d3_done'; |
| 160 |
|
| 161 |
# Now prepare the real transactions T1, T2, T3, T4 on the master. |
| 162 |
|
| 163 |
--connection con_temp3 |
| 164 |
# Create transaction T1. |
| 165 |
INSERT INTO t3 VALUES (64, foo(64, |
| 166 |
'rpl_parallel_before_mark_start_commit SIGNAL t1_waiting WAIT_FOR t1_cont', '')); |
| 167 |
|
| 168 |
# Create transaction T2, as a group commit leader on the master. |
| 169 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2 WAIT_FOR master_cont2'; |
| 170 |
send INSERT INTO t3 VALUES (65, foo(65, '', '')); |
| 171 |
|
| 172 |
--connection server_1 |
| 173 |
SET debug_sync='now WAIT_FOR master_queued2'; |
| 174 |
|
| 175 |
--connection con_temp4 |
| 176 |
# Create transaction T3, participating in T2's group commit. |
| 177 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; |
| 178 |
send INSERT INTO t3 VALUES (66, foo(66, '', '')); |
| 179 |
|
| 180 |
--connection server_1 |
| 181 |
SET debug_sync='now WAIT_FOR master_queued3'; |
| 182 |
|
| 183 |
--connection con_temp5 |
| 184 |
# Create transaction T4, participating in group commit with T2 and T3. |
| 185 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued4'; |
| 186 |
send INSERT INTO t3 VALUES (67, foo(67, '', '')); |
| 187 |
|
| 188 |
--connection server_1 |
| 189 |
SET debug_sync='now WAIT_FOR master_queued4'; |
| 190 |
SET debug_sync='now SIGNAL master_cont2'; |
| 191 |
|
| 192 |
--connection con_temp3 |
| 193 |
REAP; |
| 194 |
--connection con_temp4 |
| 195 |
REAP; |
| 196 |
--connection con_temp5 |
| 197 |
REAP; |
| 198 |
|
| 199 |
--connection server_1 |
| 200 |
SELECT * FROM t3 WHERE a >= 60 ORDER BY a; |
| 201 |
SET debug_sync='RESET'; |
| 202 |
|
| 203 |
--connection server_2 |
| 204 |
# Now we have the four transactions pending for replication on the slave. |
| 205 |
# Let them be queued for our three worker threads in a controlled fashion. |
| 206 |
# We put them at a stage where T1 is delayed and T3 is waiting for T1 to |
| 207 |
# commit before T3 can start. Then we kill T3. |
| 208 |
|
| 209 |
# Make the worker D0 free, and wait for T1 to be queued in it. |
| 210 |
SET debug_sync='now SIGNAL d0_cont'; |
| 211 |
SET debug_sync='now WAIT_FOR t1_waiting'; |
| 212 |
|
| 213 |
# Make the worker D3 free, and wait for T2 to be queued in it. |
| 214 |
SET debug_sync='now SIGNAL d3_cont'; |
| 215 |
SET debug_sync='now WAIT_FOR t2_waiting'; |
| 216 |
|
| 217 |
# Now release worker D1, and wait for T3 to be queued in it. |
| 218 |
# T3 will wait for T1 to commit before it can start. |
| 219 |
SET debug_sync='now SIGNAL d1_cont'; |
| 220 |
SET debug_sync='now WAIT_FOR t3_waiting'; |
| 221 |
|
| 222 |
# Release worker D2. Wait for T4 to be queued, so we are sure it has |
| 223 |
# received the debug_sync signal (else we might overwrite it with the |
| 224 |
# next debug_sync). |
| 225 |
SET debug_sync='now SIGNAL d2_cont'; |
| 226 |
SET debug_sync='now WAIT_FOR t4_waiting'; |
| 227 |
|
| 228 |
# Now we kill the waiting transaction T3 in worker D1. |
| 229 |
--replace_result $d1_thd_id THD_ID |
| 230 |
eval KILL $d1_thd_id; |
| 231 |
|
| 232 |
# Wait until T3 has reacted on the kill. |
| 233 |
SET debug_sync='now WAIT_FOR t3_killed'; |
| 234 |
|
| 235 |
# Now we can allow T1 to proceed. |
| 236 |
SET debug_sync='now SIGNAL t1_cont'; |
| 237 |
|
| 238 |
--let $slave_sql_errno= 1317,1927,1964 |
| 239 |
--source include/wait_for_slave_sql_error.inc |
| 240 |
STOP SLAVE IO_THREAD; |
| 241 |
# Since T2, T3, and T4 run in parallel, we can not be sure if T2 will have time |
| 242 |
# to commit or not before the stop. However, T1 should commit, and T3/T4 may |
| 243 |
# not have committed. (After slave restart we check that all become committed |
| 244 |
# eventually). |
| 245 |
SELECT * FROM t3 WHERE a >= 60 AND a != 65 ORDER BY a; |
| 246 |
|
| 247 |
# Now we have to disable the debug_sync statements, so they do not trigger |
| 248 |
# when the events are retried. |
| 249 |
SET debug_sync='RESET'; |
| 250 |
SET GLOBAL slave_parallel_threads=0; |
| 251 |
SET GLOBAL slave_parallel_threads=10; |
| 252 |
SET sql_log_bin=0; |
| 253 |
DROP FUNCTION foo; |
| 254 |
--delimiter || |
| 255 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 256 |
RETURNS INT DETERMINISTIC |
| 257 |
BEGIN |
| 258 |
RETURN x; |
| 259 |
END |
| 260 |
|| |
| 261 |
--delimiter ; |
| 262 |
SET sql_log_bin=1; |
| 263 |
|
| 264 |
--connection server_1 |
| 265 |
UPDATE t3 SET b=b+1 WHERE a=60; |
| 266 |
--save_master_pos |
| 267 |
|
| 268 |
--connection server_2 |
| 269 |
--source include/start_slave.inc |
| 270 |
--sync_with_master |
| 271 |
SELECT * FROM t3 WHERE a >= 60 ORDER BY a; |
| 272 |
# Restore the foo() function. |
| 273 |
SET sql_log_bin=0; |
| 274 |
DROP FUNCTION foo; |
| 275 |
--delimiter || |
| 276 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 277 |
RETURNS INT DETERMINISTIC |
| 278 |
BEGIN |
| 279 |
IF d1 != '' THEN |
| 280 |
SET debug_sync = d1; |
| 281 |
END IF; |
| 282 |
IF d2 != '' THEN |
| 283 |
SET debug_sync = d2; |
| 284 |
END IF; |
| 285 |
RETURN x; |
| 286 |
END |
| 287 |
|| |
| 288 |
--delimiter ; |
| 289 |
SET sql_log_bin=1; |
| 290 |
|
| 291 |
--connection server_2 |
| 292 |
# Respawn all worker threads to clear any left-over debug_sync or other stuff. |
| 293 |
--source include/stop_slave.inc |
| 294 |
SET GLOBAL slave_parallel_threads=0; |
| 295 |
SET GLOBAL slave_parallel_threads=10; |
| 296 |
--source include/start_slave.inc |
| 297 |
|
| 298 |
--echo *** 5. Test killing thread that is waiting for queue of max length to shorten *** |
| 299 |
|
| 300 |
# Find the thread id of the driver SQL thread that we want to kill. |
| 301 |
--let $wait_condition= SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE '%Slave has read all relay log%' |
| 302 |
--source include/wait_condition.inc |
| 303 |
--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND LIKE 'Slave_SQL'` |
| 304 |
SET @old_max_queued= @@GLOBAL.slave_parallel_max_queued; |
| 305 |
SET GLOBAL slave_parallel_max_queued=9000; |
| 306 |
|
| 307 |
--connection server_1 |
| 308 |
--let bigstring= `SELECT REPEAT('x', 10000)` |
| 309 |
# Create an event that will wait to be signalled. |
| 310 |
INSERT INTO t3 VALUES (80, foo(0, |
| 311 |
'ha_write_row_end SIGNAL query_waiting WAIT_FOR query_cont', '')); |
| 312 |
|
| 313 |
--connection server_2 |
| 314 |
SET debug_sync='now WAIT_FOR query_waiting'; |
| 315 |
# Inject that the SQL driver thread will signal `wait_queue_ready' to debug_sync |
| 316 |
# as it goes to wait for the event queue to become smaller than the value of |
| 317 |
# @@slave_parallel_max_queued. |
| 318 |
SET @old_dbug= @@GLOBAL.debug_dbug; |
| 319 |
SET GLOBAL debug_dbug="+d,rpl_parallel_wait_queue_max"; |
| 320 |
|
| 321 |
--connection server_1 |
| 322 |
--disable_query_log |
| 323 |
# Create an event that will fill up the queue. |
| 324 |
# The Xid event at the end of the event group will have to wait for the Query |
| 325 |
# event with the INSERT to drain so the queue becomes shorter. However that in |
| 326 |
# turn waits for the prior event group to continue. |
| 327 |
eval INSERT INTO t3 VALUES (81, LENGTH('$bigstring')); |
| 328 |
--enable_query_log |
| 329 |
SELECT * FROM t3 WHERE a >= 80 ORDER BY a; |
| 330 |
|
| 331 |
--connection server_2 |
| 332 |
SET debug_sync='now WAIT_FOR wait_queue_ready'; |
| 333 |
|
| 334 |
--replace_result $thd_id THD_ID |
| 335 |
eval KILL $thd_id; |
| 336 |
|
| 337 |
SET debug_sync='now WAIT_FOR wait_queue_killed'; |
| 338 |
SET debug_sync='now SIGNAL query_cont'; |
| 339 |
|
| 340 |
--let $slave_sql_errno= 1317,1927,1964 |
| 341 |
--source include/wait_for_slave_sql_error.inc |
| 342 |
STOP SLAVE IO_THREAD; |
| 343 |
|
| 344 |
SET GLOBAL debug_dbug=@old_dbug; |
| 345 |
SET GLOBAL slave_parallel_max_queued= @old_max_queued; |
| 346 |
|
| 347 |
--connection server_1 |
| 348 |
INSERT INTO t3 VALUES (82,0); |
| 349 |
--save_master_pos |
| 350 |
|
| 351 |
--connection server_2 |
| 352 |
SET debug_sync='RESET'; |
| 353 |
--source include/start_slave.inc |
| 354 |
--sync_with_master |
| 355 |
SELECT * FROM t3 WHERE a >= 80 ORDER BY a; |
| 356 |
|
| 357 |
--connection server_2 |
| 358 |
--source include/stop_slave.inc |
| 359 |
SET GLOBAL slave_parallel_mode=@old_parallel_mode; |
| 360 |
SET GLOBAL slave_parallel_threads=@old_parallel_threads; |
| 361 |
--source include/start_slave.inc |
| 362 |
SET DEBUG_SYNC= 'RESET'; |
| 363 |
|
| 364 |
--connection server_1 |
| 365 |
DROP function foo; |
| 366 |
DROP TABLE t3; |
| 367 |
SET DEBUG_SYNC= 'RESET'; |
| 368 |
|
| 369 |
--source include/rpl_end.inc |