你好老师,这个问题最近又出现了,在大量插入数据时出现的
目前TiDB 已经改成了 全局的悲观锁模式
v3.0.5
java 程序 异常
Caused by: java.sql.SQLException: Error: KV error safe to retry tikv restarts txn: Txn(Mvcc(TxnLockNotFound { start_ts: 413963114113925133, commit_ts: 413963128571166725, key: […] })) [try again later]
20-01-16 11:06:54 TraceId:[] [SimpleAsyncTaskExecutor-1] WARN o.s.a.r.l.ConditionalRejectingErrorHandler - Execution of Rabbit message listener failed.
org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:941)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:851)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:771)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:102)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:198)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1311)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:752)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1254)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1224)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:102)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1470)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: commit failed
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:588)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:518)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.sinoeyes.db.service.pfizer.DcFlowdataDeliverSaleManager$$EnhancerBySpringCGLIB$$ee57639f.saveDcFlowdataDeliverSale(<generated>)
at com.sinoeyes.mapping.service.SourceToFinalService.transferEdiSale(SourceToFinalService.java:493)
at com.sinoeyes.mapping.service.SourceToFinalService.invokeTransfer(SourceToFinalService.java:278)
at com.sinoeyes.mapping.service.SourceToFinalService.lambda$transferData2Final$0(SourceToFinalService.java:114)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at com.sinoeyes.mapping.service.SourceToFinalService.transferData2Final(SourceToFinalService.java:106)
at com.sinoeyes.mapping.service.SourceToFinalService$$FastClassBySpringCGLIB$$8a43d1f6.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
at com.sinoeyes.log.annotation.TuningMonitorLogger.aroundAdvisor(TuningMonitorLogger.java:77)
at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.sinoeyes.mapping.service.SourceToFinalService$$EnhancerBySpringCGLIB$$fe3ed9b2.transferData2Final(<generated>)
at com.sinoeyes.mapping.listener.CheckAllPending2FinalListener.onMessage(CheckAllPending2FinalListener.java:41)
at com.sinoeyes.mapping.listener.CheckAllPending2FinalListener.onMessage(CheckAllPending2FinalListener.java:18)
at com.sinoeyes.jms.AbstractQueueMessageReceiver$1.onMessage(AbstractQueueMessageReceiver.java:84)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:848)
... 10 common frames omitted
Caused by: org.hibernate.TransactionException: commit failed
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:187)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
... 46 common frames omitted
Caused by: org.hibernate.TransactionException: unable to commit against JDBC connection
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:116)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:180)
... 47 common frames omitted
Caused by: java.sql.SQLException: Error: KV error safe to retry tikv restarts txn: Txn(Mvcc(TxnLockNotFound { start_ts: 413963114113925133, commit_ts: 413963128571166725, key: [116, 128, 0, 0, 0, 0, 0, 52, 197, 95, 105, 128, 0, 0, 0, 0, 0, 0, 1, 1, 56, 97, 55, 52, 56, 99, 55, 50, 255, 54, 102, 97, 99, 51, 56, 97, 55, 255, 48, 49, 54, 102, 97, 99, 53, 48, 255, 57, 51, 100, 50, 50, 49, 53, 53, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247] })) [try again later]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1548)
at com.alibaba.druid.pool.DruidPooledConnection.commit(DruidPooledConnection.java:749)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:112)
... 48 common frames omitted
20-01-16 10:49:29 TraceId:[] [SimpleAsyncTaskExecutor-1] WARN o.s.a.r.l.ConditionalRejectingErrorHandler - Execution of Rabbit message listener failed.
org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:941)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:851)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:771)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:102)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:198)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1311)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:752)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1254)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1224)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:102)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1470)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: commit failed
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:588)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:518)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.sinoeyes.db.service.pfizer.DcFlowdataDeliverSaleManager$$EnhancerBySpringCGLIB$$bec7121e.saveDcFlowdataDeliverSale(<generated>)
at com.sinoeyes.mapping.service.SourceToFinalService.transferEdiSale(SourceToFinalService.java:493)
at com.sinoeyes.mapping.service.SourceToFinalService.invokeTransfer(SourceToFinalService.java:278)
at com.sinoeyes.mapping.service.SourceToFinalService.lambda$transferData2Final$0(SourceToFinalService.java:114)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at com.sinoeyes.mapping.service.SourceToFinalService.transferData2Final(SourceToFinalService.java:106)
at com.sinoeyes.mapping.service.SourceToFinalService$$FastClassBySpringCGLIB$$8a43d1f6.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
at com.sinoeyes.log.annotation.TuningMonitorLogger.aroundAdvisor(TuningMonitorLogger.java:77)
at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.sinoeyes.mapping.service.SourceToFinalService$$EnhancerBySpringCGLIB$$2c540f63.transferData2Final(<generated>)
at com.sinoeyes.mapping.listener.CheckAllPending2FinalListener.onMessage(CheckAllPending2FinalListener.java:41)
at com.sinoeyes.mapping.listener.CheckAllPending2FinalListener.onMessage(CheckAllPending2FinalListener.java:18)
at com.sinoeyes.jms.AbstractQueueMessageReceiver$1.onMessage(AbstractQueueMessageReceiver.java:84)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:848)
... 10 common frames omitted
Caused by: org.hibernate.TransactionException: commit failed
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:187)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
... 46 common frames omitted
Caused by: org.hibernate.TransactionException: unable to commit against JDBC connection
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:116)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:180)
... 47 common frames omitted
Caused by: java.sql.SQLException: Error: KV error safe to retry tikv restarts txn: Txn(Mvcc(TxnLockNotFound { start_ts: 413962849663057923, commit_ts: 413962854552043522, key: [116, 128, 0, 0, 0, 0, 0, 52, 197, 95, 105, 128, 0, 0, 0, 0, 0, 0, 1, 1, 56, 97, 55, 52, 56, 55, 57, 55, 255, 54, 102, 97, 99, 51, 56, 55, 52, 255, 48, 49, 54, 102, 97, 99, 52, 49, 255, 50, 102, 49, 48, 48, 99, 55, 50, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247] })) [try again later]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1548)
at com.alibaba.druid.pool.DruidPooledConnection.commit(DruidPooledConnection.java:749)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:112)
... 48 common frames omitted
tidb.log
[2020/01/16 11:06:54.650 +08:00] [INFO] [coprocessor.go:743] ["[TIME_COP_PROCESS] resp_time:26.194490676s txnStartTS:413963121702993925 region_id:89025 store_addr:172.106.180.53:20160 kv_process_ms:216 scan_total_write:198304 scan_processed_write:132680 scan_total_data:198155 scan_processed_data:132680 scan_total_lock:1 scan_processed_lock:0"]
[2020/01/16 11:06:54.650 +08:00] [INFO] [region_cache.go:287] ["invalidate current region, because others failed on same store"] [region=40] [store=172.106.180.53:20160]
[2020/01/16 11:06:54.656 +08:00] [INFO] [coprocessor.go:743] ["[TIME_COP_PROCESS] resp_time:5.770516127s txnStartTS:413963113956638724 region_id:89377 store_addr:172.106.180.53:20160"]
[2020/01/16 11:06:54.658 +08:00] [WARN] [session.go:446] ["commit failed"] [conn=22869] ["finished txn"="Txn{state=invalid}"] [error="[kv:6]Error: KV error safe to retry tikv restarts txn: Txn(Mvcc(TxnLockNotFound { start_ts: 413963114113925133, commit_ts: 413963128571166725, key: [116, 128, 0, 0, 0, 0, 0, 52, 197, 95, 105, 128, 0, 0, 0, 0, 0, 0, 1, 1, 56, 97, 55, 52, 56, 99, 55, 50, 255, 54, 102, 97, 99, 51, 56, 97, 55, 255, 48, 49, 54, 102, 97, 99, 53, 48, 255, 57, 51, 100, 50, 50, 49, 53, 53, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247] })) [try again later]"]
[2020/01/16 11:06:54.658 +08:00] [WARN] [session.go:964] ["run statement error"] [conn=22869] [schemaVersion=14017] [error="previous statement: /*......*/ insert into dc_fds (..............) values (..........): [kv:6]Error: KV error safe to retry tikv restarts txn: Txn(Mvcc(TxnLockNotFound { start_ts: 413963114113925133, commit_ts: 413963128571166725, key: [116, 128, 0, 0, 0, 0, 0, 52, 197, 95, 105, 128, 0, 0, 0, 0, 0, 0, 1, 1, 56, 97, 55, 52, 56, 99, 55, 50, 255, 54, 102, 97, 99, 51, 56, 97, 55, 255, 48, 49, 54, 102, 97, 99, 53, 48, 255, 57, 51, 100, 50, 50, 49, 53, 53, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247] })) [try again later]"] [errorVerbose="[kv:6]Error: KV error safe to retry tikv restarts txn: Txn(Mvcc(TxnLockNotFound { start_ts: 413963114113925133, commit_ts: 413963128571166725, key: [116, 128, 0, 0, 0, 0, 0, 52, 197, 95, 105, 128, 0, 0, 0, 0, 0, 0, 1, 1, 56, 97, 55, 52, 56, 99, 55, 50, 255, 54, 102, 97, 99, 51, 56, 97, 55, 255, 48, 49, 54, 102, 97, 99, 53, 48, 255, 57, 51, 100, 50, 50, 49, 53, 53, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247] })) [try again later]\
previous statement: /*......*/ insert into dc_fds (.......) values (......)"] [session="{\
\"currDBName\": \"pressure_pf\",\
\"id\": 22869,\
\"status\": 0,\
\"strictMode\": true,\
\"user\": {\
\"Username\": \"root\",\
\"Hostname\": \"172.106.181.51\",\
\"CurrentUser\": false,\
\"AuthUsername\": \"root\",\
\"AuthHostname\": \"%\"\
}\
}"]
[2020/01/16 11:06:54.659 +08:00] [WARN] [conn.go:682] ["dispatch error"] [conn=22869] [connInfo="id:22869, addr:172.160.181.51:47446 status:0, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:0"] [sql=commit] [err="[kv:6]Error: KV error safe to retry tikv restarts txn: Txn(Mvcc(TxnLockNotFound { start_ts: 413963114113925133, commit_ts: 413963128571166725, key: [116, 128, 0, 0, 0, 0, 0, 52, 197, 95, 105, 128, 0, 0, 0, 0, 0, 0, 1, 1, 56, 97, 55, 52, 56, 99, 55, 50, 255, 54, 102, 97, 99, 51, 56, 97, 55, 255, 48, 49, 54, 102, 97, 99, 53, 48, 255, 57, 51, 100, 50, 50, 49, 53, 53, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247] })) [try again later]\
previous statement: /*......*/ insert into dc_fds (.......) values (.......)"]
[2020/01/16 11:06:54.660 +08:00] [INFO] [coprocessor.go:743] ["[TIME_COP_PROCESS] resp_time:554.768763ms txnStartTS:413963128426987525 region_id:89045 store_addr:172.160.180.59:20160 kv_process_ms:554 scan_total_write:137280 scan_processed_write:137279 scan_total_data:137279 scan_processed_data:137279 scan_total_lock:1 scan_processed_lock:0"]
[2020/01/16 11:06:54.672 +08:00] [INFO] [coprocessor.go:743] ["[TIME_COP_PROCESS] resp_time:4.465431012s txnStartTS:413963113956638724 region_id:89377 store_addr:172.160.180.53:20160"]
[2020/01/16 11:06:54.673 +08:00] [INFO] [coprocessor.go:743] ["[TIME_COP_PROCESS] resp_time:5.625270458s txnStartTS:413963113956638724 region_id:136647 store_addr:172.160.180.53:20160"]
[2020/01/16 11:06:54.673 +08:00] [INFO] [coprocessor.go:743] ["[TIME_COP_PROCESS] resp_time:5.421161595s txnStartTS:413963113956638724 region_id:136647 store_addr:172.160.180.53:20160"]
监控图表