Debian Codegraph @

mysql-test/suite/innodb/t/deadlock_wait_thr_race.test

raw
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 SET innodb_snapshot_isolation=OFF;
41 # RC is necessary to do semi-consistent read
42 SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
43 # It will be hit on trying to lock (20,20).
44 SET DEBUG_SYNC = 'lock_trx_handle_wait_enter SIGNAL upd_locked WAIT_FOR upd_cont';
45 SET DEBUG_SYNC = 'trx_t_release_locks_enter SIGNAL sel_cont WAIT_FOR upd_cont_2';
46 BEGIN; # trx 2
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 # The following UPDATE will be chosen as deadlock victim and rolled back.
51 --send UPDATE t SET b = 100
52
53 --connection default
54 SET DEBUG_SYNC="now WAIT_FOR upd_locked";
55 SET DEBUG_SYNC="deadlock_report_before_lock_releasing SIGNAL upd_cont WAIT_FOR sel_cont";
56 SET DEBUG_SYNC="lock_wait_before_suspend SIGNAL sel_before_suspend";
57 # If the bug is not fixed, the following SELECT will crash, as the above UPDATE
58 # will reset trx->lock.wait_thr during rollback
59 --send SELECT * FROM t WHERE a = 10 FOR UPDATE;
60
61 --connect(con_3,localhost,root,,)
62 SET DEBUG_SYNC="now WAIT_FOR sel_before_suspend";
63 SET DEBUG_SYNC="now SIGNAL upd_cont_2";
64 --disconnect con_3
65
66 --connection con_2
67 --error ER_LOCK_DEADLOCK
68 --reap
69 --disconnect con_2
70
71 --connection default
72 --reap
73 SET DEBUG_SYNC = 'RESET';
74 DROP TABLE t;
75 DROP TABLE t2;
76 --source include/wait_until_count_sessions.inc