Bug #82127 | Deadlock with 3 concurrent DELETEs by UNIQUE key | ||
---|---|---|---|
Submitted: | 6 Jul 2016 13:55 | Modified: | 12 Jun 2019 15:33 |
Reporter: | Valeriy Kravchuk | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S3 (Non-critical) |
Version: | 5.7.13 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | deadlock, innodb, missing manual |
[6 Jul 2016 13:55]
Valeriy Kravchuk
[6 Jul 2016 17:42]
MySQL Verification Team
Hi Valeriy, Thank you so much for your bug report. However, I am wandering why do you think that this is a bug ??? What we have is a deadlock that occurs during lock upgrading and not during lock acquiring. Deadlocks are to be expected in the transactional engines, and are not consider bugs. If you remember, I have filed for the feature request, where priority would go to the transaction that just wants to upgrade a lock. It was even justified by Heikki. I can try to provide for it a much higher priority. Would that be good enough for you ???? Thanks for the reminder, though ...
[6 Jul 2016 21:45]
Valeriy Kravchuk
Please, send me URLs and quotes from that manual pages that explain the case when DELETE may request a record lock on secondary index and then request a next-key lock on the same record of the same secondary index. I'll easily agree it's not a bug if the manual explains the locks requests we see in this case and why they are needed at the REPEATABLE READ (default) isolation level.
[6 Jul 2016 21:48]
Valeriy Kravchuk
If you mean this old request, https://bugs.mysql.com/bug.php?id=21356, Sinisa, then I have to say that this case is different.
[7 Jul 2016 14:01]
MySQL Verification Team
Valeriy, To tell you the truth I do not see anything unknown in your report. With triggers, both the 'before delete' and 'after delete' triggers are trying to delete the same record. That sounds like a natural deadlock to me. Without triggers, you are trying to delete the same row(s) from three separate connections. That leads to the natural deadlock, due to the lock upgrading, about which I have submitted a feature request.
[7 Jul 2016 16:35]
Valeriy Kravchuk
Sinisa, please, give me URL or present a quote from the current manual of MySQL 5.7 (or any version) that explains when "lock upgrading" happens. Alternatively, show me the code that does this. Deadlocks in concurrent environment are surely expected and not new, and manual explains many of typical scenarios, but not the one I reproduced here. Nothing in the manual (from my knowledge) explains why (or in what cases) DELETE, at REPEATABLE READ isolation level, may get a secondary index record lock and then request a next-key lock on the SAME record. So, I see a documentation issue here at least.
[7 Jul 2016 17:25]
MySQL Verification Team
This is a fair request. Verified.
[12 Jun 2018 14:23]
Daniel Price
Posted by developer: The locking that occurs in this scenario has been determined to be suboptimal. Reclassifying as an InnoDB code bug.
[17 Aug 2018 17:32]
Valeriy Kravchuk
Changed category.
[12 Jun 2019 15:29]
Daniel Price
Posted by developer: commit 16d84704097d5ce086eac0a3a1f2dbca0e6fa80c Author: Jakub Łopuszański Date: Tue Jun 11 12:36:53 2019 +0200 Bug #23755664 DEADLOCK WITH 3 CONCURRENT DELETES BY UNIQUE KEY PROBLEM: A deadlock was possible when a transaction tried to "upgrade" an already held Record Lock to Next Key Lock. SOLUTION: This patch is based on observations that: (1) a Next Key Lock is equivalent to Record Lock combined with Gap Lock (2) a GAP Lock never has to wait for any other lock In case we request a Next Key Lock, we check if we already own a Record Lock of equal or stronger mode, and if so, then we either upgrade it to Next Key Lock, or if it is not possible (because the single lock_t struct is shared by more than one row) we change the requested lock type to GAP Lock, which we either already have, or can be granted immediately. (I don't consider Insert Intention Locks a Gap Lock in above statements). Reviewed-by: Debarun Banerjee RB:19879
[12 Jun 2019 15:33]
Daniel Price
Posted by developer: Fixed as of the upcoming 8.0.18 release, and here's the changelog entry: A deadlock was possible when a transaction tries to upgrade a record lock to a next key lock. Thank you for the bug report.
[13 Jun 2019 12:45]
MySQL Verification Team
Thank you, Daniel.