You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "WXingSong (via GitHub)" <gi...@apache.org> on 2025/12/06 02:32:45 UTC
[I] I have a question about transaction [shardingsphere]
WXingSong opened a new issue, #37283:
URL: https://github.com/apache/shardingsphere/issues/37283
I am using sharding jdbc version 5.5.1+Seata2.2.0.
When Sharding-JDBC is integrated with Seata, all `@Transactional` annotations end up being taken over by Seata and behave the same as `@GlobalTransactional`. However, in real business scenarios, only cross-service operations require global transactions, while simple operations within a single service do not involve cross-database or sharding queries and only need local transactions.
How can we achieve different levels of transaction handling in such scenarios so that local transactions inside a single service are not taken over by Seata?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] I have a question about transaction [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #37283:
URL: https://github.com/apache/shardingsphere/issues/37283#issuecomment-3641610755
> @linghengqian
- Um, to be honest, I don't see what this has to do with me.
- The existing documentation is based on my existing unit tests and a rather unusual set of external integration tests. Some of those external integration unit tests are from my Yuque article, while the other part was written by another Seata committer in the integration tests for `baomidou/mybatis-plus`. Since issue https://github.com/apache/incubator-seata/issues/6614 remains unresolved, moving those integration tests into the ShardingSphere master branch would be extremely complex. In short, you can make a presupposition that the document has room for improvement.
> Based on our business scenario, global transactions are only needed for cross-service calls, while simple operations within a single service should use local transactions.
- I tend to adopt the viewpoint proposed by the Seata committer: for Seata, a single data source either contains only distributed transactions or only non-distributed transactions. ShardingSphere's existing Seata integration tests are created from this perspective. In other words, this can be broken down into a single database instance and multiple database connections, also known as a multi-data source problem. Since you're using the `@org.springframework.transaction.annotation.Transactional` under Spring Framework, why not try configuring Spring beans with multiple ShardingSphere data sources? I recall discussing this in a previous issue; see https://github.com/apache/shardingsphere/issues/35892#issuecomment-3037940418 .
- Regarding whether ShardingSphere JDBC has an annotation similar to the `com.baomidou.dynamic.datasource.annotation.DS` class from the `baomidou` community for switching the data source used to create transactions, I would say there isn't one yet. After all, even Seata doesn't provide this functionality, so how could ShardingSphere bypass the operation of creating multiple data source connections simultaneously to handle this issue?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] I have a question about transaction [shardingsphere]
Posted by "WXingSong (via GitHub)" <gi...@apache.org>.
WXingSong closed issue #37283: I have a question about transaction
URL: https://github.com/apache/shardingsphere/issues/37283
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] I have a question about transaction [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37283:
URL: https://github.com/apache/shardingsphere/issues/37283#issuecomment-3620503358
I'm not familiar with Seata.
Can you please inquire with the Seata community on my behalf, or could you introduce the purpose of certain Seata configurations you have enabled?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] I have a question about transaction [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37283:
URL: https://github.com/apache/shardingsphere/issues/37283#issuecomment-3619398659
• Understanding
- On ShardingSphere-JDBC 5.5.1 with Seata 2.2.0, all @Transactional calls are behaving like Seata global transactions. You want only cross-service/cross-database operations to use a global transaction, and simple single-service operations to
stay local. You also ask whether a single service that updates multiple databases can rely on local transactions for rollback.
Root Cause (based on given info)
- ShardingSphere’s default transaction type is LOCAL; only when you explicitly switch to BASE (Seata AT) or XA does it become a distributed transaction (see official docs: https://shardingsphere.apache.org/document/current/en/user-manual/
shardingsphere-jdbc/special-api/transaction/ (https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/special-api/transaction/)).
- All @Transactional being treated as global usually means your data sources are proxied by Seata (auto data source proxy), or ShardingSphere’s default transaction type is set to BASE/XA. The exact cause needs your current configuration to
confirm.
Analysis
- Local transactions only guarantee atomicity within a single data source; even within one service, cross-database updates need a distributed transaction (Seata BASE/XA) to ensure consistency.
- To keep most calls local: keep ShardingSphere’s default transaction type as LOCAL; avoid Seata auto-proxying every data source (or only proxy the ones that need global transactions); and annotate only the operations that truly need global
consistency with @GlobalTransactional, switching the transaction type to BASE before those calls (per the doc above).
- If everything is still taken over, we need to inspect which transaction manager Spring is picking and how the data sources are proxied.
Conclusion
- This looks like a configuration/usage issue (global proxying or default transaction type), not a ShardingSphere bug.
- Suggested next steps: ensure default transaction type remains LOCAL, limit Seata data source proxying to the paths that need global transactions, and explicitly opt into BASE/XA only where strong consistency is required.
- To pinpoint further, please share: Seata settings (whether auto data source proxy is enabled), the active Spring transaction manager, and your ShardingSphere transaction type configuration.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] I have a question about transaction [shardingsphere]
Posted by "WXingSong (via GitHub)" <gi...@apache.org>.
WXingSong commented on issue #37283:
URL: https://github.com/apache/shardingsphere/issues/37283#issuecomment-3619601545
> • Understanding
>
> * On ShardingSphere-JDBC 5.5.1 with Seata 2.2.0, all [@transactional](https://github.com/transactional) calls are behaving like Seata global transactions. You want only cross-service/cross-database operations to use a global transaction, and simple single-service operations to
> stay local. You also ask whether a single service that updates multiple databases can rely on local transactions for rollback.
>
> Root Cause (based on given info)
>
> * ShardingSphere’s default transaction type is LOCAL; only when you explicitly switch to BASE (Seata AT) or XA does it become a distributed transaction (see official docs: https://shardingsphere.apache.org/document/current/en/user-manual/
> shardingsphere-jdbc/special-api/transaction/ (https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/special-api/transaction/)).
> * All [@transactional](https://github.com/transactional) being treated as global usually means your data sources are proxied by Seata (auto data source proxy), or ShardingSphere’s default transaction type is set to BASE/XA. The exact cause needs your current configuration to
> confirm.
>
> Analysis
>
> * Local transactions only guarantee atomicity within a single data source; even within one service, cross-database updates need a distributed transaction (Seata BASE/XA) to ensure consistency.
> * To keep most calls local: keep ShardingSphere’s default transaction type as LOCAL; avoid Seata auto-proxying every data source (or only proxy the ones that need global transactions); and annotate only the operations that truly need global
> consistency with @GlobalTransactional, switching the transaction type to BASE before those calls (per the doc above).
> * If everything is still taken over, we need to inspect which transaction manager Spring is picking and how the data sources are proxied.
>
> Conclusion
>
> * This looks like a configuration/usage issue (global proxying or default transaction type), not a ShardingSphere bug.
> * Suggested next steps: ensure default transaction type remains LOCAL, limit Seata data source proxying to the paths that need global transactions, and explicitly opt into BASE/XA only where strong consistency is required.
> * To pinpoint further, please share: Seata settings (whether auto data source proxy is enabled), the active Spring transaction manager, and your ShardingSphere transaction type configuration.
My Sharding-JDBC related configuration
```
transaction:
defaultType: BASE
providerType: Seata
```
Seata related configuration
```
seata:
enable-auto-data-source-proxy: false
```
Do you mean that I should change the configuration to LOCAL and remove Seata’s enable-auto-data-source-proxy: false setting, and then use Seata’s @GlobalTransactional only when I need global transactions across services, right?
```
transaction:
defaultType: LOCAL
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] I have a question about transaction [shardingsphere]
Posted by "WXingSong (via GitHub)" <gi...@apache.org>.
WXingSong commented on issue #37283:
URL: https://github.com/apache/shardingsphere/issues/37283#issuecomment-3624368587
> I'm not familiar with Seata. Can you please inquire with the Seata community on my behalf, or could you introduce the purpose of certain Seata configurations you have enabled?
I configured everything strictly according to this document:
https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/special-api/transaction/seata/
The document states:
```
transaction:
defaultType: BASE
providerType: Seata
```
```
seata:
enable-auto-data-source-proxy: false
```
I have already tried changing the transaction configuration in Sharding to LOCAL and used Seata’s proxy.
```
transaction:
defaultType: LOCAL
```
```
seata:
enable-auto-data-source-proxy: false
```
However, it didn’t work. An error occurred and the transaction was rolled back.
Based on our business scenario, global transactions are only needed for cross-service calls, while simple operations within a single service should use local transactions. Does Sharding provide any solution for this? I will also raise this issue in the Seata community.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org