| 1 |
--echo *** Test killing slave threads at various wait points *** |
| 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 |
# Test various aspects of parallel replication. |
| 10 |
|
| 11 |
--connection server_2 |
| 12 |
SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; |
| 13 |
SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode; |
| 14 |
--source include/stop_slave.inc |
| 15 |
SET GLOBAL slave_parallel_threads=10; |
| 16 |
SET GLOBAL slave_parallel_mode='conservative'; |
| 17 |
CHANGE MASTER TO master_use_gtid=slave_pos; |
| 18 |
--source include/start_slave.inc |
| 19 |
|
| 20 |
--connection server_1 |
| 21 |
--connect (con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 22 |
--connect (con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 23 |
--connect (con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 24 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 25 |
CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM; |
| 26 |
CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB; |
| 27 |
CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; |
| 28 |
# MDEV-515 takes X-lock on the table for the first insert. |
| 29 |
# So concurrent insert won't happen on the table |
| 30 |
INSERT INTO t2 VALUES(100); |
| 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 |
|
| 70 |
--echo *** 1. Test killing transaction waiting in commit for previous transaction to commit *** |
| 71 |
|
| 72 |
# Set up three transactions on the master that will be group-committed |
| 73 |
# together so they can be replicated in parallel on the slave. |
| 74 |
--connection con_temp3 |
| 75 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; |
| 76 |
send INSERT INTO t3 VALUES (31, foo(31, |
| 77 |
'commit_before_prepare_ordered WAIT_FOR t2_waiting', |
| 78 |
'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); |
| 79 |
|
| 80 |
--connection server_1 |
| 81 |
SET debug_sync='now WAIT_FOR master_queued1'; |
| 82 |
|
| 83 |
--connection con_temp4 |
| 84 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; |
| 85 |
BEGIN; |
| 86 |
# This insert is just so we can get T2 to wait while a query is running that we |
| 87 |
# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. |
| 88 |
INSERT INTO t3 VALUES (32, foo(32, |
| 89 |
'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', |
| 90 |
'')); |
| 91 |
# This insert sets up debug_sync points so that T2 will tell when it is at its |
| 92 |
# wait point where we want to kill it - and when it has been killed. |
| 93 |
INSERT INTO t3 VALUES (33, foo(33, |
| 94 |
'group_commit_waiting_for_prior SIGNAL t2_waiting', |
| 95 |
'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); |
| 96 |
send COMMIT; |
| 97 |
|
| 98 |
--connection server_1 |
| 99 |
SET debug_sync='now WAIT_FOR master_queued2'; |
| 100 |
|
| 101 |
--connection con_temp5 |
| 102 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; |
| 103 |
send INSERT INTO t3 VALUES (34, foo(34, |
| 104 |
'', |
| 105 |
'')); |
| 106 |
|
| 107 |
--connection server_1 |
| 108 |
SET debug_sync='now WAIT_FOR master_queued3'; |
| 109 |
SET debug_sync='now SIGNAL master_cont1'; |
| 110 |
|
| 111 |
--connection con_temp3 |
| 112 |
REAP; |
| 113 |
--connection con_temp4 |
| 114 |
REAP; |
| 115 |
--connection con_temp5 |
| 116 |
REAP; |
| 117 |
|
| 118 |
--connection server_1 |
| 119 |
SELECT * FROM t3 WHERE a >= 30 ORDER BY a; |
| 120 |
SET debug_sync='RESET'; |
| 121 |
|
| 122 |
--connection server_2 |
| 123 |
SET sql_log_bin=0; |
| 124 |
CALL mtr.add_suppression("Query execution was interrupted"); |
| 125 |
CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); |
| 126 |
CALL mtr.add_suppression("Slave: Connection was killed"); |
| 127 |
SET sql_log_bin=1; |
| 128 |
# Wait until T2 is inside executing its insert of 32, then find it in SHOW |
| 129 |
# PROCESSLIST to know its thread id for KILL later. |
| 130 |
SET debug_sync='now WAIT_FOR t2_query'; |
| 131 |
--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(32%' AND INFO NOT LIKE '%LIKE%'` |
| 132 |
SET debug_sync='now SIGNAL t2_cont'; |
| 133 |
|
| 134 |
# Wait until T2 has entered its wait for T1 to commit, and T1 has |
| 135 |
# progressed into its commit phase. |
| 136 |
SET debug_sync='now WAIT_FOR t1_ready'; |
| 137 |
|
| 138 |
# Now kill the transaction T2. |
| 139 |
--replace_result $thd_id THD_ID |
| 140 |
eval KILL $thd_id; |
| 141 |
|
| 142 |
# Wait until T2 has reacted on the kill. |
| 143 |
SET debug_sync='now WAIT_FOR t2_killed'; |
| 144 |
|
| 145 |
# Now we can allow T1 to proceed. |
| 146 |
SET debug_sync='now SIGNAL t1_cont'; |
| 147 |
|
| 148 |
--let $slave_sql_errno= 1317,1927,1964 |
| 149 |
--source include/wait_for_slave_sql_error.inc |
| 150 |
STOP SLAVE IO_THREAD; |
| 151 |
SELECT * FROM t3 WHERE a >= 30 ORDER BY a; |
| 152 |
|
| 153 |
# Now we have to disable the debug_sync statements, so they do not trigger |
| 154 |
# when the events are retried. |
| 155 |
SET debug_sync='RESET'; |
| 156 |
SET GLOBAL slave_parallel_threads=0; |
| 157 |
SET GLOBAL slave_parallel_threads=10; |
| 158 |
SET sql_log_bin=0; |
| 159 |
DROP FUNCTION foo; |
| 160 |
--delimiter || |
| 161 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 162 |
RETURNS INT DETERMINISTIC |
| 163 |
BEGIN |
| 164 |
RETURN x; |
| 165 |
END |
| 166 |
|| |
| 167 |
--delimiter ; |
| 168 |
SET sql_log_bin=1; |
| 169 |
|
| 170 |
--connection server_1 |
| 171 |
INSERT INTO t3 VALUES (39,0); |
| 172 |
--save_master_pos |
| 173 |
|
| 174 |
--connection server_2 |
| 175 |
--source include/start_slave.inc |
| 176 |
--sync_with_master |
| 177 |
SELECT * FROM t3 WHERE a >= 30 ORDER BY a; |
| 178 |
# Restore the foo() function. |
| 179 |
SET sql_log_bin=0; |
| 180 |
DROP FUNCTION foo; |
| 181 |
--delimiter || |
| 182 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 183 |
RETURNS INT DETERMINISTIC |
| 184 |
BEGIN |
| 185 |
IF d1 != '' THEN |
| 186 |
SET debug_sync = d1; |
| 187 |
END IF; |
| 188 |
IF d2 != '' THEN |
| 189 |
SET debug_sync = d2; |
| 190 |
END IF; |
| 191 |
RETURN x; |
| 192 |
END |
| 193 |
|| |
| 194 |
--delimiter ; |
| 195 |
SET sql_log_bin=1; |
| 196 |
|
| 197 |
|
| 198 |
--connection server_2 |
| 199 |
# Respawn all worker threads to clear any left-over debug_sync or other stuff. |
| 200 |
--source include/stop_slave.inc |
| 201 |
SET GLOBAL slave_parallel_threads=0; |
| 202 |
SET GLOBAL slave_parallel_threads=10; |
| 203 |
--source include/start_slave.inc |
| 204 |
|
| 205 |
|
| 206 |
--echo *** 2. Same as (1), but without restarting IO thread after kill of SQL threads *** |
| 207 |
|
| 208 |
# Set up three transactions on the master that will be group-committed |
| 209 |
# together so they can be replicated in parallel on the slave. |
| 210 |
--connection con_temp3 |
| 211 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; |
| 212 |
send INSERT INTO t3 VALUES (41, foo(41, |
| 213 |
'commit_before_prepare_ordered WAIT_FOR t2_waiting', |
| 214 |
'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); |
| 215 |
|
| 216 |
--connection server_1 |
| 217 |
SET debug_sync='now WAIT_FOR master_queued1'; |
| 218 |
|
| 219 |
--connection con_temp4 |
| 220 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; |
| 221 |
BEGIN; |
| 222 |
# This insert is just so we can get T2 to wait while a query is running that we |
| 223 |
# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. |
| 224 |
INSERT INTO t3 VALUES (42, foo(42, |
| 225 |
'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', |
| 226 |
'')); |
| 227 |
# This insert sets up debug_sync points so that T2 will tell when it is at its |
| 228 |
# wait point where we want to kill it - and when it has been killed. |
| 229 |
INSERT INTO t3 VALUES (43, foo(43, |
| 230 |
'group_commit_waiting_for_prior SIGNAL t2_waiting', |
| 231 |
'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); |
| 232 |
send COMMIT; |
| 233 |
|
| 234 |
--connection server_1 |
| 235 |
SET debug_sync='now WAIT_FOR master_queued2'; |
| 236 |
|
| 237 |
--connection con_temp5 |
| 238 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; |
| 239 |
send INSERT INTO t3 VALUES (44, foo(44, |
| 240 |
'', |
| 241 |
'')); |
| 242 |
|
| 243 |
--connection server_1 |
| 244 |
SET debug_sync='now WAIT_FOR master_queued3'; |
| 245 |
SET debug_sync='now SIGNAL master_cont1'; |
| 246 |
|
| 247 |
--connection con_temp3 |
| 248 |
REAP; |
| 249 |
--connection con_temp4 |
| 250 |
REAP; |
| 251 |
--connection con_temp5 |
| 252 |
REAP; |
| 253 |
|
| 254 |
--connection server_1 |
| 255 |
SELECT * FROM t3 WHERE a >= 40 ORDER BY a; |
| 256 |
SET debug_sync='RESET'; |
| 257 |
|
| 258 |
--connection server_2 |
| 259 |
# Wait until T2 is inside executing its insert of 42, then find it in SHOW |
| 260 |
# PROCESSLIST to know its thread id for KILL later. |
| 261 |
SET debug_sync='now WAIT_FOR t2_query'; |
| 262 |
--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(42%' AND INFO NOT LIKE '%LIKE%'` |
| 263 |
SET debug_sync='now SIGNAL t2_cont'; |
| 264 |
|
| 265 |
# Wait until T2 has entered its wait for T1 to commit, and T1 has |
| 266 |
# progressed into its commit phase. |
| 267 |
SET debug_sync='now WAIT_FOR t1_ready'; |
| 268 |
|
| 269 |
# Now kill the transaction T2. |
| 270 |
--replace_result $thd_id THD_ID |
| 271 |
eval KILL $thd_id; |
| 272 |
|
| 273 |
# Wait until T2 has reacted on the kill. |
| 274 |
SET debug_sync='now WAIT_FOR t2_killed'; |
| 275 |
|
| 276 |
# Now we can allow T1 to proceed. |
| 277 |
SET debug_sync='now SIGNAL t1_cont'; |
| 278 |
|
| 279 |
--let $slave_sql_errno= 1317,1927,1964 |
| 280 |
--source include/wait_for_slave_sql_error.inc |
| 281 |
|
| 282 |
# Now we have to disable the debug_sync statements, so they do not trigger |
| 283 |
# when the events are retried. |
| 284 |
SET debug_sync='RESET'; |
| 285 |
SET GLOBAL slave_parallel_threads=0; |
| 286 |
SET GLOBAL slave_parallel_threads=10; |
| 287 |
SET sql_log_bin=0; |
| 288 |
DROP FUNCTION foo; |
| 289 |
--delimiter || |
| 290 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 291 |
RETURNS INT DETERMINISTIC |
| 292 |
BEGIN |
| 293 |
RETURN x; |
| 294 |
END |
| 295 |
|| |
| 296 |
--delimiter ; |
| 297 |
SET sql_log_bin=1; |
| 298 |
--source include/stop_slave_io.inc |
| 299 |
--connection server_1 |
| 300 |
INSERT INTO t3 VALUES (49,0); |
| 301 |
--save_master_pos |
| 302 |
|
| 303 |
--connection server_2 |
| 304 |
CHANGE MASTER TO master_use_gtid=no; |
| 305 |
--source include/start_slave.inc |
| 306 |
--sync_with_master |
| 307 |
SELECT * FROM t3 WHERE a >= 40 ORDER BY a; |
| 308 |
# Restore the foo() function. |
| 309 |
SET sql_log_bin=0; |
| 310 |
DROP FUNCTION foo; |
| 311 |
--delimiter || |
| 312 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 313 |
RETURNS INT DETERMINISTIC |
| 314 |
BEGIN |
| 315 |
IF d1 != '' THEN |
| 316 |
SET debug_sync = d1; |
| 317 |
END IF; |
| 318 |
IF d2 != '' THEN |
| 319 |
SET debug_sync = d2; |
| 320 |
END IF; |
| 321 |
RETURN x; |
| 322 |
END |
| 323 |
|| |
| 324 |
--delimiter ; |
| 325 |
SET sql_log_bin=1; |
| 326 |
|
| 327 |
|
| 328 |
--connection server_2 |
| 329 |
# Respawn all worker threads to clear any left-over debug_sync or other stuff. |
| 330 |
--source include/stop_slave.inc |
| 331 |
SET GLOBAL slave_parallel_threads=0; |
| 332 |
SET GLOBAL slave_parallel_threads=10; |
| 333 |
--source include/start_slave.inc |
| 334 |
|
| 335 |
|
| 336 |
--echo *** 3. Same as (2), but not using gtid mode *** |
| 337 |
|
| 338 |
--connection server_1 |
| 339 |
# Set up three transactions on the master that will be group-committed |
| 340 |
# together so they can be replicated in parallel on the slave. |
| 341 |
--connection con_temp3 |
| 342 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; |
| 343 |
send INSERT INTO t3 VALUES (51, foo(51, |
| 344 |
'commit_before_prepare_ordered WAIT_FOR t2_waiting', |
| 345 |
'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); |
| 346 |
|
| 347 |
--connection server_1 |
| 348 |
SET debug_sync='now WAIT_FOR master_queued1'; |
| 349 |
|
| 350 |
--connection con_temp4 |
| 351 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; |
| 352 |
BEGIN; |
| 353 |
# This insert is just so we can get T2 to wait while a query is running that we |
| 354 |
# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. |
| 355 |
INSERT INTO t3 VALUES (52, foo(52, |
| 356 |
'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', |
| 357 |
'')); |
| 358 |
# This insert sets up debug_sync points so that T2 will tell when it is at its |
| 359 |
# wait point where we want to kill it - and when it has been killed. |
| 360 |
INSERT INTO t3 VALUES (53, foo(53, |
| 361 |
'group_commit_waiting_for_prior SIGNAL t2_waiting', |
| 362 |
'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); |
| 363 |
send COMMIT; |
| 364 |
|
| 365 |
--connection server_1 |
| 366 |
SET debug_sync='now WAIT_FOR master_queued2'; |
| 367 |
|
| 368 |
--connection con_temp5 |
| 369 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; |
| 370 |
send INSERT INTO t3 VALUES (54, foo(54, |
| 371 |
'', |
| 372 |
'')); |
| 373 |
|
| 374 |
--connection server_1 |
| 375 |
SET debug_sync='now WAIT_FOR master_queued3'; |
| 376 |
SET debug_sync='now SIGNAL master_cont1'; |
| 377 |
|
| 378 |
--connection con_temp3 |
| 379 |
REAP; |
| 380 |
--connection con_temp4 |
| 381 |
REAP; |
| 382 |
--connection con_temp5 |
| 383 |
REAP; |
| 384 |
|
| 385 |
--connection server_1 |
| 386 |
SELECT * FROM t3 WHERE a >= 50 ORDER BY a; |
| 387 |
SET debug_sync='RESET'; |
| 388 |
|
| 389 |
--connection server_2 |
| 390 |
# Wait until T2 is inside executing its insert of 52, then find it in SHOW |
| 391 |
# PROCESSLIST to know its thread id for KILL later. |
| 392 |
SET debug_sync='now WAIT_FOR t2_query'; |
| 393 |
--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(52%' AND INFO NOT LIKE '%LIKE%'` |
| 394 |
SET debug_sync='now SIGNAL t2_cont'; |
| 395 |
|
| 396 |
# Wait until T2 has entered its wait for T1 to commit, and T1 has |
| 397 |
# progressed into its commit phase. |
| 398 |
SET debug_sync='now WAIT_FOR t1_ready'; |
| 399 |
|
| 400 |
# Now kill the transaction T2. |
| 401 |
--replace_result $thd_id THD_ID |
| 402 |
eval KILL $thd_id; |
| 403 |
|
| 404 |
# Wait until T2 has reacted on the kill. |
| 405 |
SET debug_sync='now WAIT_FOR t2_killed'; |
| 406 |
|
| 407 |
# Now we can allow T1 to proceed. |
| 408 |
SET debug_sync='now SIGNAL t1_cont'; |
| 409 |
|
| 410 |
--let $slave_sql_errno= 1317,1927,1964 |
| 411 |
--source include/wait_for_slave_sql_error.inc |
| 412 |
SELECT * FROM t3 WHERE a >= 50 ORDER BY a; |
| 413 |
|
| 414 |
# Now we have to disable the debug_sync statements, so they do not trigger |
| 415 |
# when the events are retried. |
| 416 |
SET debug_sync='RESET'; |
| 417 |
SET GLOBAL slave_parallel_threads=0; |
| 418 |
SET GLOBAL slave_parallel_threads=10; |
| 419 |
SET sql_log_bin=0; |
| 420 |
DROP FUNCTION foo; |
| 421 |
--delimiter || |
| 422 |
CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) |
| 423 |
RETURNS INT DETERMINISTIC |
| 424 |
BEGIN |
| 425 |
RETURN x; |
| 426 |
END |
| 427 |
|| |
| 428 |
--delimiter ; |
| 429 |
SET sql_log_bin=1; |
| 430 |
|
| 431 |
--connection server_1 |
| 432 |
INSERT INTO t3 VALUES (59,0); |
| 433 |
--save_master_pos |
| 434 |
|
| 435 |
--connection server_2 |
| 436 |
START SLAVE SQL_THREAD; |
| 437 |
--sync_with_master |
| 438 |
SELECT * FROM t3 WHERE a >= 50 ORDER BY a; |
| 439 |
|
| 440 |
# Clean up. |
| 441 |
--connection server_2 |
| 442 |
--source include/stop_slave.inc |
| 443 |
CHANGE MASTER TO master_use_gtid=slave_pos; |
| 444 |
SET GLOBAL slave_parallel_threads=@old_parallel_threads; |
| 445 |
SET GLOBAL slave_parallel_mode=@old_parallel_mode; |
| 446 |
--source include/start_slave.inc |
| 447 |
SET DEBUG_SYNC= 'RESET'; |
| 448 |
|
| 449 |
--connection server_1 |
| 450 |
DROP function foo; |
| 451 |
DROP TABLE t1,t2,t3; |
| 452 |
SET DEBUG_SYNC= 'RESET'; |
| 453 |
|
| 454 |
--source include/rpl_end.inc |