Magento僵局 [英] Magento deadlocks

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

问题描述

我正在使用Magento 1.7.0.2 Community Edition,但遇到了一个大问题-死锁和超出了锁定等待超时"错误.在执行特定的 CRON 任务

I am using Magento 1.7.0.2 Community Edition and I have encountered a big problem - deadlocks and "Lock wait timeout exceeded" errors. Problem exists while specific CRON tasks are executed

  • 导入/更新产品(尺寸,颜色,制造商也是如此).大约有5000种产品,但是在90%的脚本中,出现超出锁定等待超时"错误或死锁错误.脚本是使用Magento准则开发的,如果没有其他进程在运行,它可以很好地工作.例如,如果reindex正在运行,则肯定会出现错误.它表明是由于表锁造成的
  • Magento在某些情况下会设置读取锁定.我已经阅读了一些与此相关的主题,并且正在更改的唯一正确解决方案是/lib/Zend/Db/Statement/Pdo.php _execute函数.当我们期待将Magento升级到最新的稳定版本时,我们无法承受更改核心文件的费用.
  • Importing/updating products(sizes, colors, manufacturers as well). There are around 5000 products but in 90% script gets "Lock wait timeout exceeded" errors or a deadlock error. Script is developed using Magento guidelines and it works fine if no other processes are running. For example if reindex is running, we get an error for sure. It seams that is because of table locks
  • Magento puts a read lock in some cases. I have read several topics about this already and the only proper solution seams to be changing /lib/Zend/Db/Statement/Pdo.php _execute function. As we are looking forward for upgrading Magento to the latest stable version we can`t afford changing core files.

所以我的问题-有没有办法避免这种情况(无论是在PHP,MySQL还是服务器(我们使用nginx)级别)?

So my question - is there a way how to avoid this(whether on PHP, MySQL or server(we use nginx) level)?

推荐答案

我在尝试一次导入五个或六个以上的产品时遇到了这个问题.有关可用死锁的更多信息,此处.

I came across this issue whilst trying to import more than five or six products at once. There is more information on deadlocks available here.

要解决此问题,我必须将数据库查询放在

To solve this problem I had to place my database queries in SERIALIZABLE transactions where possible, like so:

$adapter = Mage::getModel('core/resource')->getConnection('core_write');
// Commit any existing transactions (use with caution!)
if ($adapter->getTransactionLevel > 0) {
    $adapter->commit();
}
$adapter->query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE');
$product->save(); // etc

交易示例:

$adapter = Mage::getModel('core/resource')->getConnection('core_write');
// Commit any existing transactions (use with caution!)
if ($adapter->getTransactionLevel > 0) {
    $adapter->commit();
}
$adapter->query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE');
$adapter->beginTransaction();
try {
    $adapter->query(/* SQL goes here */);
    $adapter->commit();
} catch (Exception $e) {
    // Rollback on fail always
    $adapter->rollBack();
    throw $e;
}

如果您需要任何其他帮助,请随时告诉我.

If you require any further help on this, feel free to let me know.

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

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