Details
Description
As explained in upstream bug reports (that has all the details on the test case):
http://bugs.mysql.com/bug.php?id=82127
https://bugs.launchpad.net/percona-server/+bug/1598822
there is a deadlock scenario with 3 concurrent DELETEs by UNIQUE key that can not be explained by the manual:
CREATE TABLE `tu`(`id` int(11), `a` int(11) DEFAULT NULL, `b` varchar(10) DEFAULT NULL, `c` varchar(10) DEFAULT NULL, PRIMARY KEY(`id`), UNIQUE KEY `u`(`a`,`b`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 STATS_PERSISTENT=0;
|
|
insert into tu values(1,1,'a','a'),(2,9999,'xxxx','x'),(3,10000,'b','b'),(4,4,'c','c');
|
|
mysqlslap -uroot --concurrency=3 --create-schema=test --no-drop --number-of-queries=1000 --query="delete from tu where a = 9999 and b = 'xxxx'"
|
mysqlslap: Cannot run query delete from tu where a = 9999 and b = 'xxxx' ERROR : Deadlock found when trying to get lock; try restarting transaction
|
Deadlock happens both with triggers mentioned in that bug reports and without them (just less often).
The problem was originally noted by customer on MariaDB 5.5.24, but affects all released versions up to those based on InnoDB from 5.7.x for sure.
As there is no visible progress on upstream bugs, I create this bug report for MariaDB to decide if there is anything to fix here or to document clearly in the knowledge base.
Attachments
Issue Links
- is blocked by
-
MDEV-27025 insert-intention lock conflicts with waiting ORDINARY lock
-
- Closed
-
- relates to
-
MDEV-14589 InnoDB should not lock a delete-marked record
-
- Closed
-
-
MDEV-16232 Use fewer mini-transactions
-
- Stalled
-
-
MDEV-16402 Support Index Condition Pushdown for clustered PK scans
-
- Confirmed
-
-
MDEV-16406 Refactor the InnoDB record locks
-
- Open
-
-
MDEV-18706 ER_LOCK_DEADLOCK on concurrent read and insert into already locked gap
-
- In Review
-
-
MDEV-31833 replication breaks when using optimistic replication and replica is a galera node
-
- Closed
-
-
MDEV-20605 Awaken transaction can miss inserted by other transaction records due to wrong persistent cursor restoration
-
- Closed
-
-
MDEV-22698 Deadlock on concurrent acquisition from multiple indexes
-
- Open
-
-
MDEV-23560 Deadlock detected on SELECT when only one record being processed
-
- Open
-
-
MDEV-28800 SIGABRT due to running out of memory for InnoDB locks
-
- Closed
-
- links to
- mentioned in
-
Page Loading...
Can't repeat it with the following test:
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
--connect(dont_purge, localhost,root,,)
START TRANSACTION WITH CONSISTENT SNAPSHOT;
#
#
# identified by a secondary index key.
# This kind of operation (besides LOCK_IX on a table) requires
# an LOCK_REC_NOT_GAP|LOCK_REC|LOCK_X lock on a secondary index
CREATE TABLE `t`(
`id` INT,
`a` INT DEFAULT NULL,
PRIMARY KEY(`id`),
UNIQUE KEY `u`(`a`)
) ENGINE=InnoDB;
INSERT INTO t (`id`,`a`) VALUES
--connect(deleter,localhost,root,,)
--connect(holder,localhost,root,,)
--connect(waiter,localhost,root,,)
--connection deleter
SET DEBUG_SYNC =
'lock_sec_rec_read_check_and_lock_has_locked
SIGNAL deleter_has_locked
WAIT_FOR waiter_has_locked';
--connection holder
SET DEBUG_SYNC=
SET DEBUG_SYNC=
--connection waiter
SET DEBUG_SYNC=
SET DEBUG_SYNC=
--connection deleter
--reap
--connection holder
--reap
--connection waiter
--reap
--disconnect deleter
--disconnect holder
--disconnect waiter
--disconnect dont_purge
DROP TABLE `t`;
and the following sync point:
diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc
--- a/storage/innobase/lock/lock0lock.cc
+++ b/storage/innobase/lock/lock0lock.cc
}
+
Like lock_clust_rec_read_check_and_lock(), but reads a
secondary index record.
dberr_t err;
ulint heap_no;
+ SCOPE_EXIT([]() {
+ });
+
ut_ad(!dict_index_is_clust(index));
ut_ad(!dict_index_is_online_ddl(index));
ut_ad(block->frame == page_align(rec));
from
commit bfba840dfa7794b988c59c94658920dbe556075d
Author: Jakub Łopuszański <jakub.lopuszanski@oracle.com>
Date: Tue Jun 11 12:36:53 2019 +0200
Bug #23755664 DEADLOCK WITH 3 CONCURRENT DELETES BY UNIQUE KEY
on the latest 10.4, as well as with the sequence of steps described in https://bugs.mysql.com/bug.php?id=82127.
Have not understood yet why.