Skip to content

Commit

Permalink
bugfix:fix wrong exception information when rollback fails due to dir…
Browse files Browse the repository at this point in the history
…ty data (apache#2333)
  • Loading branch information
funky-eyes committed Mar 7, 2020
1 parent 826a725 commit 21e0355
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public TransactionInfo getTransactionInfo() {
case RollbackFailure:
failureHandler.onRollbackFailure(e.getTransaction(), e.getCause());
throw e.getCause();
case RollbackRetrying:
failureHandler.onRollbackRetrying(e.getTransaction(), e.getCause());
throw e.getCause();
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 @@ -22,6 +22,7 @@
import io.netty.util.TimerTask;
import io.seata.common.thread.NamedThreadFactory;
import io.seata.core.exception.TransactionException;
import io.seata.core.logger.StackTraceLogger;
import io.seata.core.model.GlobalStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -67,6 +68,13 @@ public void onRollbackFailure(GlobalTransaction tx, Throwable cause) {
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()});
timer.newTimeout(new CheckTimerTask(tx, GlobalStatus.RollbackRetrying), SCHEDULE_INTERVAL_SECONDS,
TimeUnit.SECONDS);
}

protected class CheckTimerTask implements TimerTask {

private final GlobalTransaction tx;
Expand Down
8 changes: 8 additions & 0 deletions tm/src/main/java/io/seata/tm/api/FailureHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ public interface FailureHandler {
* @param cause the cause
*/
void onRollbackFailure(GlobalTransaction tx, Throwable cause);

/**
* On rollback retrying
*
* @param tx the tx
* @param cause the cause
*/
void onRollbackRetrying(GlobalTransaction tx, Throwable cause);
}
8 changes: 7 additions & 1 deletion tm/src/main/java/io/seata/tm/api/TransactionalExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ enum Code {
* Report failure code.
*/
//
ReportFailure
ReportFailure,

/**
* Rollback retrying code.
*/
//
RollbackRetrying
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.seata.common.util.StringUtils;
import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.core.model.GlobalStatus;
import io.seata.tm.api.transaction.Propagation;
import io.seata.tm.api.transaction.TransactionHook;
import io.seata.tm.api.transaction.TransactionHookManager;
Expand Down Expand Up @@ -143,7 +144,9 @@ private void rollbackTransaction(GlobalTransaction tx, Throwable ex) throws Tran
tx.rollback();
triggerAfterRollback();
// 3.1 Successfully rolled back
throw new TransactionalExecutor.ExecutionException(tx, TransactionalExecutor.Code.RollbackDone, ex);
throw new TransactionalExecutor.ExecutionException(tx,
tx.getStatus().equals(GlobalStatus.RollbackRetrying) ? TransactionalExecutor.Code.RollbackRetrying :
TransactionalExecutor.Code.RollbackDone, ex);
}

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

0 comments on commit 21e0355

Please sign in to comment.