Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seata SAGA模式提示:seata_state_machine_inst.PRIMARY #6489

Open
1 task
7colorlotus opened this issue Apr 22, 2024 · 5 comments
Open
1 task

Seata SAGA模式提示:seata_state_machine_inst.PRIMARY #6489

7colorlotus opened this issue Apr 22, 2024 · 5 comments

Comments

@7colorlotus
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

使用Seata时,SAGA模式。一个接口比如创建订单,前一个创建订单请求,由于特殊场景(比如在扣库存请求失败时库存服务重启,或者处理事务时服务重启)导致事务处理失败。后面的创建订单请求,无法正常进行事务处理,会提示状态机实例表(seata_state_machine_inst)主键冲突。理论上,一个新的请求,应该有一个全新的全局事务id(xid),为何会出现此问题?

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

Record statemachine start error: [10000] [Unknown error] [Internal error], StateMachine: CreateOrder, XID: 172.23.0.244:8091:524592202459856896, Reason: Duplicate entry '172.23.0.244:8091:524592202459856896' for key 'seata_state_machine_inst.PRIMARY'

Ⅲ. Describe what you expected to happen

提示上面的错误,是使用seata时,使用了相同的全局事务id。导致了插入数据库表:seata_state_machine_inst,提示主键冲突。期望应该不会出现生成重复的全局事务id,能正常进行分布式事务处理。

Ⅳ. How to reproduce it (as minimally and precisely as possible)

Minimal yet complete reproducer code (or URL to code):

Ⅴ. Anything else we need to know?

希望可以解释一下出现这种问题的原因,在不升级seata版本的前提下,能够修复或者避免出现此类情况。

Ⅵ. Environment:

  • JDK version(e.g. java -version): 1.8
  • Seata client/server version: 1.4.1
  • Database version: mysql 8.0.25
  • OS(e.g. uname -a): Linux 4.19.91-26.al7.x86_64
  • Others:
@funky-eyes
Copy link
Contributor

方便提供下异常堆栈吗?
Is it convenient to provide the exception stack?

@7colorlotus
Copy link
Author

image 数据库里有了相同id的全局事务记录了,是上一个事务执行失败的记录。目前状态是RU状态。

因为配置了重试30分钟如果不成功就失败,所以也没有在重试了

@7colorlotus
Copy link
Author

方便提供下异常堆栈吗? Is it convenient to provide the exception stack?

是这个对吗?

io.seata.common.exception.StoreException: Duplicate entry '172.23.0.244:8091:524592202459856896' for key 'seata_state_machine_inst.PRIMARY'
at io.seata.saga.engine.store.db.AbstractStore.executeUpdate(AbstractStore.java:150)
at io.seata.saga.engine.store.db.DbAndReportTcStateLogStore.recordStateMachineStarted(DbAndReportTcStateLogStore.java:111)
at io.seata.saga.engine.impl.ProcessCtrlStateMachineEngine.startInternal(ProcessCtrlStateMachineEngine.java:136)
at io.seata.saga.engine.impl.ProcessCtrlStateMachineEngine.startWithBusinessKey(ProcessCtrlStateMachineEngine.java:88)
at com.gtech.trade.component.OrderTransactionComponent.createOrderTransactional(OrderTransactionComponent.java:173)
at com.gtech.trade.component.OrderTransactionComponent$$FastClassBySpringCGLIB$$7db2bf34.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
at com.gtech.trade.component.OrderTransactionComponent$$EnhancerBySpringCGLIB$$2b47a2be.createOrderTransactional()
at com.gtech.trade.component.OrderComponent.createOrder(OrderComponent.java:170)
at com.gtech.trade.controller.OrderController.splitOrder(OrderController.java:122)
at com.gtech.trade.controller.OrderController.createOrder(OrderController.java:75)
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:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:769)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1787)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '172.23.0.244:8091:524592202459856896' for key 'seata_state_machine_inst.PRIMARY'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1320)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeUpdate(DruidPooledPreparedStatement.java:255)
at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.MasterSlavePreparedStatement.executeUpdate(MasterSlavePreparedStatement.java:128)
at io.seata.saga.engine.store.db.AbstractStore.executeUpdate(AbstractStore.java:144)

@wt-better
Copy link
Contributor

wt-better commented Apr 24, 2024

Are you set DbStateMachineConfig#seqGenerator gen seq by bussinessId? If seqGeneraor is set, it needs to be unique even if it is the same businessId.

@7colorlotus
Copy link
Author

7colorlotus commented Apr 25, 2024

Are you set DbStateMachineConfig#seqGenerator gen seq by bussinessId? If seqGeneraor is set, it needs to be unique even if it is the same businessId.

NO,I have not set DbStateMachineConfig#seqGenerator, and debug find the DbStateMachineConfig#seqGenerator value is null after I set。

image

And StateMachineEngine object show the DbStateMachineConfig#seqGenerator value like this:
image
This should be default value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants