seata并发测试报错:get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1

原创 2019-10-20 22:42 阅读(4317)次
我在做seata并发测试时报如下错误,并发只有3个,其中一个报获得全局锁失败:
2019-10-20 22:07:21.548  INFO 22228 --- [nio-8092-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-10-20 22:07:21.548  INFO 22228 --- [nio-8092-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-10-20 22:07:21.560  INFO 22228 --- [nio-8092-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 11 ms
/api/stockInfo/updateStock拿到分布式事务xid:192.168.64.1:18091:2025291276
2019-10-20 22:07:21.585  INFO 22228 --- [nio-8092-exec-2] i.s.common.loader.EnhancedServiceLoader  : load ContextCore[null] extension by class[io.seata.core.context.ThreadLocalContextCore]
2019-10-20 22:07:21.664  WARN 22228 --- [nfigOperate_1_2] io.seata.config.FileConfiguration        : Could not found property client.lock.retry.policy.branch-rollback-on-conflict, try to use default value instead.
2019-10-20 22:07:21.834  INFO 22228 --- [nio-8092-exec-2] i.s.common.loader.EnhancedServiceLoader  : load LoadBalance[null] extension by class[io.seata.discovery.loadbalance.RandomLoadBalance]
2019-10-20 22:07:21.870  WARN 22228 --- [nio-8092-exec-2] i.s.common.loader.EnhancedServiceLoader  : load [io.seata.rm.datasource.undo.parser.ProtostuffUndoLogParser] class fail. io/protostuff/runtime/RuntimeEnv
2019-10-20 22:07:21.874  INFO 22228 --- [nio-8092-exec-2] i.s.common.loader.EnhancedServiceLoader  : load UndoLogParser[jackson] extension by class[io.seata.rm.datasource.undo.parser.JacksonUndoLogParser]
/api/stockInfo/updateStock拿到分布式事务xid:192.168.64.1:18091:2025291280
/api/stockInfo/updateStock拿到分布式事务xid:192.168.64.1:18091:2025291279
2019-10-20 22:07:22.450 ERROR 22228 --- [nio-8092-exec-3] c.m.c.e.ControllerExceptionAdviceHandle  : 请求/api/stockInfo/updateStock地址出错:
### Error committing transaction.  Cause: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
### Cause: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
; uncategorized SQLException; SQL state [null]; error code [0]; get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1; nested exception is io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
org.springframework.jdbc.UncategorizedSQLException: 
### Error committing transaction.  Cause: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
### Cause: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
; uncategorized SQLException; SQL state [null]; error code [0]; get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1; nested exception is io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
	at com.sun.proxy.$Proxy101.update(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:294)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:67)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
	at com.sun.proxy.$Proxy107.updateStock(Unknown Source)
	at com.mcu.service.StockInfoService.updateStock(StockInfoService.java:20)
	at com.mcu.service.StockInfoService$$FastClassBySpringCGLIB$$25739e26.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	at com.mcu.service.StockInfoService$$EnhancerBySpringCGLIB$$33b22cea.updateStock(<generated>)
	at com.mcu.controller.StockInfoController.updateStock(StockInfoController.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.mcu.filter.CookieFilter.doFilter(CookieFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
	at io.seata.rm.datasource.ConnectionProxy.recognizeLockKeyConflictException(ConnectionProxy.java:148)
	at io.seata.rm.datasource.ConnectionProxy.processGlobalTransactionCommit(ConnectionProxy.java:212)
	at io.seata.rm.datasource.ConnectionProxy.doCommit(ConnectionProxy.java:189)
	at io.seata.rm.datasource.ConnectionProxy.lambda$commit$0(ConnectionProxy.java:177)
	at io.seata.rm.datasource.ConnectionProxy$LockRetryPolicy.execute(ConnectionProxy.java:280)
	at io.seata.rm.datasource.ConnectionProxy.commit(ConnectionProxy.java:176)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.commit(JdbcTransaction.java:71)
	at org.apache.ibatis.executor.BaseExecutor.commit(BaseExecutor.java:244)
	at org.apache.ibatis.executor.CachingExecutor.commit(CachingExecutor.java:119)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
	at com.sun.proxy.$Proxy148.commit(Unknown Source)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:223)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:437)
	... 76 more
ResponseData类发现错误信息:[message]-系统异常,[remark]-[mcu-stock]
### Error committing transaction.  Cause: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
### Cause: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
; uncategorized SQLException; SQL state [null]; error code [0]; get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1; nested exception is io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:192.168.64.1:18091:2025291279, lockKeys:stock_info:1
2019-10-20 22:07:22.897  INFO 22228 --- [atch_RMROLE_1_8] i.s.core.rpc.netty.RmMessageListener     : onMessage:xid=192.168.64.1:18091:2025291280,branchId=2025291283,branchType=AT,resourceId=jdbc:mysql://127.0.0.1:3306/mcu_stock,applicationData=null
2019-10-20 22:07:22.900  INFO 22228 --- [atch_RMROLE_1_8] io.seata.rm.AbstractRMHandler            : Branch committing: 192.168.64.1:18091:2025291280 2025291283 jdbc:mysql://127.0.0.1:3306/mcu_stock null
2019-10-20 22:07:22.901  INFO 22228 --- [atch_RMROLE_1_8] io.seata.rm.AbstractRMHandler            : Branch commit result: PhaseTwo_Committed
2019-10-20 22:07:22.907  INFO 22228 --- [atch_RMROLE_2_8] i.s.core.rpc.netty.RmMessageListener     : onMessage:xid=192.168.64.1:18091:2025291276,branchId=2025291278,branchType=AT,resourceId=jdbc:mysql://127.0.0.1:3306/mcu_stock,applicationData=null
2019-10-20 22:07:22.908  INFO 22228 --- [atch_RMROLE_2_8] io.seata.rm.AbstractRMHandler            : Branch committing: 192.168.64.1:18091:2025291276 2025291278 jdbc:mysql://127.0.0.1:3306/mcu_stock null
2019-10-20 22:07:22.908  INFO 22228 --- [atch_RMROLE_2_8] io.seata.rm.AbstractRMHandler            : Branch commit result: PhaseTwo_Committed

不知道为何会并发3个也不能顺利通过,只能单线程更新,语句如下:

update stock_info t set t.stockCount= t.stockCount - 1 where productId=1 and t.stockCount > 1

如果分布式事务都是insert就不会报错,还在解决中。。

我升级到0.9版本后,再修改了数据源配置后就没有发现这个问题了。自己的开发机上用ab并发测试结果如下:


300个线程并发测试能每秒处理100-150TPS左右

搭建spring cloud +seata分布式事务可参考我另一篇文章:

spring cloud+feign+mybatis中使用seata实现分布式事务