Skip to content

Commit

Permalink
bugfix: Using @GlobalTransactional in RM, when RM rolls back, ShouldN…
Browse files Browse the repository at this point in the history
…everHappenException will be thrown
  • Loading branch information
pengten committed Mar 28, 2023
1 parent 09bfc42 commit 6e73019
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5413](https://github.com/seata/seata/pull/5413)] fix bad service configuration file and compilation failure
- [[#5415](https://github.com/seata/seata/pull/5415)] fix transaction timeout on client side not execute hook and failureHandler
- [[#5447](https://github.com/seata/seata/pull/5447)] fix oracle xa mode cannnot be used By same database

- [[#5472](https://github.com/seata/seata/pull/5472)] Using `@GlobalTransactional` in RM, `ShouldNverHappenException` will be thrown

### optimize:
- [[#5208](https://github.com/seata/seata/pull/5208)] optimize throwable getCause once more
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [[#5413](https://github.com/seata/seata/pull/5413)] 修复 arm64平台下的JDK和Spring兼容问题
- [[#5415](https://github.com/seata/seata/pull/5415)] 修复客户侧事务提交前超时未执行hook和failureHandler的问题
- [[#5447](https://github.com/seata/seata/pull/5447)] fix oracle xa mode cannnot be used By same database
- [[#5472](https://github.com/seata/seata/pull/5472)] 在RM中使用`@GlobalTransactional`时,如果RM执行失败会抛出`ShouldNeverHappenException`


### optimize:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.seata.tm.TransactionManagerHolder;
import io.seata.tm.api.DefaultFailureHandlerImpl;
import io.seata.tm.api.FailureHandler;
import io.seata.tm.api.GlobalTransaction;
import io.seata.tm.api.TransactionalExecutor;
import io.seata.tm.api.TransactionalTemplate;
import io.seata.tm.api.transaction.NoRollbackRule;
Expand All @@ -64,6 +65,7 @@
import static io.seata.common.DefaultValues.DEFAULT_TM_DEGRADE_CHECK_ALLOW_TIMES;
import static io.seata.common.DefaultValues.DEFAULT_TM_DEGRADE_CHECK_PERIOD;
import static io.seata.common.DefaultValues.TM_INTERCEPTOR_ORDER;
import static io.seata.tm.api.GlobalTransactionRole.Participant;

/**
* The type Global transactional interceptor.
Expand Down Expand Up @@ -247,6 +249,12 @@ public TransactionInfo getTransactionInfo() {
}
});
} catch (TransactionalExecutor.ExecutionException e) {
GlobalTransaction globalTransaction = e.getTransaction();

// If Participant, just throw the exception to original.
if (globalTransaction.getGlobalTransactionRole() == Participant) {
throw e.getOriginalException();
}
TransactionalExecutor.Code code = e.getCode();
Throwable cause = e.getCause();
boolean timeout = isTimeoutException(cause);
Expand All @@ -259,17 +267,17 @@ public TransactionInfo getTransactionInfo() {
}
case BeginFailure:
succeed = false;
failureHandler.onBeginFailure(e.getTransaction(), cause);
failureHandler.onBeginFailure(globalTransaction, cause);
throw cause;
case CommitFailure:
succeed = false;
failureHandler.onCommitFailure(e.getTransaction(), cause);
failureHandler.onCommitFailure(globalTransaction, cause);
throw cause;
case RollbackFailure:
failureHandler.onRollbackFailure(e.getTransaction(), e.getOriginalException());
failureHandler.onRollbackFailure(globalTransaction, e.getOriginalException());
throw e.getOriginalException();
case Rollbacking:
failureHandler.onRollbacking(e.getTransaction(), e.getOriginalException());
failureHandler.onRollbacking(globalTransaction, e.getOriginalException());
if (timeout) {
throw cause;
} else {
Expand Down

0 comments on commit 6e73019

Please sign in to comment.