我在交易中创建订单时遇到了死锁。 Spree Adjustments表获取锁定并继续更新Promotions或TaxOns。同时,其他请求或订单需要更新相同的记录。
------------------------
LATEST DETECTED DEADLOCK
------------------------
2016-09-17 20:40:15 7fee358d0b00
*** (1) TRANSACTION:
TRANSACTION 3880159183, ACTIVE 2 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 10 lock struct(s), heap size 2936, 7 row lock(s), undo log entries 18
MySQL thread id 128414, OS thread handle 0x7fee6fd6ab00, query id 53800114 172.31.34.254 connect_api_user updating
UPDATE `my_variants` SET `my_variants`.`quantity` = 2, `my_variants`.`updated_at` = '2016-09-17 20:40:43' WHERE `my_variants`.`id` = 108430
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 2414 page no 1809 n bits 88 index `PRIMARY` of table `marketplace`.`my_variants` trx table locks 5 total table locks 2 trx id 3880159183 lock_mode X locks rec but not gap waiting lock hold time 2 wait time before grant 0
*** (2) TRANSACTION:
TRANSACTION 3880159065, ACTIVE 3 sec starting index read
mysql tables in use 1, locked 1
22 lock struct(s), heap size 2936, 15 row lock(s), undo log entries 36
MySQL thread id 125879, OS thread handle 0x7fee358d0b00, query id 53804455 172.31.34.254 connect_api_user updating
UPDATE `spree_adjustments` SET `spree_adjustments`.`eligible` = 0 WHERE `spree_adjustments`.`adjustable_id` = 2298885 AND `spree_adjustments`.`adjustable_type` = 'Spree::LineItem' AND `spree_adjustments`.`source_type` = 'Spree::PromotionAction' AND (`spree_adjustments`.`id` != 665173)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 2414 page no 1809 n bits 88 index `PRIMARY` of table `marketplace`.`teni_variants` trx table locks 13 total table locks 2 trx id 3880159065 lock_mode X locks rec but not gap lock hold time 2 wait time before grant 0
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1544 page no 2024 n bits 432 index `index_spree_adjustments_on_adjustable_id_and_adjustable_type` of table `marketplace`.`spree_adjustments` trx table locks 13 total table locks 2 trx id 3880159065 lock_mode X locks rec but not gap waiting lock hold time 0 wait time before grant 0
*** WE ROLL BACK TRANSACTION (1)