当前位置 : 首页 » 文章分类 :  开发  »  一次MySQL死锁案例分析

一次MySQL死锁案例分析

首页文章列表中的简介

分析

业务上来说,是两个用户同时对 account1_id=55735549 这个用户进行取关操作,同时写 app_user_relationship 表时导致死锁。

代码层面,对 account1_id-account2_id 这个key加了redis分布式锁,所以同时写 account1 和 account2 都相同的,分布式锁层面就会拦截住,但这两个sql account2不同,分布式锁锁不住。

explain 下这条sql语句:

MariaDB [uds]> explain UPDATE app_user_relationship SET relation = 0, relation_before = 2, channel = 0, app_id = 100043 WHERE account1_id =55735549 AND account2_id = 126475;
+------+-------------+-----------------------+-------------+-------------------------+-------------------------+---------+------+------+-------------------------------------------------------+
| id   | select_type | table                 | type        | possible_keys           | key                     | key_len | ref  | rows | Extra                                                 |
+------+-------------+-----------------------+-------------+-------------------------+-------------------------+---------+------+------+-------------------------------------------------------+
|    1 | SIMPLE      | app_user_relationship | index_merge | account1_id,account2_id | account1_id,account2_id | 9,9     | NULL |    1 | Using intersect(account1_id,account2_id); Using where |
+------+-------------+-----------------------+-------------+-------------------------+-------------------------+---------+------+------+-------------------------------------------------------+
1 row in set (0.009 sec)

同事帮看了下,看到explain的type是index_merge,感觉像是走交叉索引导致的死锁。
这个表在 account1 和 account2 上都有外键,外键默认会创建索引,所以这条sql会同时使用2个索引来加速。
上网搜了下,有好多类似情况,大体上能确定原因就是这个。

InnoDB行锁是通过给索引上的索引项加锁来实现的,InnoDB这种行锁实现特点意味着:只有通过索引条件检索数据,InnoDB才使用行级锁,否则,InnoDB将使用表锁!
在实际应用中,要特别注意InnoDB行锁的这一特性,不然的话,可能导致大量的锁冲突,从而影响并发性能。
1、在不通过索引条件查询的时候,InnoDB 确实使用的是表锁,而不是行锁。
2、由于 MySQL 的行锁是针对索引加的锁,不是针对记录加的锁,所以虽然是访问不同行 的记录,但是如果是使用相同的索引键,是会出现锁冲突的。应用设计的时候要注意这一点。
3、当表有多个索引的时候,不同的事务可以使用不同的索引锁定不同的行,另外,不论 是使用主键索引、唯一索引或普通索引,InnoDB 都会使用行锁来对数据加锁。
4、即便在条件中使用了索引字段,但是否使用索引来检索数据是由 MySQL 通过判断不同 执行计划的代价来决定的,如果 MySQL 认为全表扫 效率更高,比如对一些很小的表,它 就不会使用索引,这种情况下 InnoDB 将使用表锁,而不是行锁。因此,在分析锁冲突时, 别忘了检查 SQL 的执行计划,以确认是否真正使用了索引。

MySQL中的行级锁,表级锁,页级锁
http://www.hollischuang.com/archives/914

index_merge引发的死锁排查
https://www.cnblogs.com/cchust/p/6464188.html

index merge 引起的死锁分析
http://seanlook.com/2017/03/11/mysql-index_merge-deadlock/

解决

解决方法:加联合索引
添加联合索引 account_key(account1_id,account2_id),这样以来查询会选择这一个索引,至于 idx_sid 这个单列索引还需不需要,看业务场景。

创建联合索引:

create index idx_account1_2 on app_user_relationship (account1_id, account2_id);

创建之后再explain下这个SQL:

MariaDB [uds]> explain UPDATE app_user_relationship SET relation = 0, relation_before = 2, channel = 0, app_id = 100043 WHERE account1_id =55735549 AND account2_id = 126475;
+------+-------------+-----------------------+---------+-----------------------------+-------------------------+---------+------+------+-------------+
| id   | select_type | table                 | type    | possible_keys               | key                     | key_len | ref  | rows | Extra       |
+------+-------------+-----------------------+---------+-----------------------------+-------------------------+---------+------+------+-------------+
|    1 | SIMPLE      | app_user_relationship | range   | account2_id,idx_account1_2  | idx_account1_2          | 18      | NULL |    1 | Using where |
+------+-------------+-----------------------+---------+-----------------------------+-------------------------+---------+------+------+-------------+
1 row in set (0.009 sec)

