Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

The integration with Seata doesn't work #31715

Closed
Famezyy opened this issue Jun 16, 2024 · 9 comments
Closed

The integration with Seata doesn't work #31715

Famezyy opened this issue Jun 16, 2024 · 9 comments

Comments

@Famezyy
Copy link

Famezyy commented Jun 16, 2024

I'm using version 5.5.0, but when incorporating seata it is not working as expected.
I first created two services: consumer and provider, and the provider service is been called in consumer service.
Then checked the official documentation and disabled the auto data proxy of seata. Also refered to #22356 and #30146 and added the following interceptor in the provider service:

@Configuration
public class MySeataConfigure implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ShardingSphereInterceptor());
    }

    static class ShardingSphereInterceptor implements HandlerInterceptor {
        public boolean preHandle(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler) throws TransactionException {
            String xid = RootContext.getXID();
            if (xid == null) {
                xid = request.getHeader(RootContext.KEY_XID);
            }
            if (!StringUtils.isBlank(xid) && SeataTransactionHolder.get() == null) {
                RootContext.bind(xid);
                SeataTransactionHolder.set(GlobalTransactionContext.getCurrentOrCreate());
            }
            return true;
        }
    }
}

but when error occured in consumer service after calling provider service, rollback only happened in consumer service.

consumer service log

