时间:2021-07-01 10:21:17 帮助过:23人阅读
”
在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) { case LOCK_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时,就认为发生了死锁.
资料出处:
http://blog.csdn.net/sunmun/article/details/50088381
https://dev.mysql.com/doc/refman/5.7/en/innodb-deadlock-detection.html
http://www.cnblogs.com/zemliu/p/3502395.html
MySQL死锁检测和回滚
标签:output ase innodb dead actions htm details 递归 mysql死锁