index_merge 变为 range

但我在test环境上,创建联合索引后,explain 还是 index_merge,DBA在生产上explain是range,说索引跟数据量关系很大,就算结构一样,数据量不一样的表,走的索引也不太一样的

表结构

create table app_user_relationship
(
    id bigint auto_increment
        primary key,
    app_id int not null,
    user1_id bigint not null,
    user2_id bigint not null,
    account1_id bigint null,
    account2_id bigint null,
    relation smallint(6) not null comment '关系类型:0-初始关系 1-好友关系,2-关注,3-被关注',
    relation_before smallint(6) not null comment '之前的关系,关系类型:0-初始关系,1-好友关系,2-关注,3-被关注',
    create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
    update_time timestamp default CURRENT_TIMESTAMP not null comment '修改时间',
    channel tinyint not null,
    constraint user1_id
        unique (user1_id, user2_id),
    constraint app_user_relationship_ibfk_1
        foreign key (user1_id) references uds.user (id),
    constraint app_user_relationship_ibfk_2
        foreign key (user2_id) references uds.user (id),
    constraint app_user_relationship_ibfk_3
        foreign key (account1_id) references uds.user_account_info (account_id),
    constraint app_user_relationship_ibfk_4
        foreign key (account2_id) references uds.user_account_info (account_id)
)
;

create index account1_id
    on app_user_relationship (account1_id)
;

create index account2_id
    on app_user_relationship (account2_id)
;

create index user2_id
    on app_user_relationship (user2_id)
;

MySQL死锁日志

show engine innodb status;

------------------------
LATEST DETECTED DEADLOCK
------------------------
2018-11-05 19:07:44 2b6bcb03f700
*** (1) TRANSACTION:
TRANSACTION 67059742790, ACTIVE 0 sec fetching rows
mysql tables in use 3, locked 3
LOCK WAIT 462 lock struct(s), heap size 63016, 4 row lock(s)
MySQL thread id 39706604, OS thread handle 0x2b6ba0f91700, query id 168182824647 10.128.18.185 uds_prod_w updating
UPDATE app_user_relationship SET relation = 0, relation_before = 2, channel = 0, app_id = 100043 WHERE account1_id =55735549 AND account2_id = 1800241143
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 536 page no 65409 n bits 264 index `PRIMARY` of table `uds`.`app_user_relationship` trx table locks 1 total table locks 2  trx id 67059742790 lock_mode X locks rec but not gap waiting lock hold time 0 wait time before grant 0
*** (2) TRANSACTION:
TRANSACTION 67059742791, ACTIVE 0 sec fetching rows
mysql tables in use 3, locked 3
641 lock struct(s), heap size 95784, 3 row lock(s)
MySQL thread id 39707153, OS thread handle 0x2b6bcb03f700, query id 168182824649 10.128.19.96 uds_prod_w updating
UPDATE app_user_relationship SET relation = 0, relation_before = 2, channel = 0, app_id = 100043 WHERE account1_id =55735549 AND account2_id = 126475
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 536 page no 65409 n bits 264 index `PRIMARY` of table `uds`.`app_user_relationship` trx table locks 1 total table locks 2  trx id 67059742791 lock_mode X locks rec but not gap lock hold time 0 wait time before grant 0
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 536 page no 29223 n bits 792 index `account1_id` of table `uds`.`app_user_relationship` trx table locks 1 total table locks 2  trx id 67059742791 lock_mode X locks rec but not gap waiting lock hold time 0 wait time before grant 0
*** WE ROLL BACK TRANSACTION (1)

服务端异常信息

