处理innoDB死锁 [英] Handling innoDB deadlock

查看:125
本文介绍了处理innoDB死锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的InnoDB表上出现了Deadlock found when trying to get lock; try restarting transaction错误.这是查询:

I've been getting a Deadlock found when trying to get lock; try restarting transaction error on my InnoDB tables. Here is the query:

UPDATE views 
SET visit_cnt = visit_cnt + 1 
WHERE visit_day = DATE(NOW()) 
AND article_id = '4838'

此查询还会通过ON UPDATE触发器触发此操作:

This query also triggers this via ON UPDATE trigger:

UPDATE articles 
SET views = views + 1 
WHERE id = NEW.article.id

这是我尝试解决的方法:

Here is how I tried to fixed it:

$attempts_left = 5;
do
{
    mysql_query ($query);

    // if we found a deadlock, we will try this query 4 more times   
    if (mysql_errno () == 1213) { // 1213 - deadlock error
        $deadlocked = true;
        $attempts_left --;
    }
    else{
        $deadlocked = false;
    }
}
while($deadlocked && $attempts_left > 0);

我的问题:这是处理死锁的唯一方法吗?我的意思是这很丑陋,而且僵局有时会不时发生.有什么建议的方法可以解决死锁吗?

My question: is this the only way to handle a deadlock? I mean this is quite ugly and deadlocks happen time to time anyway. Is there any recommended way to fix deadlocks?

推荐答案

以下是有关处理 PS:我没有什么可添加的,所以给您链接.

PS: I didn't have anything more to add so just gave you the link.

这篇关于处理innoDB死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