问题一:seata回滚不抛出异常,什么原因呢?
seata回滚不抛出异常,什么原因呢?
参考回答:
事务没有回滚 1、先检查异常是否被catch或者有无熔断降级 异常被catch后或熔断降级后,全局事务便不感知抛出的异常。建议catch异常后返回异常码给事务发起方(TM),然后事务发起方 (TM) 。通过API的方式回滚全局事务。 2、否则请自行debug以下方法: ExecuteTemplate#execute(List, StatementProxy, StatementCallback, java.lang.Object...) 如果没进入这个方法,说明数据源被没有代理
问题二:全局异常处理导致seata分布式事务无法回滚问题,有什么解决方案吗?
全局异常处理导致seata分布式事务无法回滚问题,有什么解决方案吗?
参考回答:
你异常处理后,返回的http状态码不要是200就ok了
问题三:什么方法可以在那个链路出现异常的时候,直接请求seata事务控制器直接回滚?
什么方法可以在那个链路出现异常的时候,直接请求seata事务控制器直接回滚?
参考回答:
api可以做到在rm侧发起回滚,但是如果被滥用就会出现问题,比如a调b再调c,调b的时候b异常了,b用api发起回滚,回滚后a没判断b的response结果是否正常,就去调了c,c再去注册分支的时候由于事务回滚了,这个xid就找不到了,如果tm侧不去中断调用链是会出问题的
问题四:接口使用了seata全局事务,提交几十条数据正常执行,但数据量超过两百条会报异常应该如何排查或处理?
有个接口使用了seata全局事务进行更新数据,提交几十条数据的时候正常执行,但数据量超过两百条的时候就会报异常。应该如何排查或处理?
接口所属项目报错日志: 2023-01-30 16:42:04.757 ERROR 1182262 --- [http-nio-65421-exec-4] aihma.cloud.core.base.ro.ApiRo : org.springframework.orm.jpa.JpaSystemException: Unable to commit against JDBC Connection; nested exception is org.hibernate.TransactionException: Unable to commit against JDBC Connection at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:353) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255) at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:538) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:743) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:633) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:386) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxyCglibMethodInvocation.proceed(CglibAopProxy.java:749)atio.seata.spring.annotation.GlobalTransactionalInterceptor.invoke(GlobalTransactionalInterceptor.java:156)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)atorg.springframework.aop.framework.CglibAopProxyCglibMethodInvocation.proceed(CglibAopProxy.java:749)atio.seata.spring.annotation.GlobalTransactionalInterceptor.invoke(GlobalTransactionalInterceptor.java:156)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)atorg.springframework.aop.framework.CglibAopProxyCglibMethodInvocation.proceed(CglibAopProxy.java:749) at io.seata.spring.annotation.GlobalTransactionalInterceptor.invoke(GlobalTransactionalInterceptor.java:156) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxyCglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.framework.CglibAopProxyDynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)ataihma.cloud.mvc.service.aliIot.impl.SceneServiceImplDynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)ataihma.cloud.mvc.service.aliIot.impl.SceneServiceImplDynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) at aihma.cloud.mvc.service.aliIot.impl.SceneServiceImplEnhancerBySpringCGLIB1e408270.editScene()ataihma.cloud.mvc.controller.aliIot.SceneController.edit1e408270.editScene()ataihma.cloud.mvc.controller.aliIot.SceneController.edit1e408270.editScene() at aihma.cloud.mvc.controller.aliIot.SceneController.editoriginaltn61hLv0(SceneController.java:315)ataihma.cloud.mvc.controller.aliIot.SceneController.edittn61hLv0(SceneController.java:315)ataihma.cloud.mvc.controller.aliIot.SceneController.edittn61hLv0(SceneController.java:315) at aihma.cloud.mvc.controller.aliIot.SceneController.editoriginaltn61hLv0tn61hLv0tn61hLv0accessorGjOfNFeB(SceneController.java)ataihma.cloud.mvc.controller.aliIot.SceneControllerGjOfNFeB(SceneController.java)ataihma.cloud.mvc.controller.aliIot.SceneControllerGjOfNFeB(SceneController.java) at aihma.cloud.mvc.controller.aliIot.SceneControllerauxiliary$KFpS4hDy.call(Unknown Source) at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86) at aihma.cloud.mvc.controller.aliIot.SceneController.edit(SceneController.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) .....
Caused by: org.hibernate.TransactionException: Unable to commit against JDBC Connection at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.commit(AbstractLogicalConnectionImplementor.java:87) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:272) at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:104) at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:534) ... 78 more
Caused by: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:172.29.222.218:8091:363364799438757888, lockKeys:iot_scenes_settings:8296716702708613139;iot_scenes_settings:8296716713349562374;过长省略...... at io.seata.rm.datasource.ConnectionProxy.recognizeLockKeyConflictException(ConnectionProxy.java:155) at io.seata.rm.datasource.ConnectionProxy.processGlobalTransactionCommit(ConnectionProxy.java:221) at io.seata.rm.datasource.ConnectionProxy.doCommit(ConnectionProxy.java:199) at io.seata.rm.datasource.ConnectionProxy.lambdacommitcommitcommit0(ConnectionProxy.java:184) at io.seata.rm.datasource.ConnectionProxy$LockRetryPolicy.execute(ConnectionProxy.java:292) at io.seata.rm.datasource.ConnectionProxy.commit(ConnectionProxy.java:183) at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.commit(AbstractLogicalConnectionImplementor.java:81) ... 81 more
参考回答:
其他事务占用了全局锁还没释放
问题五:全局异常处理导致seata分布式事务无法回滚问题,有人用AOP的方法解决过吗,多个服务怎么弄?
全局异常处理导致seata分布式事务无法回滚问题,有人用AOP的方法解决过吗,多个服务怎么弄?
参考回答:
使用AOP手动开启全局事务并进行回滚。
@Aspect @Component @Slf4j public class WorkAspect { @Before("execution(* com.trs.slivlooncloud.service.*.*(..))") public void before(JoinPoint joinPoint) throws TransactionException { MethodSignature signature = (MethodSignature)joinPoint.getSignature(); Method method = signature.getMethod(); GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate(); tx.begin(300000, "tran"); log.info("**********创建分布式事务完毕 {}" , tx.getXid()); } @AfterThrowing(throwing = "e", pointcut = "execution(* com.trs.slivlooncloud.service.*.*(..))") public void doRecoveryActions(Throwable e) throws TransactionException { log.info("方法执行异常:{}", e.getMessage()); if (!StringUtils.isBlank(RootContext.getXID())) { GlobalTransactionContext.reload(RootContext.getXID()).rollback(); } } }
——参考来源于SEATA官方文档。