2024-06-16T15:41:02.472+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.c.rpc.netty.TmNettyRemotingClient    : register TM success. client version:2.0.0, server version:2.0.0,channel:[id: 0xe2b99d58, L:/127.0.0.1:2059 - R:/127.0.0.1:18091]
2024-06-16T15:41:02.480+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.core.rpc.netty.NettyPoolableFactory  : register success, cost 81 ms, version:2.0.0,role:TMROLE,channel:[id: 0xe2b99d58, L:/127.0.0.1:2059 - R:/127.0.0.1:18091]
2024-06-16T15:41:02.498+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] io.seata.rm.datasource.AsyncWorker       : Async Commit Buffer Limit: 10000
2024-06-16T15:41:02.499+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.rm.datasource.xa.ResourceManagerXA   : ResourceManagerXA init ...
2024-06-16T15:41:02.508+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.core.rpc.netty.NettyClientBootstrap  : NettyClientBootstrap has started
2024-06-16T15:41:02.618+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.c.r.netty.NettyClientChannelManager  : will connect to 127.0.0.1:18091
2024-06-16T15:41:02.619+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.c.rpc.netty.RmNettyRemotingClient    : RM will register :jdbc:mysql://localhost:3306/seata
2024-06-16T15:41:02.619+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.core.rpc.netty.NettyPoolableFactory  : NettyPool create channel to transactionRole:RMROLE,address:127.0.0.1:18091,msg:< RegisterRMRequest{resourceIds='jdbc:mysql://localhost:3306/seata', version='2.0.0', applicationId='seata-consumer', transactionServiceGroup='default_tx_group', extraData='null'} >
2024-06-16T15:41:02.627+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.c.rpc.netty.RmNettyRemotingClient    : register RM success. client version:2.0.0, server version:2.0.0,channel:[id: 0x2c919b71, L:/127.0.0.1:2060 - R:/127.0.0.1:18091]
2024-06-16T15:41:02.627+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.s.core.rpc.netty.NettyPoolableFactory  : register success, cost 5 ms, version:2.0.0,role:RMROLE,channel:[id: 0x2c919b71, L:/127.0.0.1:2060 - R:/127.0.0.1:18091]
2024-06-16T15:41:07.253+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (getNetworkTimeout)
2024-06-16T15:41:07.255+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection@68fbdbee
2024-06-16T15:41:07.256+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-06-16T15:41:07.270+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] io.seata.tm.TransactionManagerHolder     : TransactionManager Singleton io.seata.tm.DefaultTransactionManager@674367bf
2024-06-16T15:41:07.277+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.seata.tm.api.DefaultGlobalTransaction  : Begin new global transaction [192.168.13.1:18091:3477311730122375224]
2024-06-16T15:41:08.348+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] ShardingSphere-SQL                       : Logic SQL: UPDATE account  SET money=money+200       WHERE  (id = ?)
2024-06-16T15:41:08.348+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] ShardingSphere-SQL                       : Actual SQL: db ::: UPDATE account  SET money=money+200       WHERE  (id = ?) ::: [1]
2024-06-16T15:41:08.813+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] io.seata.rm.AbstractResourceManager      : branch register success, xid:192.168.13.1:18091:3477311730122375224, branchId:3477311730122375225, lockKeys:account:1
2024-06-16T15:41:08.833+09:00  WARN 20652 --- [seata-consumer] [nio-8080-exec-1] ServiceLoader$InnerEnhancedServiceLoader : Load [io.seata.rm.datasource.undo.parser.ProtostuffUndoLogParser] class fail: io/protostuff/runtime/IdStrategy
2024-06-16T15:41:18.951+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.seata.tm.api.DefaultGlobalTransaction  : transaction 192.168.13.1:18091:3477311730122375224 will be rollback
2024-06-16T15:41:18.957+09:00  INFO 20652 --- [seata-consumer] [h_RMROLE_1_1_24] i.s.c.r.p.c.RmBranchRollbackProcessor    : rm handle branch rollback process:BranchRollbackRequest{xid='192.168.13.1:18091:3477311730122375224', branchId=3477311730122375225, branchType=AT, resourceId='jdbc:mysql://localhost:3306/seata', applicationData='null'}
2024-06-16T15:41:18.959+09:00  INFO 20652 --- [seata-consumer] [h_RMROLE_1_1_24] io.seata.rm.AbstractRMHandler            : Branch Rollbacking: 192.168.13.1:18091:3477311730122375224 3477311730122375225 jdbc:mysql://localhost:3306/seata
2024-06-16T15:41:19.061+09:00  INFO 20652 --- [seata-consumer] [h_RMROLE_1_1_24] i.s.r.d.undo.AbstractUndoLogManager      : xid 192.168.13.1:18091:3477311730122375224 branch 3477311730122375225, undo_log deleted with GlobalFinished
2024-06-16T15:41:19.063+09:00  INFO 20652 --- [seata-consumer] [h_RMROLE_1_1_24] i.seata.rm.datasource.DataSourceManager  : branch rollback success, xid:192.168.13.1:18091:3477311730122375224, branchId:3477311730122375225
2024-06-16T15:41:19.064+09:00  INFO 20652 --- [seata-consumer] [h_RMROLE_1_1_24] io.seata.rm.AbstractRMHandler            : Branch Rollbacked result: PhaseTwo_Rollbacked
2024-06-16T15:41:19.069+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.seata.tm.api.DefaultGlobalTransaction  : transaction end, xid = 192.168.13.1:18091:3477311730122375224
2024-06-16T15:41:19.069+09:00  INFO 20652 --- [seata-consumer] [nio-8080-exec-1] i.seata.tm.api.DefaultGlobalTransaction  : [192.168.13.1:18091:3477311730122375224] rollback status: Rollbacked
2024-06-16T15:41:19.075+09:00 ERROR 20652 --- [seata-consumer] [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.ArithmeticException: / by zero] with root cause

provider service log

