Search in sources :

Example 11 with TransactionException

use of io.seata.core.exception.TransactionException in project seata by seata.

the class SessionHolder method queueToAsyncCommitting.

private static void queueToAsyncCommitting(GlobalSession globalSession) {
    try {
        globalSession.addSessionLifecycleListener(getAsyncCommittingSessionManager());
        getAsyncCommittingSessionManager().addGlobalSession(globalSession);
    } catch (TransactionException e) {
        throw new ShouldNeverHappenException(e);
    }
}
Also used : TransactionException(io.seata.core.exception.TransactionException) ShouldNeverHappenException(io.seata.common.exception.ShouldNeverHappenException)

Example 12 with TransactionException

use of io.seata.core.exception.TransactionException in project seata by seata.

the class XAModeTest2 method initRM.

private void initRM() throws Throwable {
    // init RM
    DefaultResourceManager.get();
    // mock the RM of XA
    DefaultResourceManager.mockResourceManager(BranchType.XA, new ResourceManagerXA() {

        @Override
        public void registerResource(Resource resource) {
            dataSourceCache.put(resource.getResourceId(), resource);
        }

        @Override
        public Long branchRegister(BranchType branchType, String resourceId, String clientId, String xid, String applicationData, String lockKeys) throws TransactionException {
            return mockBranchId;
        }

        @Override
        public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException {
        }
    });
}
Also used : TransactionException(io.seata.core.exception.TransactionException) BranchType(io.seata.core.model.BranchType) ResourceManagerXA(io.seata.rm.datasource.xa.ResourceManagerXA) XAResource(javax.transaction.xa.XAResource) Resource(io.seata.core.model.Resource) BranchStatus(io.seata.core.model.BranchStatus)

Example 13 with TransactionException

use of io.seata.core.exception.TransactionException in project seata by seata.

the class DefaultFailureHandlerImpl method shouldStop.

private boolean shouldStop(final GlobalTransaction tx, GlobalStatus required) {
    try {
        GlobalStatus status = tx.getStatus();
        LOGGER.info("transaction [{}] current status is [{}]", tx.getXid(), status);
        if (status == required || status == GlobalStatus.Finished) {
            return true;
        }
    } catch (TransactionException e) {
        LOGGER.error("fetch GlobalTransaction status error", e);
    }
    return false;
}
Also used : TransactionException(io.seata.core.exception.TransactionException) GlobalStatus(io.seata.core.model.GlobalStatus)

Example 14 with TransactionException

use of io.seata.core.exception.TransactionException in project seata by seata.

the class DefaultGlobalTransaction method rollback.

@Override
public void rollback() throws TransactionException {
    if (role == GlobalTransactionRole.Participant) {
        // Participant has no responsibility of rollback
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Ignore Rollback(): just involved in global transaction [{}]", xid);
        }
        return;
    }
    assertXIDNotNull();
    int retry = ROLLBACK_RETRY_COUNT <= 0 ? DEFAULT_TM_ROLLBACK_RETRY_COUNT : ROLLBACK_RETRY_COUNT;
    try {
        while (retry > 0) {
            try {
                status = transactionManager.rollback(xid);
                break;
            } catch (Throwable ex) {
                LOGGER.error("Failed to report global rollback [{}],Retry Countdown: {}, reason: {}", this.getXid(), retry, ex.getMessage());
                retry--;
                if (retry == 0) {
                    throw new TransactionException("Failed to report global rollback", ex);
                }
            }
        }
    } finally {
        if (xid.equals(RootContext.getXID())) {
            suspend();
        }
    }
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("[{}] rollback status: {}", xid, status);
    }
}
Also used : TransactionException(io.seata.core.exception.TransactionException)

Example 15 with TransactionException

use of io.seata.core.exception.TransactionException in project XHuiCloud by sindaZeng.

the class DefaultCoordinator method handleRetryCommitting.

/**
 * Handle retry committing.
 */
protected void handleRetryCommitting() {
    Collection<GlobalSession> committingSessions = SessionHolder.getRetryCommittingSessionManager().allSessions();
    if (CollectionUtils.isEmpty(committingSessions)) {
        return;
    }
    long now = System.currentTimeMillis();
    for (GlobalSession committingSession : committingSessions) {
        try {
            if (isRetryTimeout(now, MAX_COMMIT_RETRY_TIMEOUT.toMillis(), committingSession.getBeginTime())) {
                /**
                 * Prevent thread safety issues
                 */
                SessionHolder.getRetryCommittingSessionManager().removeGlobalSession(committingSession);
                LOGGER.error("Global transaction commit retry timeout and has removed [{}]", committingSession.getXid());
                continue;
            }
            committingSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
            core.doGlobalCommit(committingSession, true);
        } catch (TransactionException ex) {
            LOGGER.info("Failed to retry committing [{}] {} {}", committingSession.getXid(), ex.getCode(), ex.getMessage());
        }
    }
}
Also used : TransactionException(io.seata.core.exception.TransactionException) GlobalSession(io.seata.server.session.GlobalSession)

Aggregations

TransactionException (io.seata.core.exception.TransactionException)54 BranchStatus (io.seata.core.model.BranchStatus)14 GlobalSession (io.seata.server.session.GlobalSession)9 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)7 StoreException (io.seata.common.exception.StoreException)7 ExecutionException (io.seata.tm.api.TransactionalExecutor.ExecutionException)6 GlobalTransaction (io.seata.tm.api.GlobalTransaction)5 IOException (java.io.IOException)5 TimeoutException (java.util.concurrent.TimeoutException)5 NotSupportYetException (io.seata.common.exception.NotSupportYetException)4 GlobalTransactionEvent (io.seata.core.event.GlobalTransactionEvent)4 GlobalTransactionException (io.seata.core.exception.GlobalTransactionException)4 GlobalStatus (io.seata.core.model.GlobalStatus)4 EngineExecutionException (io.seata.saga.engine.exception.EngineExecutionException)4 BranchSession (io.seata.server.session.BranchSession)4 SQLException (java.sql.SQLException)4 StateMachineInstance (io.seata.saga.statelang.domain.StateMachineInstance)3 TransactionalExecutor (io.seata.tm.api.TransactionalExecutor)3 XAException (javax.transaction.xa.XAException)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3