Search in sources :

Example 16 with TransactionException

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

the class SessionHolder method queueToRetryRollback.

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

Example 17 with TransactionException

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

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 18 with TransactionException

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

the class SessionHolder method queueToRetryCommit.

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

Example 19 with TransactionException

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

the class SagaCore method doGlobalCommit.

@Override
public boolean doGlobalCommit(GlobalSession globalSession, boolean retrying) throws TransactionException {
    try {
        BranchStatus branchStatus = branchCommit(globalSession, SessionHelper.newBranch(BranchType.SAGA, globalSession.getXid(), -1, getSagaResourceId(globalSession), globalSession.getStatus().name()));
        switch(branchStatus) {
            case PhaseTwo_Committed:
                removeAllBranches(globalSession);
                LOGGER.info("Successfully committed SAGA global[" + globalSession.getXid() + "]");
                break;
            case PhaseTwo_Rollbacked:
                LOGGER.info("Successfully rollbacked SAGA global[" + globalSession.getXid() + "]");
                removeAllBranches(globalSession);
                SessionHelper.endRollbacked(globalSession);
                return false;
            case PhaseTwo_RollbackFailed_Retryable:
                LOGGER.error("By [{}], failed to rollback SAGA global [{}], will retry later.", branchStatus, globalSession.getXid());
                SessionHolder.getRetryCommittingSessionManager().removeGlobalSession(globalSession);
                globalSession.queueToRetryRollback();
                return false;
            case PhaseOne_Failed:
                LOGGER.error("By [{}], finish SAGA global [{}]", branchStatus, globalSession.getXid());
                removeAllBranches(globalSession);
                globalSession.changeStatus(GlobalStatus.Finished);
                globalSession.end();
                return false;
            case PhaseTwo_CommitFailed_Unretryable:
                if (globalSession.canBeCommittedAsync()) {
                    LOGGER.error("By [{}], failed to commit SAGA global [{}]", branchStatus, globalSession.getXid());
                    break;
                } else {
                    SessionHelper.endCommitFailed(globalSession);
                    LOGGER.error("Finally, failed to commit SAGA global[{}]", globalSession.getXid());
                    return false;
                }
            default:
                if (!retrying) {
                    globalSession.queueToRetryCommit();
                    return false;
                } else {
                    LOGGER.error("Failed to commit SAGA global[{}], will retry later.", globalSession.getXid());
                    return false;
                }
        }
    } catch (Exception ex) {
        LOGGER.error("Failed to commit global[" + globalSession.getXid() + "]", ex);
        if (!retrying) {
            globalSession.queueToRetryRollback();
        }
        throw new TransactionException(ex);
    }
    return true;
}
Also used : TransactionException(io.seata.core.exception.TransactionException) GlobalTransactionException(io.seata.core.exception.GlobalTransactionException) BranchStatus(io.seata.core.model.BranchStatus) TransactionException(io.seata.core.exception.TransactionException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) GlobalTransactionException(io.seata.core.exception.GlobalTransactionException)

Example 20 with TransactionException

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

the class DefaultCoordinatorTest method branchCommit.

@Test
public void branchCommit() throws TransactionException {
    BranchStatus result = null;
    String xid = null;
    GlobalSession globalSession = null;
    try {
        xid = core.begin(applicationId, txServiceGroup, txName, timeout);
        Long branchId = core.branchRegister(BranchType.AT, resourceId, clientId, xid, applicationData, lockKeys_1);
        globalSession = SessionHolder.findGlobalSession(xid);
        result = core.branchCommit(globalSession, globalSession.getBranch(branchId));
    } catch (TransactionException e) {
        Assertions.fail(e.getMessage());
    }
    Assertions.assertEquals(result, BranchStatus.PhaseTwo_Committed);
    globalSession = SessionHolder.findGlobalSession(xid);
    Assertions.assertNotNull(globalSession);
    globalSession.end();
}
Also used : TransactionException(io.seata.core.exception.TransactionException) GlobalSession(io.seata.server.session.GlobalSession) BranchStatus(io.seata.core.model.BranchStatus) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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