Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
bugfix: fix XA connection rollback failure (#6492)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanyaofei committed Apr 23, 2024
1 parent eabb48c commit 13600a8
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ public synchronized void commit() throws SQLException {
}
try {
// XA End: Success
end(XAResource.TMSUCCESS);
try {
end(XAResource.TMSUCCESS);
} catch (SQLException sqle) {
// Rollback immediately before the XA Branch Context was deleted.
rollback(false);
throw new SQLException(sqle.getMessage(), SQLSTATE_XA_NOT_END, sqle);
}
long now = System.currentTimeMillis();
checkTimeout(now);
setPrepareTime(now);
Expand All @@ -215,7 +221,7 @@ public synchronized void commit() throws SQLException {
// Branch Report to TC: Failed
reportStatusToTC(BranchStatus.PhaseOne_Failed);
throw new SQLException(
"Failed to end(TMSUCCESS)/prepare xa branch on " + xid + "-" + xaBranchXid.getBranchId() + " since " + xe
"Failed to end(TMSUCCESS)/prepare/rollback(TMFAIL) xa branch on " + xid + "-" + xaBranchXid.getBranchId() + " since " + xe
.getMessage(), xe);
} finally {
cleanXABranchContext();
Expand All @@ -224,6 +230,11 @@ public synchronized void commit() throws SQLException {

@Override
public void rollback() throws SQLException {
// XA End & XA Rollback
rollback(true);
}

public void rollback(boolean end) throws SQLException {
if (currentAutoCommitStatus) {
// Ignore the committing on an autocommit session.
return;
Expand All @@ -233,8 +244,10 @@ public void rollback() throws SQLException {
}
try {
if (!rollBacked) {
// XA End: Fail
xaResource.end(this.xaBranchXid, XAResource.TMFAIL);
if (end) {
// XA End: Fail
xaResource.end(this.xaBranchXid, XAResource.TMFAIL);
}
xaRollback(xaBranchXid);
}
// Branch Report to TC
Expand Down

0 comments on commit 13600a8

Please sign in to comment.