美文网首页
记一次update死锁处理

记一次update死锁处理

作者: bobozhangshao | 来源:发表于2019-10-24 14:10 被阅读0次

背景

让DBA查日志

show engine innodb status
可以看到两条数据

UPDATE  nr_activity_dish SET day_stock='9999', dstock_update_time='20191024' WHERE (activity_id =  '5000000003940695') AND (dish_id =  '1547797854069605')

UPDATE  nr_activity_dish SET day_stock='9999', dstock_update_time='20191024' WHERE (activity_id =  '5000000003940695') AND (dish_id =  '15477812970614023')

虽然acitivity_id和dish_id都是独立索引,但是update加锁时候只会使用一个,导致多行数据被锁

------------------------
LATEST DETECTED DEADLOCK
------------------------
2019-10-24 01:08:15 7f7f58063700
*** (1) TRANSACTION:
TRANSACTION 2559276227, ACTIVE 0 sec fetching rows
mysql tables in use 3, locked 3
LOCK WAIT 396 lock struct(s), heap size 46632, 4 row lock(s)
MySQL thread id 22749534, OS thread handle 0x7f7f4ea61700, query id 5012948981 10.252.16.9 mai_elemarketing Searching rows for update
/*E:shardkey=shardid&appid=bdwaimai_marketing.elemarketing&shardvalue=11&rid=bdwaimai_wmq.pusher^^6004B4B47E7B4332B85DDBE44BD6E15C|1571850495596&rpcid=1.1.5:E*//*E:group=place_waimai_elemarketing-bdwaimai_marketing_elemarketing_group&sqlId=9000591fb4342a9196717dfad9f4d6c4:E*/UPDATE  nr_activity_dish SET day_stock='9999', dstock_update_time='20191024' WHERE (activity_id =  '5000000003940695') AND (dish_id =  '1547797854069605')
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 31 page no 33335403 n bits 80 index `PRIMARY` of table `place_waimai_elemarketing`.`nr_activity_dish` trx id 2559276227 lock_mode X locks rec but not gap waiting
Record lock, heap no 11 PHYSICAL RECORD: n_fields 23; compact format; info bits 0
 0: len 8; hex 80000000a8f7234b; asc       #K;;
 1: len 6; hex 00009775741a; asc    ut ;;
 2: len 7; hex 38000078352df6; asc 8  x5- ;;
 3: len 8; hex 0011c379381ca157; asc    y8  W;;
 4: len 8; hex 00000000850540fd; asc       @ ;;
 5: len 8; hex 0036fcfd28036d07; asc  6  ( m ;;
 6: len 19; hex e781abe783a7203730672a34e4b8aa2fe7bb84; asc        70g*4   /   ;;
 7: len 4; hex 800001e0; asc     ;;
 8: len 4; hex 800001e0; asc     ;;
 9: len 30; hex 7b2261637469766974795f6964223a223530303030303030303339343036; asc {"activity_id":"50000000039406; (total 908 bytes);
 10: len 4; hex 8000000a; asc     ;;
 11: len 4; hex 0000270f; asc   ' ;;
 12: len 4; hex 0000270f; asc   ' ;;
 13: len 4; hex 8000270f; asc   ' ;;
 14: len 4; hex 8000270f; asc   ' ;;
 15: len 4; hex 8134172f; asc  4 /;;
 16: len 4; hex 80000000; asc     ;;
 17: len 4; hex 80000000; asc     ;;
 18: len 1; hex 01; asc  ;;
 19: len 4; hex 5da5e015; asc ]   ;;
 20: len 4; hex 5daf3711; asc ] 7 ;;
 21: len 8; hex 8000000000000012; asc         ;;
 22: len 6; hex 5daf37110bae; asc ] 7   ;;

