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

XA事务模式下写入的查询不到问题探讨 #6512

Open
1 task
wuchaococo opened this issue Apr 29, 2024 · 9 comments
Open
1 task

XA事务模式下写入的查询不到问题探讨 #6512

wuchaococo opened this issue Apr 29, 2024 · 9 comments

Comments

@wuchaococo
Copy link

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

Ⅰ. Issue Description

#6510
Oracle数据库下,使用XA模式,对于写入的数据,再次查询(同一个事务内)回出现查询不到的问题。
基本业务代码如下,一个本地事务:
1 先写入一条数据
2 然后查询,没有查询出来
目前发现写入操作和查询都记录了一下分支事务
日志中client报:phasetwo_commitfailed_XAER_NOTA_Retryable,

不在一个本地事务中时,由于事务的隔离性,另一个connection是不可能查出来的。在读写场景都在一个服务下,没有跨服务时可以加@transactional注解解决

现在的疑问是如果在本地事务中两个数据源,这种场景如何使用XA

Ⅱ. Describe what happened

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

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

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

  1. xxx
  2. xxx
  3. xxx

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

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

  • JDK version(e.g. java -version): 1.8
  • Seata client/server version: 1.8
  • Database version: oracle11g
  • OS(e.g. uname -a):
  • Others:
@funky-eyes
Copy link
Contributor

你多数据源导致无法使用本地事务,这个问题跟seata无关,在于你的多数据源如何使用
Your multiple data sources make it impossible to use local transactions. This problem has nothing to do with seata, but how your multiple data sources are used

@wuchaococo
Copy link
Author

那在多数据源场景下,如何使用SEATA的XA模式

@funky-eyes
Copy link
Contributor

取决你的多数据源如何使用,你自己实现的时候讲多个数据源中需要重入的connection自行缓存后,在相同线程中操作相同数据源时,优先使用缓存的数据源,在最后触发提交也是个办法。
Depending on how your multi-data source is used, when you implement it yourself, you need to cache the connections that need to be reentered in multiple data sources. When operating the same data source in the same thread, you should use the cached data source first, and finally trigger the commit method.

@wuchaococo
Copy link
Author

进程内我可以缓存,但是如果跨服务了,怎么缓存

@funky-eyes
Copy link
Contributor

跨服务本身就不支持,建议你先去了解下xa事务的原理,这个原理不是seata定义的,是X/Open 组织,seata去对接了各个数据库的实现而已。你自己去拿个mysql,弄2个客户端直接连上去起2个事务,你觉得能查到?都不用说分布式事务,基本本地事务,你重复调了一个service,@transactional注解在service里,而不是在business里,也变成了2个事务,前一个不提交不后一个怎么查得到

@funky-eyes
Copy link
Contributor

xa模式就不要考虑多次调用下的资源重入了,如果要做到这块支持是非常困难的,但也不是没有办法。会使调用变成有状态,这个成本和风险也比较高

@wuchaococo
Copy link
Author

基本明确了,如果跨服务以后,就不考虑XA了,如果我想做资源重用,能否给个思路?

@funky-eyes
Copy link
Contributor

资源重入不要用xa模式,除非是在一个服务内没有跨多次调用的,可以用@transactional注解的方式处理。
资源重入场景可以用at模式,这个是在跨服务调用,在同一个全局事务下都是允许重入的

@slievrly
Copy link
Member

Cross-service even AT mode cannot read uncommitted data unless you change the default transaction isolation level.

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