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: fix readonly branch commit errors in Oracle XA transactions. #6707

Merged
merged 14 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6668](https://github.com/apache/incubator-seata/pull/6668)] thread safety issue when adding and removing instances
- [[#6678](https://github.com/apache/incubator-seata/pull/6678)] fix the same record has different lowkeys due to mixed case of table names yesterday
- [[#6697](https://github.com/apache/incubator-seata/pull/6697)] v0 ByteBuf should not decode by super class
- [[#6707](https://github.com/apache/incubator-seata/pull/6707)] fix readonly branch commit errors in Oracle XA transactions

### optimize:
- [[#6499](https://github.com/apache/incubator-seata/pull/6499)] split the task thread pool for committing and rollbacking statuses
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [[#6668](https://github.com/apache/incubator-seata/pull/6668)] 解决namingserver同一个集群下instance添加和删除时的线程安全问题
- [[#6678](https://github.com/apache/incubator-seata/pull/6678)] 修复由于表名大小写问题导致的相同记录生成不同RowKey的问题
- [[#6697](https://github.com/apache/incubator-seata/pull/6697)] v0版本的ByteBuf不应由父类先解码
- [[#6707](https://github.com/apache/incubator-seata/pull/6707)] 修复Oracle XA事务中只读分支提交出错的问题


### optimize:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ const branchSessionStatusList:Array<StatusType> = [
iconType: 'error',
iconColor: '#FF3333',
},
{
label: 'PhaseOne_RDONLY',
value: 13,
iconType: 'ellipsis',
iconColor: 'rgb(3, 193, 253)',
},
];

class TransactionInfo extends React.Component<GlobalProps, TransactionInfoState> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ public enum BranchStatus {
* The Phase two rollback failed retryable because of XAException.XAER_NOTA.
* description:rollback logic is failed because of XAException.XAER_NOTA but retryable.
*/
PhaseTwo_RollbackFailed_XAER_NOTA_Retryable(12);
PhaseTwo_RollbackFailed_XAER_NOTA_Retryable(12),


/**
* The results of the Phase one are read-only.
* Description: After the branch prepare in the Oracle database, only purely read-only query statements were executed.
*/
PhaseOne_RDONLY(13);

private int code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,14 @@ public synchronized void commit() throws SQLException {
long now = System.currentTimeMillis();
checkTimeout(now);
setPrepareTime(now);
xaResource.prepare(xaBranchXid);
int prepare = xaResource.prepare(xaBranchXid);
// Based on the four databases: MySQL (8), Oracle (12c), Postgres (16), and MSSQL Server (2022),
// only Oracle has read-only optimization; the others do not provide read-only feedback.
// Therefore, the database type check can be eliminated here.
if (prepare == XAResource.XA_RDONLY) {
// Branch Report to TC: RDONLY
reportStatusToTC(BranchStatus.PhaseOne_RDONLY);
}
} catch (XAException xe) {
// Branch Report to TC: Failed
reportStatusToTC(BranchStatus.PhaseOne_Failed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,10 @@ enum BranchStatusProto {
*/
// Rollback logic is failed but NOT retryable.
PhaseTwo_RollbackFailed_Unretryable = 10;
/**
* The results of the Phase one are read-only.
*/
// In the branch transaction, only purely read-only query statements were executed.
PhaseOne_RDONLY = 13;

}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ public boolean doGlobalCommit(GlobalSession globalSession, boolean retrying) thr
SessionHelper.removeBranch(globalSession, branchSession, !retrying);
return CONTINUE;
}
// Only databases with read-only optimization, such as Oracle,
// will report the RDONLY status during XA transactions.
// At this point, the branch transaction can be ignored.
if (currentStatus == BranchStatus.PhaseOne_RDONLY
&& branchSession.getBranchType() == BranchType.XA) {
SessionHelper.removeBranch(globalSession, branchSession, !retrying);
return CONTINUE;
}
try {
BranchStatus branchStatus = getCore(branchSession.getBranchType()).branchCommit(globalSession, branchSession);
if (isXaerNotaTimeout(globalSession,branchStatus)) {
Expand Down
Loading