mysql如何关闭死锁检测,MySQL死锁检测和回滚

最近碰到“TOO DEEP OR LONG SEARCH IN THE LOCK TABLE WAITS-FOR GRAPH, WE WILL ROLL BACK FOLLOWING TRANSACTION”。html

从新温习下受益良多,其中死锁的断定规则,其实咱们早在5年前解决秒杀场景的第一个版本就已经涉及,而且思路很类似,若是有时间的话,我会补充上一批文章说下若是关闭死锁检测对单行更新能提高多少性能。mysql

下面这一段代码展现的是:sql

“函数

If the LATEST DETECTED DEADLOCK section of InnoDB Monitor output includes a message stating, “TOO DEEP OR LONG SEARCH IN THE LOCK TABLE WAITS-FOR GRAPH, WE WILL ROLL BACK FOLLOWING TRANSACTION,” this indicates that the number of transactions on the wait-for list has reached a limit of 200. A wait-for list that exceeds 200 transactions is treated as a deadlock and the transaction attempting to check the wait-for list is rolled back. The same error may also occur if the locking thread must look at more than 1,000,000 locks owned by transactions on the wait-for list.性能

”this

在innodb源代码lock/lock0lock.c文件中,定义了两个常量:/*Restricts the length of search we will do in the waits-for

graph of transactions*/

#define LOCK_MAX_N_STEPS_IN_DEADLOCK_CHECK 1000000

/*Restricts the recursion depth of the search we will do in the waits-for

graph of transactions*/

#define LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK 200而后在检查是否产生死锁的函数lock_deadlock_occurs()中有以下代码:

ret= lock_deadlock_recursive(trx, trx, lock, &cost, 0);switch(ret) {caseLOCK_EXCEED_MAX_DEPTH:

产生死锁

...break;

}

其中的lock_deadlock_recursive()函数是递归函数,它会检查自身递归深度,其中有以下代码:

ibool too_far= depth >LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK|| *cost >LOCK_MAX_N_STEPS_IN_DEADLOCK_CHECK;

...if(too_far) {return(LOCK_EXCEED_MAX_DEPTH);

}

所以innodb在检查是否产生死锁时调用lock_deadlock_occurs()检查,这个函数再会调用lock_deadlock_recursive()递归检查锁的数目(不知道这么说是否确切?),当递归的深度depth大于了一开始介绍的常量LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK,或者cost(不清楚这个表明什么)大于一开始介绍的常量LOCK_MAX_N_STEPS_IN_DEADLOCK_CHECK时,就认为发生了死锁.spa

资料出处:.net

http://blog.csdn.net/sunmun/article/details/50088381code

https://dev.mysql.com/doc/refman/5.7/en/innodb-deadlock-detection.htmlhtm

http://www.cnblogs.com/zemliu/p/3502395.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值