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

bugfix: prevents XA mode resource suspension #4074

Merged
merged 22 commits into from
Oct 22, 2021
Merged

Conversation

funky-eyes
Copy link
Contributor

@funky-eyes funky-eyes commented Oct 13, 2021

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

设计思路:
首先分析一下seata-xa的执行逻辑,首先来看下一阶段
注册分支->xa start->xa end->xa prepare->hold本地xa连接
二阶段:
查找xa本地连接->有则直接xa二阶段,否进行创建一个新的xaconnection
分析二阶段创建新的xaconnection只可能由于原先的rm宕机 或者 已经进行过二阶段处理,但是tc可能宕机或者其它原因,导致需要再次下发
目前做法:
注册分支->hold连接->xa start ->xa end->xa prepare
二阶段:
执行二阶段xa rollback或者commit出现XAER_NOTA异常时,表示找不到该xid,此时有两种情况,1.xid已经被处理过 2.由于这个xid还未end无法rollback 此时出现异常会将二阶段状态存储到rm端
start end prepare均有一个前置的从本地缓存读取该branchid的二阶段结果,如果已经存二阶段结果,均会抛出SQLException异常,使connection走到rollback逻辑,rollback执行结束后便会清空本地缓存
但目前有个问题,就是出现上述情况1的时候,本地会出现一个该branchid的状态,但不会被清除,如果反复出现悬挂或网络等问题造成tc重试下发,会有oom风险,目前想法是用guava做一个缓存,元素封顶为1000,先进先出来淘汰

由于是注册后立即 hold ,所以只有2种接下的可能,1.hold之前收到回滚指令,目前的解法是缓存本地二阶段的值,让其之后的start end prepare走向rollback
2.hold并start之后下发,由于复用了同一个connection,会是XAER_RMFAIL异常,此时tc会重试,只要走到end/prepare,tc都能将其重试回滚,如果走到prepare rm挂了,由于tc会重试,此时其他的rm也会进行回滚成功,如果是在end挂了,直接这个xa事务就关闭了rollback了,此时tc请求给其它的rm时,只会在本地缓存一个二阶段的值,就出现了上面说到的可能出现oom,目前采用了guava缓存,1024个值,并自动过期和设置了上限,应该能有效控制

Ⅱ. Does this pull request fix one issue?

fixes #4073

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2021

Codecov Report

Merging #4074 (2b22180) into develop (9d5ff40) will increase coverage by 0.01%.
The diff coverage is 53.57%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #4074      +/-   ##
=============================================
+ Coverage      49.44%   49.45%   +0.01%     
- Complexity      3750     3759       +9     
=============================================
  Files            700      700              
  Lines          23571    23607      +36     
  Branches        2912     2919       +7     
=============================================
+ Hits           11654    11676      +22     
- Misses         10731    10742      +11     
- Partials        1186     1189       +3     
Impacted Files Coverage Δ
...ta/rm/datasource/xa/AbstractDataSourceProxyXA.java 7.14% <0.00%> (-0.55%) ⬇️
...a/io/seata/rm/datasource/xa/ResourceManagerXA.java 13.88% <0.00%> (-1.27%) ⬇️
...a/io/seata/rm/datasource/xa/ConnectionProxyXA.java 56.45% <63.15%> (+1.45%) ⬆️
.../main/java/io/seata/rm/BaseDataSourceResource.java 31.14% <66.66%> (+4.73%) ⬆️
...torage/file/store/FileTransactionStoreManager.java 57.41% <0.00%> (+0.64%) ⬆️

@funky-eyes funky-eyes mentioned this pull request Oct 13, 2021
1 task
@funky-eyes funky-eyes added this to the 1.5.0 milestone Oct 14, 2021
@funky-eyes funky-eyes added mode: XA XA transaction mode module/rm-datasource rm-datasource module type: bug Category issues or prs related to bug. labels Oct 14, 2021
@funky-eyes funky-eyes merged commit 0c2ae32 into apache:develop Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mode: XA XA transaction mode module/rm-datasource rm-datasource module type: bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XA模式资源悬挂问题
2 participants