| 1 |
--source include/have_innodb.inc |
| 2 |
--source include/have_debug.inc |
| 3 |
--source include/have_debug_sync.inc |
| 4 |
--source include/count_sessions.inc |
| 5 |
|
| 6 |
--disable_query_log |
| 7 |
call mtr.add_suppression("InnoDB: Transaction was aborted due to "); |
| 8 |
--enable_query_log |
| 9 |
|
| 10 |
--connect (pause_purge,localhost,root) |
| 11 |
START TRANSACTION WITH CONSISTENT SNAPSHOT; |
| 12 |
|
| 13 |
--connection default |
| 14 |
CREATE TABLE t (pk int PRIMARY KEY, sk INT UNIQUE) ENGINE=InnoDB; |
| 15 |
INSERT INTO t VALUES (10, 100); |
| 16 |
|
| 17 |
--connect (con1,localhost,root) |
| 18 |
BEGIN; # trx 0 |
| 19 |
SELECT * FROM t WHERE sk = 100 FOR UPDATE; |
| 20 |
|
| 21 |
--connect (con2,localhost,root) |
| 22 |
SET DEBUG_SYNC="lock_wait_start SIGNAL insert_wait_started"; |
| 23 |
# trx 1 is locked on try to read the record in secondary index during duplicates |
| 24 |
# check. It's the first in waiting queue, that's why it will be woken up firstly |
| 25 |
# when trx 0 commits. |
| 26 |
--send INSERT INTO t VALUES (5, 100) # trx 1 |
| 27 |
|
| 28 |
--connect (con3,localhost,root) |
| 29 |
# MDEV-30225 is fixed only for RR |
| 30 |
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; |
| 31 |
SET DEBUG_SYNC="now WAIT_FOR insert_wait_started"; |
| 32 |
SET DEBUG_SYNC="lock_wait_start SIGNAL delete_started_waiting"; |
| 33 |
# trx 2 can delete (5, 100) on master, but not on slave, as on slave trx 1 |
| 34 |
# can insert (5, 100) after trx 2 positioned it's cursor. Trx 2 lock is placed |
| 35 |
# in waiting queue after trx 1 lock, but its persistent cursor position was |
| 36 |
# stored on (100, 10) record in secondary index before suspending. After trx 1 |
| 37 |
# is committed, trx 2 will restore persistent cursor position on (100, 10). As |
| 38 |
# (100, 5) secondary index record was inserted before (100, 10) in logical |
| 39 |
# order, and (100, 10) record is delete-marked, trx 2 just continues scanning. |
| 40 |
# |
| 41 |
# Note. There can be several records with the same key in unique secondary |
| 42 |
# index, but only one of them must be non-delete-marked. That's why when we do |
| 43 |
# point query, cursor position is set in the first record in logical order, and |
| 44 |
# then records are iterated until either non-delete-marked record is found or |
| 45 |
# all records with the same unique fields are iterated. |
| 46 |
--send DELETE FROM t WHERE sk = 100 # trx 2 |
| 47 |
|
| 48 |
--connection con1 |
| 49 |
SET DEBUG_SYNC="now WAIT_FOR delete_started_waiting"; |
| 50 |
DELETE FROM t WHERE sk=100; # trx 0 |
| 51 |
COMMIT; |
| 52 |
--disconnect con1 |
| 53 |
|
| 54 |
--connection con2 |
| 55 |
--reap |
| 56 |
--disconnect con2 |
| 57 |
|
| 58 |
--connection con3 |
| 59 |
# If the bug is fixed, deadlock error will be there, as trx 2 owns |
| 60 |
# next-key lock waiting for trx 1, and trx 1 requests |
| 61 |
# insert-intention lock, conflicting with trx 2 next-key lock. |
| 62 |
--error ER_LOCK_DEADLOCK |
| 63 |
--reap |
| 64 |
--disconnect con3 |
| 65 |
|
| 66 |
--connection default |
| 67 |
# If the bug is not fixed, we will see the row inserted by trx 1 here. This can |
| 68 |
# cause duplicate key error on slave, when some other trx tries in insert row |
| 69 |
# with the same secondary key, as was inserted by trx 1, and not deleted by trx |
| 70 |
# 2. |
| 71 |
SELECT * FROM t; |
| 72 |
|
| 73 |
--disconnect pause_purge |
| 74 |
SET DEBUG_SYNC="RESET"; |
| 75 |
DROP TABLE t; |
| 76 |
--source include/wait_until_count_sessions.inc |