Skip to content

Commit

Permalink
bugfix: TM rollback fail throw the seata exception, rollback retrying…
Browse files Browse the repository at this point in the history
… throw NPE (apache#2760)
  • Loading branch information
wangliang181230 committed Jun 24, 2020
1 parent 16e07c1 commit c860c6b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ public TransactionInfo getTransactionInfo() {
failureHandler.onCommitFailure(e.getTransaction(), e.getCause());
throw e.getCause();
case RollbackFailure:
failureHandler.onRollbackFailure(e.getTransaction(), e.getCause());
throw e.getCause();
failureHandler.onRollbackFailure(e.getTransaction(), e.getOriginalException());
throw e.getOriginalException();
case RollbackRetrying:
failureHandler.onRollbackRetrying(e.getTransaction(), e.getCause());
throw e.getCause();
failureHandler.onRollbackRetrying(e.getTransaction(), e.getOriginalException());
throw e.getOriginalException();
default:
throw new ShouldNeverHappenException(String.format("Unknown TransactionalExecutor.Code: %s", code));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public void onCommitFailure(GlobalTransaction tx, Throwable cause) {
}

@Override
public void onRollbackFailure(GlobalTransaction tx, Throwable cause) {
LOGGER.warn("Failed to rollback transaction[" + tx.getXid() + "]", cause);
public void onRollbackFailure(GlobalTransaction tx, Throwable originalException) {
LOGGER.warn("Failed to rollback transaction[" + tx.getXid() + "]", originalException);
timer.newTimeout(new CheckTimerTask(tx, GlobalStatus.Rollbacked), SCHEDULE_INTERVAL_SECONDS, TimeUnit.SECONDS);
}

@Override
public void onRollbackRetrying(GlobalTransaction tx, Throwable cause) {
StackTraceLogger.warn(LOGGER, cause, "Retrying to rollback transaction[{}]", new String[] {tx.getXid()});
public void onRollbackRetrying(GlobalTransaction tx, Throwable originalException) {
StackTraceLogger.warn(LOGGER, originalException, "Retrying to rollback transaction[{}]", new String[] {tx.getXid()});
timer.newTimeout(new CheckTimerTask(tx, GlobalStatus.RollbackRetrying), SCHEDULE_INTERVAL_SECONDS,
TimeUnit.SECONDS);
}
Expand Down
12 changes: 6 additions & 6 deletions tm/src/main/java/io/seata/tm/api/FailureHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public interface FailureHandler {
/**
* On rollback failure.
*
* @param tx the tx
* @param cause the cause
* @param tx the tx
* @param originalException the originalException
*/
void onRollbackFailure(GlobalTransaction tx, Throwable cause);
void onRollbackFailure(GlobalTransaction tx, Throwable originalException);

/**
* On rollback retrying
*
* @param tx the tx
* @param cause the cause
* @param tx the tx
* @param originalException the originalException
*/
void onRollbackRetrying(GlobalTransaction tx, Throwable cause);
void onRollbackRetrying(GlobalTransaction tx, Throwable originalException);
}
12 changes: 6 additions & 6 deletions tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ public boolean existingTransaction() {



private void completeTransactionAfterThrowing(TransactionInfo txInfo, GlobalTransaction tx, Throwable ex) throws TransactionalExecutor.ExecutionException {
private void completeTransactionAfterThrowing(TransactionInfo txInfo, GlobalTransaction tx, Throwable originalException) throws TransactionalExecutor.ExecutionException {
//roll back
if (txInfo != null && txInfo.rollbackOn(ex)) {
if (txInfo != null && txInfo.rollbackOn(originalException)) {
try {
rollbackTransaction(tx, ex);
rollbackTransaction(tx, originalException);
} catch (TransactionException txe) {
// Failed to rollback
throw new TransactionalExecutor.ExecutionException(tx, txe,
TransactionalExecutor.Code.RollbackFailure, ex);
TransactionalExecutor.Code.RollbackFailure, originalException);
}
} else {
// not roll back on this exception, so commit
Expand All @@ -160,13 +160,13 @@ private void commitTransaction(GlobalTransaction tx) throws TransactionalExecuto
}
}

private void rollbackTransaction(GlobalTransaction tx, Throwable ex) throws TransactionException, TransactionalExecutor.ExecutionException {
private void rollbackTransaction(GlobalTransaction tx, Throwable originalException) throws TransactionException, TransactionalExecutor.ExecutionException {
triggerBeforeRollback();
tx.rollback();
triggerAfterRollback();
// 3.1 Successfully rolled back
throw new TransactionalExecutor.ExecutionException(tx, GlobalStatus.RollbackRetrying.equals(tx.getLocalStatus())
? TransactionalExecutor.Code.RollbackRetrying : TransactionalExecutor.Code.RollbackDone, ex);
? TransactionalExecutor.Code.RollbackRetrying : TransactionalExecutor.Code.RollbackDone, originalException);
}

private void beginTransaction(TransactionInfo txInfo, GlobalTransaction tx) throws TransactionalExecutor.ExecutionException {
Expand Down

0 comments on commit c860c6b

Please sign in to comment.