| 1 |
--source include/have_innodb.inc |
| 2 |
--source include/have_debug_sync.inc |
| 3 |
--source include/count_sessions.inc |
| 4 |
|
| 5 |
--disable_query_log |
| 6 |
call mtr.add_suppression("InnoDB: Transaction was aborted due to "); |
| 7 |
--enable_query_log |
| 8 |
|
| 9 |
# Purge can cause deadlock in the test, requesting page's RW_X_LATCH for trx |
| 10 |
# ids reseting, after trx 2 acqured RW_S_LATCH and suspended in debug sync point |
| 11 |
# lock_trx_handle_wait_enter, waiting for upd_cont signal, which must be |
| 12 |
# emitted after the last SELECT in this test. The last SELECT will hang waiting |
| 13 |
# for purge RW_X_LATCH releasing, and trx 2 will be rolled back by timeout. |
| 14 |
|
| 15 |
# There is deadlock_report_before_lock_releasing sync point in |
| 16 |
# Deadlock::report(), which is waiting for sel_cont signal under |
| 17 |
# lock_sys_t lock. The signal must be issued after "UPDATE t SET b = 100" |
| 18 |
# rollback, and that rollback is executing undo record, which is blocked on |
| 19 |
# dict_sys latch request. dict_sys is locked by the thread of statistics |
| 20 |
# update(dict_stats_save()), and during that update lock_sys lock is requested, |
| 21 |
# and can't be acquired as Deadlock::report() holds it. We have to disable |
| 22 |
# statistics update to make the test stable. |
| 23 |
|
| 24 |
CREATE TABLE t (a int PRIMARY KEY, b int) engine = InnoDB STATS_PERSISTENT=0; |
| 25 |
CREATE TABLE t2 (a int PRIMARY KEY) engine = InnoDB STATS_PERSISTENT=0; |
| 26 |
|
| 27 |
INSERT INTO t VALUES (10, 10), (20, 20), (30, 30); |
| 28 |
INSERT INTO t2 VALUES (10), (20), (30); |
| 29 |
|
| 30 |
BEGIN; # trx 1 |
| 31 |
# The following update is necessary to increase the transaction weight, which is |
| 32 |
# calculated as the number of locks + the number of undo records during deadlock |
| 33 |
# report. Victim's transaction should have minimum weight. We need trx 2 to be |
| 34 |
# choosen as victim, that's why we need to increase the current transaction |
| 35 |
# weight. |
| 36 |
UPDATE t2 SET a = a + 100; |
| 37 |
SELECT * FROM t WHERE a = 20 FOR UPDATE; |
| 38 |
|
| 39 |
--connect(con_2,localhost,root,,) |
| 40 |
# RC is necessary to do semi-consistent read |
| 41 |
SET innodb_snapshot_isolation=OFF; |
| 42 |
SET TRANSACTION ISOLATION LEVEL READ COMMITTED; |
| 43 |
BEGIN; # trx 2 |
| 44 |
# The first time it will be hit on trying to lock (20,20), the second hit |
| 45 |
# will be on (30,30). |
| 46 |
SET DEBUG_SYNC = 'lock_trx_handle_wait_before_unlocked_wait_lock_check SIGNAL upd_locked WAIT_FOR upd_cont'; |
| 47 |
# We must not modify primary key fields to cause rr_sequential() read record |
| 48 |
# function choosing in mysql_update(), i.e. both query_plan.using_filesort and |
| 49 |
# query_plan.using_io_buffer must be false during init_read_record() call. |
| 50 |
--send UPDATE t SET b = 100 |
| 51 |
|
| 52 |
--connection default |
| 53 |
SET DEBUG_SYNC="now WAIT_FOR upd_locked"; |
| 54 |
SET DEBUG_SYNC="lock_wait_before_suspend SIGNAL upd_cont"; |
| 55 |
--send SELECT * FROM t WHERE a = 10 FOR UPDATE |
| 56 |
|
| 57 |
--connection con_2 |
| 58 |
# If the bug is not fixed, lock_trx_handle_wait() wrongly returns DB_SUCCESS |
| 59 |
# instead of DB_DEADLOCK, row_search_mvcc() of trx 2 behaves so as if (20,20) |
| 60 |
# was locked. Some debug assertion must crash the server. If the bug is fixed, |
| 61 |
# trx 2 must just be rolled back by deadlock detector. |
| 62 |
--error ER_LOCK_DEADLOCK |
| 63 |
--reap |
| 64 |
|
| 65 |
--disconnect con_2 |
| 66 |
|
| 67 |
--connection default |
| 68 |
--reap |
| 69 |
SET DEBUG_SYNC = 'RESET'; |
| 70 |
DROP TABLE t; |
| 71 |
DROP TABLE t2; |
| 72 |
--source include/wait_until_count_sessions.inc |