Search in sources :

Example 11 with GlobalStatus

use of io.seata.core.model.GlobalStatus in project seata by seata.

the class DefaultCoreTest method rollBackTest.

/**
 * Roll back test.
 *
 * @param xid the xid
 * @throws Exception the exception
 */
@ParameterizedTest
@MethodSource("xidProvider")
public void rollBackTest(String xid) throws Exception {
    GlobalStatus globalStatus = core.rollback(xid);
    Assertions.assertEquals(globalStatus, GlobalStatus.Rollbacked);
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with GlobalStatus

use of io.seata.core.model.GlobalStatus in project seata by seata.

the class DefaultCoreTest method commitTest.

/**
 * Commit test.
 *
 * @param xid the xid
 * @throws Exception the exception
 */
@ParameterizedTest
@MethodSource("xidProvider")
public void commitTest(String xid) throws Exception {
    GlobalStatus globalStatus = core.commit(xid);
    Assertions.assertNotEquals(globalStatus, GlobalStatus.Begin);
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with GlobalStatus

use of io.seata.core.model.GlobalStatus in project seata by seata.

the class GlobalSession method queueToRetryRollback.

public void queueToRetryRollback() throws TransactionException {
    this.addSessionLifecycleListener(SessionHolder.getRetryRollbackingSessionManager());
    SessionHolder.getRetryRollbackingSessionManager().addGlobalSession(this);
    GlobalStatus currentStatus = this.getStatus();
    if (SessionHelper.isTimeoutGlobalStatus(currentStatus)) {
        this.changeStatus(GlobalStatus.TimeoutRollbackRetrying);
    } else {
        this.changeStatus(GlobalStatus.RollbackRetrying);
    }
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus)

Example 14 with GlobalStatus

use of io.seata.core.model.GlobalStatus in project seata by seata.

the class SessionHolder method reload.

// region reload
/**
 * Reload.
 */
protected static void reload(StoreMode storeMode) {
    if (ROOT_SESSION_MANAGER instanceof Reloadable) {
        ((Reloadable) ROOT_SESSION_MANAGER).reload();
    }
    Collection<GlobalSession> allSessions = ROOT_SESSION_MANAGER.allSessions();
    if (CollectionUtils.isNotEmpty(allSessions)) {
        List<GlobalSession> removeGlobalSessions = new ArrayList<>();
        Iterator<GlobalSession> iterator = allSessions.iterator();
        while (iterator.hasNext()) {
            GlobalSession globalSession = iterator.next();
            GlobalStatus globalStatus = globalSession.getStatus();
            switch(globalStatus) {
                case UnKnown:
                case Committed:
                case CommitFailed:
                case Rollbacked:
                case RollbackFailed:
                case TimeoutRollbacked:
                case TimeoutRollbackFailed:
                case Finished:
                    removeGlobalSessions.add(globalSession);
                    break;
                case AsyncCommitting:
                    if (storeMode == StoreMode.FILE) {
                        queueToAsyncCommitting(globalSession);
                    }
                    break;
                default:
                    {
                        if (storeMode == StoreMode.FILE) {
                            lockBranchSessions(globalSession.getSortedBranches());
                            switch(globalStatus) {
                                case Committing:
                                case CommitRetrying:
                                    queueToRetryCommit(globalSession);
                                    break;
                                case Rollbacking:
                                case RollbackRetrying:
                                case TimeoutRollbacking:
                                case TimeoutRollbackRetrying:
                                    queueToRetryRollback(globalSession);
                                    break;
                                case Begin:
                                    globalSession.setActive(true);
                                    break;
                                default:
                                    throw new ShouldNeverHappenException("NOT properly handled " + globalStatus);
                            }
                        }
                        break;
                    }
            }
        }
        for (GlobalSession globalSession : removeGlobalSessions) {
            removeInErrorState(globalSession);
        }
    }
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus) ArrayList(java.util.ArrayList) ShouldNeverHappenException(io.seata.common.exception.ShouldNeverHappenException)

Example 15 with GlobalStatus

use of io.seata.core.model.GlobalStatus in project seata by seata.

the class SessionHelper method endRollbackFailed.

/**
 * End rollback failed.
 *
 * @param globalSession the global session
 * @throws TransactionException the transaction exception
 */
public static void endRollbackFailed(GlobalSession globalSession) throws TransactionException {
    GlobalStatus currentStatus = globalSession.getStatus();
    if (isTimeoutGlobalStatus(currentStatus)) {
        globalSession.changeStatus(GlobalStatus.TimeoutRollbackFailed);
    } else {
        globalSession.changeStatus(GlobalStatus.RollbackFailed);
    }
    globalSession.end();
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus)

Aggregations

GlobalStatus (io.seata.core.model.GlobalStatus)20 TransactionException (io.seata.core.exception.TransactionException)4 ArrayList (java.util.ArrayList)4 BranchSession (io.seata.server.session.BranchSession)3 GlobalSession (io.seata.server.session.GlobalSession)3 SessionCondition (io.seata.server.session.SessionCondition)3 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)2 BranchStatus (io.seata.core.model.BranchStatus)2 SessionManager (io.seata.server.session.SessionManager)2 FileTransactionStoreManager (io.seata.server.storage.file.store.FileTransactionStoreManager)2 TransactionStoreManager (io.seata.server.store.TransactionStoreManager)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 DefaultConnection (io.mycat.datasource.jdbc.datasource.DefaultConnection)1 GlobalTransactionEvent (io.seata.core.event.GlobalTransactionEvent)1 AbstractGlobalEndResponse (io.seata.core.protocol.transaction.AbstractGlobalEndResponse)1