我在尝试一次进口超过五六种产品时遇到了这个问题。这里有更多关于死锁的信息。
为了解决这个问题,我必须尽可能将我的数据库查询放在SERIALIZABLE事务中,如下所示:
$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;
}
如果您在这方面需要任何进一步的帮助,请随时告诉我。