2024-06-16T15:26:08.571+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.c.rpc.netty.TmNettyRemotingClient    : register TM success. client version:2.0.0, server version:2.0.0,channel:[id: 0xdc135f0a, L:/127.0.0.1:13771 - R:/127.0.0.1:18091]
2024-06-16T15:26:08.578+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.core.rpc.netty.NettyPoolableFactory  : register success, cost 74 ms, version:2.0.0,role:TMROLE,channel:[id: 0xdc135f0a, L:/127.0.0.1:13771 - R:/127.0.0.1:18091]
2024-06-16T15:26:08.596+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] io.seata.rm.datasource.AsyncWorker       : Async Commit Buffer Limit: 10000
2024-06-16T15:26:08.597+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.rm.datasource.xa.ResourceManagerXA   : ResourceManagerXA init ...
2024-06-16T15:26:08.605+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.core.rpc.netty.NettyClientBootstrap  : NettyClientBootstrap has started
2024-06-16T15:26:08.705+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.c.r.netty.NettyClientChannelManager  : will connect to 127.0.0.1:18091
2024-06-16T15:26:08.706+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.c.rpc.netty.RmNettyRemotingClient    : RM will register :jdbc:mysql://localhost:3307/seata
2024-06-16T15:26:08.706+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.core.rpc.netty.NettyPoolableFactory  : NettyPool create channel to transactionRole:RMROLE,address:127.0.0.1:18091,msg:< RegisterRMRequest{resourceIds='jdbc:mysql://localhost:3307/seata', version='2.0.0', applicationId='seata-provider', transactionServiceGroup='default_tx_group', extraData='null'} >
2024-06-16T15:26:08.713+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.c.rpc.netty.RmNettyRemotingClient    : register RM success. client version:2.0.0, server version:2.0.0,channel:[id: 0xb9c2ceb6, L:/127.0.0.1:13772 - R:/127.0.0.1:18091]
2024-06-16T15:26:08.713+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] i.s.core.rpc.netty.NettyPoolableFactory  : register success, cost 5 ms, version:2.0.0,role:RMROLE,channel:[id: 0xb9c2ceb6, L:/127.0.0.1:13772 - R:/127.0.0.1:18091]
2024-06-16T15:26:13.232+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (getNetworkTimeout)
2024-06-16T15:26:13.234+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection@3656315
2024-06-16T15:26:13.235+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-06-16T15:26:14.296+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] ShardingSphere-SQL                       : Logic SQL: UPDATE account  SET money=money+200       WHERE  (id = ?)
2024-06-16T15:26:14.296+09:00  INFO 10320 --- [seata-provider] [nio-8081-exec-1] ShardingSphere-SQL                       : Actual SQL: db ::: UPDATE account  SET money=money+200       WHERE  (id = ?) ::: [2]

You can see there was no rollback happened in provider service.
I"m not sure if it is correct but in provider service it was also registering TM and RM, and there was no any branch transaction been registered.

When debugging it, I found that in provider service, it is entering the commit() method of DefaultGlobalTransaction from SeataATShardingSphereTransactionManager, and as the transaction role is Participant, it is doing nothing but just print out log says ignore commit:
image

But actually it should not come to here, I'm expecting it can register a branch transaction and commit it but not try to commit the global transaction directly.
you can find the example code in the below repo.

https://github.com/Famezyy/code-repo/tree/master

could you please tell me how to fix it?

@WXingSong
Copy link

@strongduanmu @TherChenYang I also have the same problem, which has been resolved for two or three days but still hasn't been resolved.Help!~

@TherChenYang
Copy link
Collaborator

TherChenYang commented Jun 17, 2024

@WXingSong ok, the same problem occurred at #31667, I will check it

@WXingSong
Copy link

WXingSong commented Jun 18, 2024

@WXingSong ok, the same problem occurred at #31667, I will check it

@TherChenYang T What is the current stable version for SpringCloudAlibaba 2022.0.0? The corresponding version of Seata is Seata 1.7, but there is an issue when integrating 1.7. According to #30146, Seata needs to use 2.0. Does the lower version of Shading jdbc support it? I hope to reduce the version usage before this issue is resolved.

@TherChenYang
Copy link
Collaborator

@linghengqian Can you help with this issue? I see that several Seata-related issues have been fixed in #30146.

@WXingSong
Copy link

@Famezyy I also have the same problem, have you solved it? I found that when feign remotely calls the interface, the called interface autoCommit is true, which prevents Sharding from executing the execute method of Seata's PreparedStatementProxy, resulting in undo_log not generating relevant records. So even if you execute GlobalTransactionContext. reload (Rootcontext. getXID()). rollback(), it cannot be rolled back. @linghengqian

@Famezyy
Copy link
Author

Famezyy commented Jun 20, 2024

@Famezyy I also have the same problem, have you solved it? I found that when feign remotely calls the interface, the called interface autoCommit is true, which prevents Sharding from executing the execute method of Seata's PreparedStatementProxy, resulting in undo_log not generating relevant records. So even if you execute GlobalTransactionContext. reload (Rootcontext. getXID()). rollback(), it cannot be rolled back. @linghengqian

