Magento 死锁 [英] Magento deadlocks

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

问题描述

我正在使用 Magento 1.7.0.2 社区版,但遇到了一个大问题 - 死锁和超出锁定等待超时"错误.执行特定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_执行函数.由于我们期待将 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.

为了解决这个问题,我不得不将我的数据库查询放在 SERIALIZABLE 事务在可能的情况下,像这样:

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天全站免登陆