Open wenchongyang opened 6 years ago
我这面也出现了同一的问题,事务提交失败,导致之后对数据库所有的查询操作均异常。
这个是Mycat对事务性操作的检查机制的缺漏,希望及早修复。
Error querying database. Cause: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry '0' for key 'PRIMARY'
The error may exist in file [/opt/tomcat/webapps/ROOT/WEB-INF/classes/com/hikvision/modules/memberManager/user/mapper/UserMapper.xml]
The error may involve com.hikvision.modules.memberManager.user.dao.UserMapper.find-Inline
The error occurred while setting parameters
SQL: select user_id, user_login_id, user_name, password, pwd_ind, phone_id, user_status, user_desc, locked, begin_time, end_time, ios_token, android_registe_id, is_delete, cre_id, cre_name, cre_time, upd_id, upd_name, upd_time, user_level, reserve1_int, reserve2_int, reserve3_int, reserve4_string, reserve5_string, reserve6_string,auto_login_token,login_token_time,token_valid_time,last_login_error_time,login_error_times,wechat_name from pub_user WHERE is_delete=0 and auto_login_token = ?
Cause: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry '0' for key 'PRIMARY'
; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1003]; Transaction error, need to rollback. errno:1062 Duplicate entry '0' for key 'PRIMARY'; nested exception is java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry '0' for key 'PRIMARY' at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) 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:74) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) at com.sun.proxy.$Proxy21.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) at com.sun.proxy.$Proxy32.find(Unknown Source) at com.hikvision.modules.memberManager.user.service.impl.UserServiceImpl.getUserInfoByAutoKey(UserServiceImpl.java:498) at com.testcom.modules.memberManager.user.service.impl.UserServiceImpl$$FastClassBySpringCGLIB$$e76d0f8d.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) 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:655) at com.hikvision.modules.memberManager.user.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$fdfce521.getUserInfoByAutoKey() at com.hikvision.modules.memberManager.user.controller.MobileUserController.autoLoginByRandomKey(MobileUserController.java:109) at com.hikvision.modules.memberManager.user.controller.MobileUserController$$FastClassBySpringCGLIB$$6aef2b03.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:97) at com.hikvision.modules.log.aop.SystemLogAspect.doAround(SystemLogAspect.java:96) at sun.reflect.GeneratedMethodAccessor156.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:621) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) 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:655) at com.hikvision.modules.memberManager.user.controller.MobileUserController$$EnhancerBySpringCGLIB$$f4f4b361.autoLoginByRandomKey() at sun.reflect.GeneratedMethodAccessor1505.invoke(Unknown Source) 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:222) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 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: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:121) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.hikvision.filter.SessionFilter.doFilter(SessionFilter.java:101) 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:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) 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: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry '0' for key 'PRIMARY' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) 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: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry '0' for key 'PRIMARY' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
@wenchongyang 请问一下,你这面后面是怎么避免这个问题? 麻烦分享一下
@linkerlin @zhuam @magicdoom @kingzone 麻烦给予解决 现在不少人都出现同样的问题
修订源码ServerConnection
public void setTxInterrupted(boolean txInterrupted) {
this.txInterrupted = txInterrupted;
}
修订SingleNodeHandler.backConnectionErr 方法 在返回客户端信息后回收TxInterrupted errPkg.write(source); recycleResources(); source.setTxInterrupted(false);
Caused by: java.sql.SQLException: closed connection:sql timeout con:MySQLConnection [id=16, lastTime=1521712259600, user=root, schema=tznw8, old shema=tznw8, borrowed=true, fromSlaveDB=false, threadId=18, charset=utf8, txIsolation=3, autocommit=false, attachment=dn8{INSERT INTO create_code_bag( id, code, quantity, single_no, box_no, tray_no, directory, file_name, traceability_url, product_id, product_name, spec, pro_spec, shelf_life, batch_code, pack_date, active, valid_period, status, factory_code, parent_id, create_date, update_date ) VALUES ( 'd128a72c88ad470bbe5f4ba6b2e3ff75', null, 1000000, '1000000', '', '', '/app_home/codeFiles/2018-03/2018-03-22/', '测试产品-100g每盒-1000000-二维码包-20180322-001.zip', 'http://tznw.sierac315.com/?code=', '40a8c3d19ed246219d66bdd246a3eda4', '测试产品', null, '000', 24, null, null, '0', null, '0', null, '1d15151a0d09472a89c9d305275f3285', '2018-03-22 17:50:58.297', '2018-03-22 17:50:58.297' )}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@25bed20f, host=172.19.238.127, port=3307, statusSync=null, writeQueue=0, modifiedSQLExecuted=true] 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:2487) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3051) at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049) at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:498) at sun.reflect.GeneratedMethodAccessor174.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy256.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185) at sun.reflect.GeneratedMethodAccessor229.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ... 84 common frames omitted
------------怎么整
你需要执行rollback啊
2018-03-22 17:59 GMT+08:00 zhengm notifications@github.com:
Caused by: java.sql.SQLException: closed connection:sql timeout con:MySQLConnection [id=16, lastTime=1521712259600, user=root, schema=tznw8, old shema=tznw8, borrowed=true, fromSlaveDB=false, threadId=18, charset=utf8, txIsolation=3, autocommit=false, attachment=dn8{INSERT INTO create_code_bag( id, code, quantity, single_no, box_no, tray_no, directory, file_name, traceability_url, product_id, product_name, spec, pro_spec, shelf_life, batch_code, pack_date, active, valid_period, status, factory_code, parent_id, create_date, update_date ) VALUES ( 'd128a72c88ad470bbe5f4ba6b2e3ff75', null, 1000000, '1000000', '', '', '/app_home/codeFiles/2018-03/2018-03-22/', '测试产品-100g每盒-1000000-二维码包-20180322-001.zip', 'http://tznw.sierac315.com/?code=', '40a8c3d19ed246219d66bdd246a3eda4', '测试产品', null, '000', 24, null, null, '0', null, '0', null, '1d15151a0d09472a89c9d305275f3285', '2018-03-22 17:50:58.297', '2018-03-22 17:50:58.297' )}, respHandler=io.mycat.backend.mysql.nio.handler. MultiNodeQueryHandler@25bed20f, host=172.19.238.127, port=3307, statusSync=null, writeQueue=0, modifiedSQLExecuted=true] 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:2487) at com.mysql.jdbc.PreparedStatement.executeInternal( PreparedStatement.java:1858) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute( FilterChainImpl.java:3051) at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute( FilterEventAdapter.java:440) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute( FilterChainImpl.java:3049) at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute( PreparedStatementProxyImpl.java:167) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute( DruidPooledPreparedStatement.java:498) at sun.reflect.GeneratedMethodAccessor174.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke( PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy256.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update( PreparedStatementHandler.java:46) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update( RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate( SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update( CachingExecutor.java:76) at org.apache.ibatis.session.defaults.DefaultSqlSession. update(DefaultSqlSession.java:198) at org.apache.ibatis.session.defaults.DefaultSqlSession. insert(DefaultSqlSession.java:185) at sun.reflect.GeneratedMethodAccessor229.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke( SqlSessionTemplate.java:433) ... 84 common frames omitted
------------怎么整
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MyCATApache/Mycat-Server/issues/1741#issuecomment-375240884, or mute the thread https://github.com/notifications/unsubscribe-auth/AAcmsdK6g5jiIcBqE5oclSlxBXSPONiFks5tg3X3gaJpZM4RO0UD .
@magicdoom 如果代码遗漏rollback 就会出问题,而且这个链接会一直堵死在这条语句。即是下一条语句是一条select 语句。参见我的示例,
项目中用了这个,心痛。
想问下这个问题后面有解决么?我也被这个问题坑得好惨,求大神解决
同样问题的2020沙发在此 T^T 望大佬可以给下解决方案~
生产遇到同样问题。。有排期解决吗
场景描述:
1、客户端mybatis代码模拟实现一个事务异常(唯一键重复) 2、客户端mybatis代码再起一个只查询的语句无事务。此时异常 java.lang.RuntimeException: org.springframework.jdbc.UncategorizedSQLException: Error querying database. Cause: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile' The error may exist in URL [jar:file:/app/xxx-soa-impl/member-service-impl-20171115-RELEASE.jar!/BOOT-INF/classes!/mappers/UserMapper.xml] The error may involve com.xxx.soa.impl.member.dao.UserMapper.findUserByMobile-Inline The error occurred while setting parameters SQL: SELECT id, UUID, username, password, mobile, gender, brithday, realName, id_card_number, id_card_start, id_card_end, province, city, area, area_id, area_gbcode, street_id, street, street_gbcode, address, phone, email, status, identity_auth, identity_auth_date, wechat, open_id, qq, alipay, remark, source, growth, point, is_lock, is_enabled, account_expire, password_expire, version FROM user WHERE mobile = ? AND is_deleted = 0 Cause: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile' ; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1003]; Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile'; nested exception is java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile' org.springframework.jdbc.UncategorizedSQLException: Error querying database. Cause: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile' The error may exist in URL [jar:file:/app/xx-soa-impl/member-service-impl-20171115-RELEASE.jar!/BOOT-INF/classes!/mappers/UserMapper.xml] The error may involve com.xx.soa.impl.member.dao.UserMapper.findUserByMobile-Inline The error occurred while setting parameters SQL: SELECT id, UUID, username, password, mobile, gender, brithday, realName, id_card_number, id_card_start, id_card_end, province, city, area, area_id, area_gbcode, street_id, street, street_gbcode, address, phone, email, status, identity_auth, identity_auth_date, wechat, open_id, qq, alipay, remark, source, growth, point, is_lock, is_enabled, account_expire, password_expire, version FROM user WHERE mobile = ? AND is_deleted = 0 Cause: java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile' ; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1003]; Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile'; nested exception is java.sql.SQLException: Transaction error, need to rollback. errno:1062 Duplicate entry 'xxxxxxxxxxx' for key 'uidx_mobile' at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) 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:75) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447) at com.sun.proxy.$Proxy59.selectOne(Unknown Source)
原因分析:
SingleNodeHandler 接收到backConnectionErr之后 设置了 source.setTxInterrupt(errmgs); txInterrupted只有在ServerConnection.rollback的时候才会去重置。 之后这个ServerConnection execute普通SQL的时候检查如下代码: // 事务状态检查 if (txInterrupted) { writeErrMessage(ErrorCode.ER_YES, "Transaction error, need to rollback." + txInterrputMsg); return; } 就出现上面的异常代码了。