no I'm not able to resolve it, hope they can provide a solution :)

@linghengqian
Copy link
Member

  • I haven't had time to check the git attached to this issue yet, and my computer has been flying off a cliff in the last few days (just a metaphor). Let me see what happens later.

@linghengqian
Copy link
Member

@TherChenYang T What is the current stable version for SpringCloudAlibaba 2022.0.0? The corresponding version of Seata is Seata 1.7, but there is an issue when integrating 1.7. According to #30146, Seata needs to use 2.0. Does the lower version of Shading jdbc support it? I hope to reduce the version usage before this issue is resolved.

  • @WXingSong Indeed, the current ShardingSphere JDBC Native Image product includes integration tests with seataio/seata-server:1.8.0, and I've personally tested ShardingSphere against both seataio/seata-server:1.8.0 and seataio/seata-server:2.0.0 on a HotSpot JVM locally. These unit tests do not involve a multi-microservice scenario, being executed solely within a single Spring Boot microservice. This is inherently limited by the fact that Seata Client is designed to be a globally unique instance, see Seata Multi-Client Optimization incubator-seata#6614 for reference. Currently only integration tests for seataio/seata-server:1.7.0 are missing, feel free to test seataio/seata-server:1.7.0.

@Famezyy I also have the same problem, have you solved it? I found that when feign remotely calls the interface, the called interface autoCommit is true, which prevents Sharding from executing the execute method of Seata's PreparedStatementProxy, resulting in undo_log not generating relevant records. So even if you execute GlobalTransactionContext. reload (Rootcontext. getXID()). rollback(), it cannot be rolled back. @linghengqian

  • @WXingSong Can you provide the unit tests in a separate issue? It sounds like the error stack is missing.

But actually it should not come to here, I'm expecting it can register a branch transaction and commit it but not try to commit the global transaction directly.
you can find the example code in the below repo.
https://github.com/Famezyy/code-repo/tree/master
could you please tell me how to fix it?

  • @Famezyy I actually just got myself out of a WSL sub-distro curse that Canonical put on me a while ago, refer to After Ubuntu 24.04 upgrade, GUI apps are extremely slow to open microsoft/wslg#1250 . But considering I don't see your unit tests, it's hard for me to say I understand what's going on inside git.
  • Since you appear to have intentionally omitted the unit tests, I gather that to reproduce your logs, at least the following steps would be required?
  1. Build the JAR for com.youyi:seata-provider-shardingsphere-sb:0.0.1-SNAPSHOT. It just seems overly cumbersome if I need to build a Docker Image for the com.youyi:seata-provider-shardingsphere-sb:0.0.1-SNAPSHOT module, as you haven't provided a Dockerfile.
  2. Within com.youyi:seata-consumer-shardingsphere-sb, utilize org.testcontainers:mysql:1.19.8 to spin up two Docker container instances of MySQL for unit testing, with the internal port 3306 of each container exposed to host ports 3306 and 3307 respectively.
  3. After the MySQL health checks complete, leverage testcontainers-java's Java API to instantiate a Docker container of the seataio/seata-server:2.0.0, awaiting its health check completion.
  4. Following the Seata Server's readiness, within the same unit test context, employ org.springframework.experimental.boot:spring-boot-testjars:0.0.1 to run the JAR of com.youyi:seata-provider-shardingsphere-sb:0.0.1-SNAPSHOT as a Spring bean for com.youyi:seata-consumer-shardingsphere-sb.
  5. Invoke the /provide HTTP endpoint in com.youyi:seata-consumer-shardingsphere-sb involving @LocalServerPort.
  • I assume you have not actually authored a README for this git repository.

@Famezyy
Copy link
Author

Famezyy commented Jul 1, 2024

@linghengqian Thank you for your time, I have added a junit test with a description, you can simply run ConsumerControllerTests::testConsumerController after building the JAR file for com.youyi:seata-provider-shardingsphere-sb:0.0.1-SNAPSHOT. You can find it in the below repo:
https://github.com/Famezyy/code-repo
Please kindly help check the issue.

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants