Skip to content

Commit

Permalink
Merge pull request #41955 from dsplayerX/fix_41948
Browse files Browse the repository at this point in the history
Fix XAER_RMFAIL error on transaction rollback
  • Loading branch information
hasithaa authored Jun 10, 2024
2 parents 905a73a + 5a0d731 commit ed51403
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public boolean isRetryPossible(Strand context, String transactionId) {

public void notifyAbortAndClearTransaction(String transactionBlockId) {
transactionContextStore.clear();
transactionResourceManager.endXATransaction(globalTransactionId, transactionBlockId, true);
transactionResourceManager.notifyAbort(globalTransactionId, transactionBlockId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import static io.ballerina.runtime.transactions.TransactionConstants.TRANSACTION_PACKAGE_ID;
import static io.ballerina.runtime.transactions.TransactionConstants.TRANSACTION_PACKAGE_NAME;
import static io.ballerina.runtime.transactions.TransactionConstants.TRANSACTION_PACKAGE_VERSION;
import static javax.transaction.xa.XAResource.TMFAIL;
import static javax.transaction.xa.XAResource.TMNOFLAGS;
import static javax.transaction.xa.XAResource.TMSUCCESS;

Expand Down Expand Up @@ -245,7 +246,7 @@ public void registerParticipation(String gTransactionId, String transactionBlock
*/
//TODO:Comment for now, might need it for distributed transactions.
public boolean prepare(String transactionId, String transactionBlockId) {
endXATransaction(transactionId, transactionBlockId);
endXATransaction(transactionId, transactionBlockId, false);
if (transactionManagerEnabled) {
return true;
}
Expand Down Expand Up @@ -541,7 +542,7 @@ public TransactionLocalContext getCurrentTransactionContext() {
* @param transactionId the global transaction id
* @param transactionBlockId the block id of the transaction
*/
void endXATransaction(String transactionId, String transactionBlockId) {
void endXATransaction(String transactionId, String transactionBlockId, boolean abortOnly) {
String combinedId = generateCombinedTransactionId(transactionId, transactionBlockId);
if (transactionManagerEnabled) {
Transaction trx = trxRegistry.get(combinedId);
Expand Down Expand Up @@ -569,7 +570,7 @@ void endXATransaction(String transactionId, String transactionBlockId) {
try {
XAResource xaResource = ctx.getXAResource();
if (xaResource != null) {
ctx.getXAResource().end(xid, TMSUCCESS);
xaResource.end(xid, abortOnly ? TMFAIL : TMSUCCESS);
}
} catch (XAException e) {
log.error("error in ending XA transaction " + transactionId + ":" + e.getMessage(), e);
Expand Down

0 comments on commit ed51403

Please sign in to comment.