[Handled] unknown exception
org.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 involve com.nio.uds.relation.mapper.MyRelationMapper.updateAppUserRelation-Inline
### The error occurred while setting parameters
### SQL: UPDATE app_user_relationship SET relation = ?, relation_before = ?, channel = ?, app_id = ? WHERE account1_id =? AND account2_id = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
; SQL []; 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:263) ~[spring-jdbc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) ~[mybatis-spring-1.3.0.jar!/:1.3.0]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447) ~[mybatis-spring-1.3.0.jar!/:1.3.0]
    at com.sun.proxy.$Proxy120.update(Unknown Source) ~[?:?]
    at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:295) ~[mybatis-spring-1.3.0.jar!/:1.3.0]
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:59) ~[mybatis-3.4.0.jar!/:3.4.0]
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[mybatis-3.4.0.jar!/:3.4.0]
    at com.sun.proxy.$Proxy137.updateAppUserRelation(Unknown Source) ~[?:?]
    at com.nio.uds.relation.dao.RelationDao.updateAppUserRelationship(RelationDao.java:117) ~[classes!/:1.0.0-SNAPSHOT]
    at com.nio.uds.relation.biz.AppUserRelationBiz.followUser(AppUserRelationBiz.java:66) ~[classes!/:1.0.0-SNAPSHOT]
    at com.nio.uds.relation.biz.AppUserRelationBiz$$FastClassBySpringCGLIB$$48b030e7.invoke(<generated>) ~[classes!/:1.0.0-SNAPSHOT]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at com.nio.uds.relation.biz.AppUserRelationBiz$$EnhancerBySpringCGLIB$$154499b7.followUser(<generated>) ~[classes!/:1.0.0-SNAPSHOT]
    at com.nio.uds.relation.service.RelationLockService.followUser(RelationLockService.java:49) ~[classes!/:1.0.0-SNAPSHOT]
    at com.nio.uds.relation.service.RelationLockService$$FastClassBySpringCGLIB$$95b5ab74.invoke(<generated>) ~[classes!/:1.0.0-SNAPSHOT]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:97) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at com.nio.uds.common.aspect.DistributedLockAspect.lock(DistributedLockAspect.java:104) ~[uds-common-3.2.76.jar!/:3.2.76]
    at sun.reflect.GeneratedMethodAccessor391.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at com.nio.uds.relation.service.RelationLockService$$EnhancerBySpringCGLIB$$82b9878f.followUser(<generated>) ~[classes!/:1.0.0-SNAPSHOT]
    at com.nio.uds.relation.service.AppUserRelationService.followUsers(AppUserRelationService.java:209) ~[classes!/:1.0.0-SNAPSHOT]
    at com.nio.uds.relation.controller.AppUserRelationV2Controller.followUsersIntAid(AppUserRelationV2Controller.java:117) ~[classes!/:1.0.0-SNAPSHOT]
    at com.nio.uds.relation.controller.AppUserRelationV2Controller$$FastClassBySpringCGLIB$$5e37314f.invoke(<generated>) ~[classes!/:1.0.0-SNAPSHOT]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at com.nio.uds.common.aspect.FalconAspect.monitorByFalcon(FalconAspect.java:40) ~[uds-common-3.2.76.jar!/:3.2.76]
    at sun.reflect.GeneratedMethodAccessor191.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:97) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at com.nio.uds.common.aspect.RequestAspect.doRequestAspect(RequestAspect.java:129) ~[uds-common-3.2.76.jar!/:3.2.76]
    at com.nio.uds.common.aspect.RequestAspect.doApiRequestAspect(RequestAspect.java:100) ~[uds-common-3.2.76.jar!/:3.2.76]
    at sun.reflect.GeneratedMethodAccessor190.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at com.nio.uds.relation.controller.AppUserRelationV2Controller$$EnhancerBySpringCGLIB$$ca4c8df6.followUsersIntAid(<generated>) ~[classes!/:1.0.0-SNAPSHOT]
    at sun.reflect.GeneratedMethodAccessor390.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) ~[spring-boot-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:111) ~[spring-boot-actuator-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106) ~[spring-boot-actuator-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:64) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104) ~[undertow-servlet-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:336) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) ~[undertow-core-1.4.23.Final.jar!/:1.4.23.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_181]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_181]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_181]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_181]
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:952) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) ~[HikariCP-2.4.7.jar!/:?]
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) ~[HikariCP-2.4.7.jar!/:?]
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46) ~[mybatis-3.4.0.jar!/:3.4.0]
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) ~[mybatis-3.4.0.jar!/:3.4.0]
    at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) ~[mybatis-3.4.0.jar!/:3.4.0]
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) ~[mybatis-3.4.0.jar!/:3.4.0]
    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) ~[mybatis-3.4.0.jar!/:3.4.0]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) ~[mybatis-3.4.0.jar!/:3.4.0]
    at sun.reflect.GeneratedMethodAccessor429.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434) ~[mybatis-spring-1.3.0.jar!/:1.3.0]
    ... 140 more

下一篇 Spring-RedisTemplate

阅读
4,711
阅读预计27分钟
创建日期 2018-11-06
修改日期 2018-11-07
类别
百度推荐