Innodb deadlock with already locked row (non IX)
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
Percona Server moved to https://jira.percona.com/projects/PS | Status tracked in 5.7 | |||||
5.1 |
Won't Fix
|
Medium
|
Unassigned | |||
5.5 |
Triaged
|
Medium
|
Unassigned | |||
5.6 |
Triaged
|
Medium
|
Unassigned | |||
5.7 |
Triaged
|
Medium
|
Unassigned |
Bug Description
Percona Server 5.5.20
The deadlock happens during pt-online-
Rolled back transaction:
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 50538 page no 6778 n bits 224 index `KEY01` of table `test`.`_tbl_new` trx id 549F20D92 lock_mode X locks rec but not gap
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 50538 page no 6778 n bits 224 index `KEY01` of table `test`.`_tbl_new` trx id 549F20D92 lock_mode X waiting
It seems like the transaction is trying to obtain the already locked one. The problem looks similar to "not a bug" https:/
and http://
but there is no "intention" waiting.
Transaction isolation level: repeatable-read
140516 10:26:00
*** (1) TRANSACTION:
TRANSACTION 549F20D91, ACTIVE 0 sec inserting
mysql tables in use 2, locked 2
LOCK WAIT 7 lock struct(s), heap size 1248, 5 row lock(s), undo log entries 3
MySQL thread id 3036282, OS thread handle 0x7f51d4c21700, query id 20738656662 172.18.32.20 zwebapps update
REPLACE INTO `test`.`_tbl_new` (`id`, `c1`, `c2`, `c3`, `c4`, `c5`, `c6`, `c7`, `c8`, `c9`, `c10`, `c11`, `c12`, `c13`, `c14`, `c15`, `c16`, `c17`, `c18`, `c19`, `c20`, `c21`, `c22`, `c23`, `c24`, `c25`, `c26`, `c27`, `c28`, `c29`, `c30`, `c31`, `c32`, `c33`, `c34`) VALUES (NEW.`id`, NEW.`c1`, NEW.`c2`, NEW.`c3`, NEW.`c4`, NEW.`c5`, NEW.`c6`, NEW.`c7`, NEW.`c8`, NEW.`c9`, NEW.`c10`, NEW.`c11`, NEW.`number_
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 50538 page no 6778 n bits 224 index `KEY01` of table `test`.`_tbl_new` trx id 549F20D91 lock_mode X waiting
*** (2) TRANSACTION:
TRANSACTION 549F20D92, ACTIVE 0 sec inserting, thread declared inside InnoDB 497
mysql tables in use 2, locked 2
6 lock struct(s), heap size 1248, 4 row lock(s), undo log entries 3
MySQL thread id 3036211, OS thread handle 0x7f51ab0af700, query id 20738656663 172.18.32.21 zwebapps update
REPLACE INTO `test`.`_tbl_new` (`id`, `c1`, `c2`, `c3`, `c4`, `c5`, `c6`, `c7`, `c8`, `c9`, `c10`, `c11`, `c12`, `c13`, `c14`, `c15`, `c16`, `c17`, `c18`, `c19`, `c20`, `c21`, `c22`, `c23`, `c24`, `c25`, `c26`, `c27`, `c28`, `c29`, `c30`, `c31`, `c32`, `c33`, `c34`) VALUES (NEW.`id`, NEW.`c1`, NEW.`c2`, NEW.`c3`, NEW.`c4`, NEW.`c5`, NEW.`c6`, NEW.`c7`, NEW.`c8`, NEW.`c9`, NEW.`c10`, NEW.`c11`, NEW.`number_
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 50538 page no 6778 n bits 224 index `KEY01` of table `test`.`_tbl_new` trx id 549F20D92 lock_mode X locks rec but not gap
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 50538 page no 6778 n bits 224 index `KEY01` of table `test`.`_tbl_new` trx id 549F20D92 lock_mode X waiting
*** WE ROLL BACK TRANSACTION (2)
CREATE TABLE `tbl` (
`id` varchar(32) NOT NULL,
`c1` int(11) NOT NULL,
`c2` varchar(50) NOT NULL,
`c3` varchar(20) DEFAULT NULL,
`c4` varchar(32) DEFAULT NULL,
`c5` bit(1) NOT NULL DEFAULT b'0',
`c6` date DEFAULT NULL,
`c7` date DEFAULT NULL,
`c8` datetime DEFAULT NULL,
`c9` varchar(32) DEFAULT NULL,
`c10` varchar(20) NOT NULL,
`c11` varchar(255) DEFAULT NULL,
`c12` int(11) NOT NULL DEFAULT '0',
`c13` int(11) NOT NULL DEFAULT '0',
`c14` varchar(32) NOT NULL,
`c15` bit(1) NOT NULL DEFAULT b'0',
`c16` varchar(32) NOT NULL,
`c17` datetime NOT NULL,
`c18` varchar(32) DEFAULT NULL,
`c19` datetime DEFAULT NULL,
`c20` date DEFAULT NULL,
`c21` datetime DEFAULT NULL,
`c22` datetime DEFAULT NULL,
`c23` bigint(20) DEFAULT '0',
`c24` int(11) DEFAULT '0',
`c25` int(10) NOT NULL DEFAULT '0',
`c26` bit(1) NOT NULL DEFAULT b'0',
`c27` varchar(100) DEFAULT NULL,
`c28` bit(1) NOT NULL DEFAULT b'0',
`c29` bit(1) NOT NULL DEFAULT b'0',
`c30` bit(1) DEFAULT b'0',
`c31` datetime DEFAULT NULL,
`c32` varchar(32) DEFAULT NULL,
`c33` varchar(20) DEFAULT NULL,
`c34` varchar(32) DEFAULT NULL,
`c35` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `KEY01` (`c14`,`c2`),
KEY `KEY02` (`c9`),
KEY `KEY03` (`c14`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Triggers created by pt-online-
CREATE TRIGGER `pt_osc_
CREATE TRIGGER `pt_osc_
CREATE TRIGGER `pt_osc_
(includes all fields)
I'm not able to reproduce the bug on my own hardware, maybe it's important what there are many rollback operations and transaction could contain several statements on production system.
There are also similar rollbacks with different tables (also having many fields).
I found some other customer get similar problem by 3 threads running in parallel to delete same row in high concurrency.
and the reason is the second and third thread both get into no gap lock wait before this record not be marked to delate by thread , not X lock wait.
Then after thread1 commit thread 2 and 3 get gap lock but because of index id unique index it need none gap lock then they trying to request X lock which caused deadlock.
I found the symptom slimiar in deadlock info, so just for reference while you analyze checking source code, hope it could help.
------- ------- ------- ------ ------- ------- --- .`abcdefg` trx id 2E10 lock_mode X locks rec but not gap waiti
LATEST DETECTED DEADLOCK
-------
140123 12:20:50
*** (1) TRANSACTION:
TRANSACTION 2E10, ACTIVE 5325 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 376, 1 row lock(s)
MySQL thread id 3, OS thread handle 0x1008, query id 43 192.168.xx.x username upd
ating
delete from abcdefg WHERE abc= 'vars' and def= 'vars' and ghi= '2012-12-19 00:00:00' and jkl= '2012-12-20 00:00:00';
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 23415 n bits 528 index `uniqeindex` of table
`deadlock`
ng
Record lock, heap no 167 PHYSICAL RECORD: n_fields 4; compact format;
*** (2) TRANSACTION: .`abcdefg` trx id 2E0E lock_mode X locks rec but not gap
TRANSACTION 2E0E, ACTIVE 5325 sec starting index read
mysql tables in use 1, locked 1
3 lock struct(s), heap size 1248, 2 row lock(s)
MySQL thread id 1, OS thread handle 0x1190, query id 41 192.168.xx.xx username upd
ating
delete from abcdefg WHERE abc= 'vars' and def= 'vars' and ghi= '2012-12-19 00:00:00' and jkl= '2012-12-20 00:00:00';
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 0 page no 23415 n bits 528 index `uniqeindex` of table
`deadlock`
Record lock, heap no 167 PHYSICAL RECORD: n_fields 4; compact format;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED: .`abcdefg` trx id 2E0E lock_mode X waiting ------- ------- ------
RECORD LOCKS space id 0 page no 23415 n bits 528 index `uniqeindex` of table
`deadlock`
Record lock, heap no 167 PHYSICAL RECORD: n_fields 4; compact format;
*** WE ROLL BACK TRANSACTION (1)
-------