You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "whaon (via GitHub)" <gi...@apache.org> on 2026/10/20 06:58:15 UTC
[PR] bugfix: use per-branch qualified gtrid in XA mode for DM [incubator-seata]
whaon opened a new pull request, #8312:
URL: https://github.com/apache/incubator-seata/pull/8312
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Please make sure you have read and understood the contributing guidelines -->
- [ ] I have read the [CONTRIBUTING.md](https://github.com/apache/incubator-seata/blob/2.x/CONTRIBUTING.md) guidelines.
- [ ] I have registered the PR [changes](https://github.com/apache/incubator-seata/tree/2.x/changes).
### Ⅰ. Describe what this PR did
DM rejects a new xa start with XAER_RMERR while an in-doubt (prepared) branch of the same gtrid exists on the instance, so two branches of one Seata global transaction cannot hit the same DM instance in XA mode.
For dbType=dm, qualify the XA gtrid with the branch id (gtrid = xid + "-" + branchId, formatId 9753) so every branch owns a distinct gtrid. The legacy format (formatId 9752, gtrid = xid) is kept byte-for-byte for every other database.
### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
fix #8311
### Ⅲ. Why don't you add test cases (unit test/integration test)?
### Ⅳ. Describe how to verify it
### Ⅴ. Special notes for reviews
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: use per-branch qualified gtrid in XA mode for DM [incubator-seata]
Posted by "codecov[bot] (via GitHub) via notifications" <no...@seata.apache.org>.
codecov[bot] commented on PR #8312:
URL: https://github.com/apache/incubator-seata/pull/8312#issuecomment-6619788781
## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `86.04651%` with `6 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 79.87%. Comparing base ([`cba73e1`](https://app.codecov.io/gh/apache/incubator-seata/commit/cba73e180fd8896a99df6415b859d275122feaa7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`24a7509`](https://app.codecov.io/gh/apache/incubator-seata/commit/24a75097dcde3bedcff77be32af896a8e79fb7e6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...ache/seata/rm/datasource/xa/ConnectionProxyXA.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Fxa%2FConnectionProxyXA.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS94YS9Db25uZWN0aW9uUHJveHlYQS5qYXZh) | 77.77% | [1 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...org/apache/seata/rm/datasource/xa/XABranchXid.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Fxa%2FXABranchXid.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS94YS9YQUJyYW5jaFhpZC5qYXZh) | 90.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 2.x #8312 +/- ##
============================================
+ Coverage 79.84% 79.87% +0.03%
+ Complexity 1162 1160 -2
============================================
Files 1400 1400
Lines 53011 53046 +35
Branches 6349 6357 +8
============================================
+ Hits 42325 42371 +46
+ Misses 7729 7723 -6
+ Partials 2957 2952 -5
```
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...ache/seata/rm/datasource/xa/ResourceManagerXA.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Fxa%2FResourceManagerXA.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS94YS9SZXNvdXJjZU1hbmFnZXJYQS5qYXZh) | `89.04% <100.00%> (+0.15%)` | :arrow_up: |
| [...rg/apache/seata/rm/datasource/xa/XAXidBuilder.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Fxa%2FXAXidBuilder.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS94YS9YQVhpZEJ1aWxkZXIuamF2YQ==) | `100.00% <100.00%> (ø)` | |
| [...org/apache/seata/rm/datasource/xa/XABranchXid.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Fxa%2FXABranchXid.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS94YS9YQUJyYW5jaFhpZC5qYXZh) | `75.80% <90.00%> (+7.62%)` | :arrow_up: |
| [...ache/seata/rm/datasource/xa/ConnectionProxyXA.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Fxa%2FConnectionProxyXA.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS94YS9Db25uZWN0aW9uUHJveHlYQS5qYXZh) | `89.49% <77.77%> (-0.80%)` | :arrow_down: |
... and [11 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/8312/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
[](https://app.codecov.io/gh/apache/incubator-seata/pull/8312?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: use per-branch qualified gtrid in XA mode for DM [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #8312:
URL: https://github.com/apache/incubator-seata/pull/8312#issuecomment-6285376014
<img width="952" height="106" alt="image" src="https://github.com/user-attachments/assets/adfdc143-afc1-41e4-bd28-b6b4e647960e" />
Please make sure the email address in your Git commits matches the one you used to submit the PR.
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: use per-branch qualified gtrid in XA mode for DM [incubator-seata]
Posted by "whaon (via GitHub)" <gi...@apache.org>.
whaon commented on PR #8312:
URL: https://github.com/apache/incubator-seata/pull/8312#issuecomment-6285697532
> <img alt="image" width="952" height="106" src="https://private-user-images.githubusercontent.com/19943636/678728965-adfdc143-afc1-41e4-bd28-b6b4e647960e.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTI0ODEzNTcsIm5iZiI6MTc5MjQ4MTA1NywicGF0aCI6Ii8xOTk0MzYzNi82Nzg3Mjg5NjUtYWRmZGMxNDMtYWZjMS00MWU0LWJkMjgtYjZiNGU2NDc5NjBlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjEwMjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMDIwVDA3MjQxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY1OTcwMmVlMmRjYThkZThiYjc2YzE2MGNiNzk4OTgzYmU4YjcwNzI5ZmI3OWVjNmNhZDczMzhmZmE5NTFiNTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.8BmpsOHdhxmg7-zheSwuFCLDjRz29ODbMavGbcGxyWE"> Please make sure the email address in your Git commits matches the one you used to submit the PR.
done
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: use per-branch qualified gtrid in XA mode for DM [incubator-seata]
Posted by "whaon (via GitHub)" <gi...@apache.org>.
whaon commented on code in PR #8312:
URL: https://github.com/apache/incubator-seata/pull/8312#discussion_r4331969371
##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java:
##########
@@ -204,7 +204,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
"failed to register xa branch " + xid + " since " + te.getCode() + ":" + te.getMessage(), te);
}
// 2. build XA-Xid with xid and branchId
- this.xaBranchXid = XAXidBuilder.build(xid, branchId);
+ this.xaBranchXid = XAXidBuilder.build(xid, branchId, resource.getDbType());
Review Comment:
done, see the new push
##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ResourceManagerXA.java:
##########
@@ -143,8 +143,10 @@ private BranchStatus finishBranch(
String resourceId,
String applicationData)
throws TransactionException {
- XAXid xaBranchXid = XAXidBuilder.build(xid, branchId);
Resource resource = dataSourceCache.get(resourceId);
+ String dbType =
+ resource instanceof BaseDataSourceResource ? ((BaseDataSourceResource) resource).getDbType() : null;
+ XAXid xaBranchXid = XAXidBuilder.build(xid, branchId, dbType);
Review Comment:
done, see the new push
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: use per-branch qualified gtrid in XA mode for DM [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #8312:
URL: https://github.com/apache/incubator-seata/pull/8312#discussion_r4322605326
##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java:
##########
@@ -204,7 +204,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
"failed to register xa branch " + xid + " since " + te.getCode() + ":" + te.getMessage(), te);
}
// 2. build XA-Xid with xid and branchId
- this.xaBranchXid = XAXidBuilder.build(xid, branchId);
+ this.xaBranchXid = XAXidBuilder.build(xid, branchId, resource.getDbType());
Review Comment:
[P1] Keep previously valid XIDs usable before and after branch registration
The new DM encoder can throw here **after** `branchRegister()` has succeeded, outside the `start()` failure handling. For example, with `xid = "2001:db8:1234:5678:90ab:cdef:1234:5678:8091:812345678901234567"` and `branchId = 812345678901234567L`, the old gtrid is 62 UTF-8 bytes, but the new one is 81 bytes. I compiled the PR's encoder and reproduced the `IllegalArgumentException`. No physical XA branch has started, yet the TC already has its registration. Worse, `ResourceManagerXA.finishBranch()` reconstructs the same overlong Xid before its try/catch, so TC-driven rollback cannot even reach `XAResource.rollback()` to resolve that registration.
Please use a deterministic bounded encoding for supported Seata XIDs and cover this failure through registration and phase-two rollback. Merely catching the exception here, or asserting that an oversized builder input throws, leaves the phase-two failure in place.
##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ResourceManagerXA.java:
##########
@@ -143,8 +143,10 @@ private BranchStatus finishBranch(
String resourceId,
String applicationData)
throws TransactionException {
- XAXid xaBranchXid = XAXidBuilder.build(xid, branchId);
Resource resource = dataSourceCache.get(resourceId);
+ String dbType =
+ resource instanceof BaseDataSourceResource ? ((BaseDataSourceResource) resource).getDbType() : null;
+ XAXid xaBranchXid = XAXidBuilder.build(xid, branchId, dbType);
Review Comment:
[P1] Reconstruct the format used at prepare time during upgrade recovery
This chooses the physical Xid from the **current** database type alone. If a DM branch was prepared by the previous RM with `(9752, xid, "-" + branchId)` and the RM is upgraded/restarted before phase two completes, this now builds `(9753, xid + "-" + branchId, "-" + branchId)`. Both commit and rollback therefore address a different XA transaction; the TC request carries the logical xid/branchId but no persisted encoding version to select the old identity.
The existing `XAER_NOTA` handling does not make this safe: `ResourceManagerXA` maps it to a retryable status, and `DefaultCore.doGlobalCommit()` / `doGlobalRollback()` eventually treat that status as successful after `isXaerNotaTimeout()` and remove the branch record. The old prepared transaction can remain unresolved in DM while TC considers it finished.
Please provide a recovery strategy that preserves the original physical identity, with old-prepare/new-RM commit and rollback coverage. If this intentionally requires a drained/offline upgrade, make that an explicit, enforceable migration requirement before enabling the new format. The current phase-two test only rebuilds the new format twice and misses this case.
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org