How to prevent lock wait timeout from blocking orders?
Question
Got a lock wait timeout originating in Mage_Sales_Model_Order::_afterSave()
:
https://github.com/LokeyCoding/magento-mirror/blob/magento-1.8/app/code/core/Mage/Sales/Model/Order.php#L2152
Looks like it's due to a reporting query that was running for a very long time and keeping the lock for a long time:
INSERT INTO `sales_order_aggregated_updated` (`period`, `store_id`, `order_status`, `orders_count`, `total_qty_ordered`, `total_qty_invoiced`, `total_income_amount`, `total_revenue_amount`, `total_profit_amount`, `total_invoiced_amount`, `total_canceled_amount`, `total_paid_amount`, `total_refunded_amount`, `total_tax_amount`, `total_tax_amount_actual`, `total_shipping_amount`, `total_shipping_amount_actual`, `total_discount_amount`, `total_discount_amount_actual`, `exchanges`, `gifts`)
...
Haven't dug into it much yet, was thinking I should post up a question before diving in. My inclination is to just disable the report aggregation crons entirely and rely on simple order queries (a la Aheadworks Advanced Reports) for reporting.
Solution 2
What I ended up doing was just disabling these reporting crons. Using something like Aheadworks Advanced Reports for reporting or Custom Reports is a lot more manageable in my case.
OTHER TIPS
Magento doesn't properly encapsulate transactions in MySQL, leading to errors such as these. Try setting the session transaction isolation level in MySQL to SERIALIZABLE.