我最近升级到 mysql 5.7 并观察到频繁的死锁问题。是否有任何与锁定 5.7 相关的更改?
I recently upgraded to mysql 5.7 and observing frequent deadlock issue. Is there any change related to locking in 5.7?
我最近升级到 mysql 5.7 并观察到频繁的死锁问题。是否有任何与锁定 5.7 相关的更改,因为我以前没有遇到过这个问题。
我有一个名为 retry_records 的简单 table,它具有自动递增的 id 作为主键和列 unique_reference 作为唯一索引和另外两列。此 table 正在完全多线程环境中使用,其中一段代码 select 从 table 获取 n 条记录,处理数据并更新此 table 以防万一进程失败,其他部分代码正在从 table 中删除一些已处理的记录,而另一部分代码正在在此 table 中插入一条新记录。除了select,任何查询都没有join,没有批量插入,批量更新,批量删除。所有 update/delete/insert 交易都有一个声明。即便如此,我仍在观察插入的死锁。
以下是日志:
------------------------
LATEST DETECTED DEADLOCK
------------------------
2016-09-22 13:05:09 0x7f3f427e0700
*** (1) TRANSACTION:
TRANSACTION 39420432534, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1136, 2 row lock(s), undo log entries 1
MySQL thread id 37503, OS thread handle 139917976340224, query id 1695822465
插入查询..
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1334 page no 1726952 n bits 312 index id of table `database_name`.`table_name` trx id 39420432534 lock_mode X insert intention waiting
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len 8; hex 73757072656d756d; asc supremum;;
*** (2) TRANSACTION:
TRANSACTION 39420432524, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
6 lock struct(s), heap size 1136, 5 row lock(s), undo log entries 1
MySQL thread id 37494, OS thread handle 139909675222784, query id 1695822438
另一个插入查询...
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 1334 page no 1726952 n bits 312 index id of table
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1334 page no 1726952 n bits 312 index id of table
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len 8; hex 73757072656d756d; asc supremum;;
我遇到过类似的问题。从 5.7 开始,有一个新的参数名称 innodb_deadlock_detect
This option is used to disable deadlock detection. On high concurrency
systems, deadlock detection can cause a slowdown when numerous threads
wait for the same lock. At times, it may be more efficient to disable
deadlock detection and rely on the innodb_lock_wait_timeout setting
for transaction rollback when a deadlock occurs.
禁用它可以提高性能并减少死锁问题。
我最近升级到 mysql 5.7 并观察到频繁的死锁问题。是否有任何与锁定 5.7 相关的更改,因为我以前没有遇到过这个问题。
我有一个名为 retry_records 的简单 table,它具有自动递增的 id 作为主键和列 unique_reference 作为唯一索引和另外两列。此 table 正在完全多线程环境中使用,其中一段代码 select 从 table 获取 n 条记录,处理数据并更新此 table 以防万一进程失败,其他部分代码正在从 table 中删除一些已处理的记录,而另一部分代码正在在此 table 中插入一条新记录。除了select,任何查询都没有join,没有批量插入,批量更新,批量删除。所有 update/delete/insert 交易都有一个声明。即便如此,我仍在观察插入的死锁。 以下是日志:
------------------------
LATEST DETECTED DEADLOCK
------------------------
2016-09-22 13:05:09 0x7f3f427e0700
*** (1) TRANSACTION:
TRANSACTION 39420432534, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1136, 2 row lock(s), undo log entries 1
MySQL thread id 37503, OS thread handle 139917976340224, query id 1695822465
插入查询..
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1334 page no 1726952 n bits 312 index id of table `database_name`.`table_name` trx id 39420432534 lock_mode X insert intention waiting
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len 8; hex 73757072656d756d; asc supremum;;
*** (2) TRANSACTION:
TRANSACTION 39420432524, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
6 lock struct(s), heap size 1136, 5 row lock(s), undo log entries 1
MySQL thread id 37494, OS thread handle 139909675222784, query id 1695822438
另一个插入查询...
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 1334 page no 1726952 n bits 312 index id of table
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1334 page no 1726952 n bits 312 index id of table
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len 8; hex 73757072656d756d; asc supremum;;
我遇到过类似的问题。从 5.7 开始,有一个新的参数名称 innodb_deadlock_detect
This option is used to disable deadlock detection. On high concurrency systems, deadlock detection can cause a slowdown when numerous threads wait for the same lock. At times, it may be more efficient to disable deadlock detection and rely on the innodb_lock_wait_timeout setting for transaction rollback when a deadlock occurs.
禁用它可以提高性能并减少死锁问题。