*** (2) TRANSACTION:
TRANSACTION 2559276230, ACTIVE 0 sec fetching rows
mysql tables in use 3, locked 3
396 lock struct(s), heap size 46632, 3 row lock(s)
MySQL thread id 22749588, OS thread handle 0x7f7f58063700, query id 5012948983 10.252.64.4 mai_elemarketing Searching rows for update
/*E:shardkey=shardid&appid=bdwaimai_marketing.elemarketing&shardvalue=11&rid=bdwaimai_wmq.pusher^^01FC6E0EFC4C4168BCEAD2F136D68D15|1571850495598&rpcid=1.1.5:E*//*E:group=place_waimai_elemarketing-bdwaimai_marketing_elemarketing_group&sqlId=9000591fb4342a9196717dfad9f4d6c4:E*/UPDATE  nr_activity_dish SET day_stock='9999', dstock_update_time='20191024' WHERE (activity_id =  '5000000003940695') AND (dish_id =  '15477812970614023')
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 31 page no 33335403 n bits 80 index `PRIMARY` of table `place_waimai_elemarketing`.`nr_activity_dish` trx id 2559276230 lock_mode X locks rec but not gap
Record lock, heap no 11 PHYSICAL RECORD: n_fields 23; compact format; info bits 0
 0: len 8; hex 80000000a8f7234b; asc       #K;;
 1: len 6; hex 00009775741a; asc    ut ;;
 2: len 7; hex 38000078352df6; asc 8  x5- ;;
 3: len 8; hex 0011c379381ca157; asc    y8  W;;
 4: len 8; hex 00000000850540fd; asc       @ ;;
 5: len 8; hex 0036fcfd28036d07; asc  6  ( m ;;
 6: len 19; hex e781abe783a7203730672a34e4b8aa2fe7bb84; asc        70g*4   /   ;;
 7: len 4; hex 800001e0; asc     ;;
 8: len 4; hex 800001e0; asc     ;;
 9: len 30; hex 7b2261637469766974795f6964223a223530303030303030303339343036; asc {"activity_id":"50000000039406; (total 908 bytes);
 10: len 4; hex 8000000a; asc     ;;
 11: len 4; hex 0000270f; asc   ' ;;
 12: len 4; hex 0000270f; asc   ' ;;
 13: len 4; hex 8000270f; asc   ' ;;
 14: len 4; hex 8000270f; asc   ' ;;
 15: len 4; hex 8134172f; asc  4 /;;
 16: len 4; hex 80000000; asc     ;;
 17: len 4; hex 80000000; asc     ;;
 18: len 1; hex 01; asc  ;;
 19: len 4; hex 5da5e015; asc ]   ;;
 20: len 4; hex 5daf3711; asc ] 7 ;;
 21: len 8; hex 8000000000000012; asc         ;;
 22: len 6; hex 5daf37110bae; asc ] 7   ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 31 page no 35689285 n bits 824 index `idx_aid` of table `place_waimai_elemarketing`.`nr_activity_dish` trx id 2559276230 lock_mode X locks rec but not gap waiting
Record lock, heap no 63 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
 0: len 8; hex 0011c379381ca157; asc    y8  W;;
 1: len 8; hex 80000000a8f7234b; asc       #K;;

*** WE ROLL BACK TRANSACTION (2)

相关文章

  • 记一次update死锁处理

    背景 让DBA查日志 show engine innodb status可以看到两条数据 虽然acitivity_...

  • insert on update死锁

    表结构 隔离级别 RR 死锁日志2020-01-08 16:55:44 0x7fc3dc431700*** (1)...

  • 发生死锁的情形

    多条insert on duplicate key update 死锁的原因 https://mp.weixin...

  • 死锁

    第11章:死锁和进程通信 死锁概念 死锁处理方法 死锁预防(Deadlock Prevention) 死锁避免(D...

  • [现代操作系统]--死锁

    table of content 死锁定义 死锁建模-- 资源分配图 处理死锁鸵鸟算法检测并恢复死锁检测死锁恢复利...

  • sql语句中的坑

    1、update无主键时lock table 连接数打满update 必须是主键,否则可能死锁http://bl...

  • mysql多线程update死锁问题

    最近想起之前处理过的一个mysql 死锁问题,是在高并发下update批量更新导致的,这里探讨一下发生的原因,以及...

  • java多线程笔记

    产生死锁的四个必要条件 处理死锁的基本方法 死锁预防 死锁避免 死锁检测 死锁解除 https://blog.cs...

  • 项目常见崩溃12(陆续更新)

    说起死锁, 可能很多人都懂其中的原理, 但是却很少有人真正解决甚至遇到过死锁, 最近有幸真的处理了一次死锁. 这次...

  • mysql for update 死锁问题

    在RR条件, id是主键,插入五条数据 我们可以发现 针对事务一:select * from user where...

网友评论

      本文标题:记一次update死锁处理

      本文链接:https://www.haomeiwen.com/subject/iforvctx.html