-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ 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
|
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ⅰ. 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