Bug #105655 | Wait for the lock that has already been acquired. | ||
---|---|---|---|
Submitted: | 22 Nov 2021 9:01 | Modified: | 3 Feb 2022 7:10 |
Reporter: | SeWoong Jeon | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S4 (Feature request) |
Version: | 8.0.25 | OS: | CentOS (7.9) |
Assigned to: | CPU Architecture: | x86 | |
Tags: | deadlock |
[22 Nov 2021 9:01]
SeWoong Jeon
[22 Nov 2021 22:01]
Jakub Lopuszanski
Hello and thanks for reporting. This is a known issue - the "HOLDS THE LOCK(S):" section title is misleading, sorry. It should rather be "HAS MADE A CONFLICTING REQUEST:", but we haven't changed it for backwards compatibility with tools which expect this exact wording. The X Lock request in question has not been granted yet - it still waiting, which you can tell by looking at the last word ("waiting") of the line describing the state: *** (1) HOLDS THE LOCK(S): RECORD LOCKS space id 120 page no 4 n bits 72 index PRIMARY of table `mydb`.`tb_locking_key` trx id 421310084 lock_mode X locks rec but not gap waiting Even though the request wasn't granted yet, it is still conflicting with the request of the second transaction, because InnoDB is trying to avoid starvation of the first transaction. The lock queue for the record <space_id=120,page_no=4,heap_no=2> looks something like this: [granted S-lock of Trx2] <-- [waiting X-lock of Trx1] <-- [waiting X-lock of Trx2] This is to be expected in situations where Trx2 is trying to perform "lock escalation" from "S" to "X", but there's already Trx1 waiting for the lock. Current implementation of InnoDB tries to avoid starving Trx1, so it asks Trx2 to wait so that Trx1 gets its turn to get X lock, but this leads to a deadlock. Arguably, this behaviour could be changed, and this was already contemplated recently in https://bugs.mysql.com/bug.php?id=101695 and years ago in https://bugs.mysql.com/bug.php?id=21356 but this sounds more like a feature request than a bug.
[23 Nov 2021 13:07]
MySQL Verification Team
Hi Mr Jeon, Thank you for your bug report. We agree with members of the InnoDB team on this issue. This report is a feature request, that is a duplicate of the feature request: https://bugs.mysql.com/bug.php?id=21356 That feature request was filed long time ago by the members of the MySQL team. We agree that this feature request should get a higher priority. It would be nice if you would go to the above original report and click on "Affects Me" button at the right-hand upper corner of the corresponding item. A duplicate.
[31 Jan 2022 16:47]
Jakub Lopuszanski
The fix for Bug #21356 "Change lock priority so that the transaction holding S-lock gets X-lock first" will improve behaviour in scenarios like this.
[3 Feb 2022 7:10]
SeWoong Jeon
I totally agree with your opinion. Thank you.
[3 Feb 2022 13:28]
MySQL Verification Team
Only a small addition. The original feature request: https://bugs.mysql.com/bug.php?id=21356 is much wider than just upgrading locks from shared to exclusive. It encompasses, actually, ANY lock upgrades and there are others, as described in our Reference Manual. It is also worth noted that, when materialised, this algorithm would add a new feature to the theory of locks in ACID storage engines.