2

我在 2 个进程修改 MySQL 数据库中的同一个表时遇到了一些麻烦。偶尔它会导致死锁,并且其中一个或其他进程在尝试获取锁定时发现“死锁”;尝试重新启动事务的错误。

我找到了一些关于为什么会在 stackoverflow 上发生这种情况的答案,这让我找到了一些解决问题的方法。(只需重试事务)。我希望有比这更好的解决方案,因此开始使用 SHOW ENGINE INNODB STATUS 进行调查。

我对 STATUS 命令的输出感到困惑。从我所见,它并没有显示出真正的僵局。第一个事务正在等待被锁定的行 购买第二个事务,并且第一个事务没有其他锁。第二个事务持有 4 个锁,一个是第一个事务所需的锁,正在等待第 5 个锁。没有提到任何其他事务持有第 5 个锁。

与死锁相关的输出是:

------------------------
LATEST DETECTED DEADLOCK
------------------------
130514  8:54:12
*** (1) TRANSACTION:
TRANSACTION 0 487333931, ACTIVE 0 sec, process no 1007, OS thread id 2990889792 fetching rows
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 320, 24 row lock(s), undo log entries 3
MySQL thread id 774102, query id 166772615 localhost 127.0.0.1 nesie updating
DELETE FROM DeviceStatus WHERE serialNo=1234567 AND subDevice=1 AND (parameter='band' OR parameter='arfcn' OR parameter='txPower' OR parameter='lac' OR parameter='cellId' OR parameter='channel' OR parameter='rxReversePower' OR parameter='reverseSnr' OR parameter='reverseGmp' OR parameter='reverseBepm' OR parameter='mobileHeldOn' OR parameter='mobileHeldBand' OR parameter='mobileTxPower' OR parameter='mobileCommandedPower' OR parameter='rxPathLoss' OR parameter='holdState' OR parameter='band' OR parameter='channel' OR parameter='arfcn' OR parameter='rxForwardPower' OR parameter='forwardSnr' OR parameter='forwardGmp' OR parameter='forwardBepm' OR parameter='lac' OR parameter='cellId')
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1267 page no 3 n bits 96 index `PRIMARY` of table `nesie`.`DeviceStatus` trx id 0 487333931 lock_mode X waiting
Record lock, heap no 20 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
 0: len 4; hex 80151487; asc     ;; 1: len 4; hex 80000001; asc     ;; 2: len 10; hex 6d6f6e69746f72696e67; asc monitoring;; 3: len 6; hex 00001d0c202a; asc      *;; 4: len 7; hex 00000000342dbd; asc     4- ;; 5: len 4; hex 80000000; asc     ;;

*** (2) TRANSACTION:
TRANSACTION 0 487333930, ACTIVE 0 sec, process no 1007, OS thread id 3063302976 inserting, thread declared inside InnoDB 488
mysql tables in use 1, locked 1
5 lock struct(s), heap size 320, 6 row lock(s), undo log entries 4
MySQL thread id 774099, query id 166772616 localhost nesie update
REPLACE INTO DeviceStatus VALUES (1381511,1,'scanning',1),(1381511,1,'monitoring',0),(1381511,1,'transmitting',0),(1381511,1,'power',-84),(1381511,1,'band',1),(1381511,1,'uarfcn',10661),(1381511,1,'scramblingCode',377)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 1267 page no 3 n bits 96 index `PRIMARY` of table `nesie`.`DeviceStatus` trx id 0 487333930 lock_mode X locks rec but not gap
Record lock, heap no 20 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
 0: len 4; hex 80151487; asc     ;; 1: len 4; hex 80000001; asc     ;; 2: len 10; hex 6d6f6e69746f72696e67; asc monitoring;; 3: len 6; hex 00001d0c202a; asc      *;; 4: len 7; hex 00000000342dbd; asc     4- ;; 5: len 4; hex 80000000; asc     ;;

Record lock, heap no 21 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
 0: len 4; hex 80151487; asc     ;; 1: len 4; hex 80000001; asc     ;; 2: len 5; hex 706f776572; asc power;; 3: len 6; hex 00001d0c202a; asc      *;; 4: len 7; hex 00000000342e11; asc     4. ;; 5: len 4; hex 7fffffac; asc     ;;

Record lock, heap no 22 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
 0: len 4; hex 80151487; asc     ;; 1: len 4; hex 80000001; asc     ;; 2: len 8; hex 7363616e6e696e67; asc scanning;; 3: len 6; hex 00001d0c202a; asc      *;; 4: len 7; hex 00000000342d96; asc     4- ;; 5: len 4; hex 80000001; asc     ;;

Record lock, heap no 24 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
 0: len 4; hex 80151487; asc     ;; 1: len 4; hex 80000001; asc     ;; 2: len 12; hex 7472616e736d697474696e67; asc transmitting;; 3: len 6; hex 00001d0c202a; asc      *;; 4: len 7; hex 00000000342de6; asc     4- ;; 5: len 4; hex 80000000; asc     ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1267 page no 3 n bits 96 index `PRIMARY` of table `nesie`.`DeviceStatus` trx id 0 487333930 lock_mode X locks rec but not gap waiting
Record lock, heap no 17 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
 0: len 4; hex 80151487; asc     ;; 1: len 4; hex 80000001; asc     ;; 2: len 4; hex 62616e64; asc band;; 3: len 6; hex 00001d0c19ff; asc       ;; 4: len 7; hex 000000003428a7; asc     4( ;; 5: len 4; hex 80000001; asc     ;;

*** WE ROLL BACK TRANSACTION (1)

我的问题是:

为什么这被标记为死锁,事务 1 可以排队直到事务 2 完成,因为它没有事务 2 所需的锁?

有谁知道MySQL的这种正常行为还是一个错误?

谢谢,

西蒙。

4

1 回答 1

1

您可以使用新的 5.6 变量:http ://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html#sysvar_innodb_print_all_deadlocks

这样你就可以记录所有的死锁,并且可能找到哪个事务正在启动你的死锁。

于 2015-11-05T21:34:59.983 回答