mysql|线上频出MySQL死锁问题!分享一下教科书般的排查和分析过程
1. 日志
1.1 业务日志
【mysql|线上频出MySQL死锁问题!分享一下教科书般的排查和分析过程】一直平稳运行大半年的代码 , 突然在最近几天频出现死锁异常 , 业务机器大概每一两天在业务高峰期发生一次如下的业务日志:
INFO 57553 --- [ConsumerThread2] org.example.controller.TestController : 全局链路跟踪id:2的日志:[TransactionReqVO(userId=4, money=4), TransactionReqVO(userId=2, money=2), TransactionReqVO(userId=5, money=5)] INFO 57553 --- [ConsumerThread1] org.example.controller.TestController : 全局链路跟踪id:1的日志:[TransactionReqVO(userId=5, money=5), TransactionReqVO(userId=1, money=1), TransactionReqVO(userId=4, money=4)]ERROR 57553 --- [ConsumerThread2] org.example.controller.TestController : 全局链路跟踪id:2的异常:### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock try restarting transaction### The error may exist in org/example/mapper/TestTableMapper.java (best guess)### The error may involve org.example.mapper.TestTableMapper.update-Inline### The error occurred while setting parameters### SQL: UPDATE test_table SET money = money + ? WHERE user_id = ?### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock try restarting transaction Deadlock found when trying to get lock try restarting transaction nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock try restarting transactionorg.springframework.dao.DeadlockLoserDataAccessException: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock try restarting transaction### The error may exist in org/example/mapper/TestTableMapper.java (best guess)### The error may involve org.example.mapper.TestTableMapper.update-Inline### The error occurred while setting parameters### SQL: UPDATE test_table SET money = money + ? WHERE user_id = ?### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock try restarting transaction Deadlock found when trying to get lock try restarting transaction nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock try restarting transaction at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:266) ~[spring-jdbc-5.0.13.RELEASE.jar:5.0.13.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.0.13.RELEASE.jar:5.0.13.RELEASE] at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) ~[mybatis-spring-2.0.1.jar:2.0.1] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) ~[mybatis-spring-2.0.1.jar:2.0.1] at com.sun.proxy.$Proxy59.update(Unknown Source) ~[na:na] at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:294) ~[mybatis-spring-2.0.1.jar:2.0.1] at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:67) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) ~[mybatis-3.5.1.jar:3.5.1] at com.sun.proxy.$Proxy62.update(Unknown Source) ~[na:na] at org.example.service.impl.TestServiceImpl.update(TestServiceImpl.java:16) ~[classes/:na] at org.example.manager.impl.BizManagerImpl.transactionMoney(BizManagerImpl.java:25) ~[classes/:na] at org.example.manager.impl.BizManagerImpl$$FastClassBySpringCGLIB$$824241b9.invoke(
推荐阅读
- 销售|Beyond Meat开始在线上销售植物肉
- 自营区|跨界视聊为你解析:实体店生意难做,如何借助线上平台开店引流拓客?
- 中年|京广线上的“接骨手术”
- 用友社会化用工研究院|线上营销优势尽显,用友薪福社赋能科技,助企业打通运营闭环
- 企业|字节跳动副总裁谢欣:线上办公趋势不可逆
- 大闸蟹|乱象频出 电商平台推动大闸蟹行业规范化
- 门店|乐金(LG)借助向日葵搭建百家门店线上运维体系
- 快手|快手联合QQ音乐举办“12号唱片”唱作人大赛,海选结束300强佳作频出
- 母婴|宝宝树发布《2020母婴消费洞察报告》:线上渠道销售额增速达24.2%
- |2020年线上显卡前十销量曝光,七彩虹不是第一,微星不进前五