Search in sources :

Example 16 with GlobalStatus

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

the class DbAndReportTcStateLogStore method reportTransactionFinished.

protected void reportTransactionFinished(StateMachineInstance machineInstance, ProcessContext context) {
    if (sagaTransactionalTemplate != null) {
        try {
            GlobalTransaction globalTransaction = getGlobalTransaction(machineInstance, context);
            if (globalTransaction == null) {
                throw new EngineExecutionException("Global transaction is not exists", FrameworkErrorCode.ObjectNotExists);
            }
            GlobalStatus globalStatus;
            if (ExecutionStatus.SU.equals(machineInstance.getStatus()) && machineInstance.getCompensationStatus() == null) {
                globalStatus = GlobalStatus.Committed;
            } else if (ExecutionStatus.SU.equals(machineInstance.getCompensationStatus())) {
                globalStatus = GlobalStatus.Rollbacked;
            } else if (ExecutionStatus.FA.equals(machineInstance.getCompensationStatus()) || ExecutionStatus.UN.equals(machineInstance.getCompensationStatus())) {
                globalStatus = GlobalStatus.RollbackRetrying;
            } else if (ExecutionStatus.FA.equals(machineInstance.getStatus()) && machineInstance.getCompensationStatus() == null) {
                globalStatus = GlobalStatus.Finished;
            } else if (ExecutionStatus.UN.equals(machineInstance.getStatus()) && machineInstance.getCompensationStatus() == null) {
                globalStatus = GlobalStatus.CommitRetrying;
            } else {
                globalStatus = GlobalStatus.UnKnown;
            }
            sagaTransactionalTemplate.reportTransaction(globalTransaction, globalStatus);
        } catch (ExecutionException e) {
            LOGGER.error("Report transaction finish to server error: {}, StateMachine: {}, XID: {}, Reason: {}", e.getCode(), machineInstance.getStateMachine().getName(), machineInstance.getId(), e.getMessage(), e);
        } catch (TransactionException e) {
            LOGGER.error("Report transaction finish to server error: {}, StateMachine: {}, XID: {}, Reason: {}", e.getCode(), machineInstance.getStateMachine().getName(), machineInstance.getId(), e.getMessage(), e);
        } finally {
            // clear
            RootContext.unbind();
            RootContext.unbindBranchType();
            sagaTransactionalTemplate.triggerAfterCompletion();
            sagaTransactionalTemplate.cleanUp();
        }
    }
}
Also used : TransactionException(io.seata.core.exception.TransactionException) GlobalStatus(io.seata.core.model.GlobalStatus) GlobalTransaction(io.seata.tm.api.GlobalTransaction) EngineExecutionException(io.seata.saga.engine.exception.EngineExecutionException) ExecutionException(io.seata.tm.api.TransactionalExecutor.ExecutionException) EngineExecutionException(io.seata.saga.engine.exception.EngineExecutionException)

Example 17 with GlobalStatus

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

the class SeataTransactionSession method begin.

@Override
@SneakyThrows
public void begin() {
    if (tx == null) {
        tx = GlobalTransactionContext.createNew();
    }
    String xid = RootContext.getXID();
    if (xid == null) {
        GlobalStatus localStatus = tx.getLocalStatus();
        switch(localStatus) {
            case Rollbacked:
            case Committed:
            case Finished:
            case UnKnown:
                for (Map.Entry<String, DefaultConnection> e : updateConnectionMap.entrySet()) {
                    e.getValue().close();
                }
                updateConnectionMap.clear();
                tx.begin();
                mycatXid = tx.getXid();
                break;
            case Begin:
            case Committing:
            case CommitRetrying:
            case Rollbacking:
            case RollbackRetrying:
            case TimeoutRollbacking:
            case TimeoutRollbackRetrying:
            case AsyncCommitting:
            case CommitFailed:
            case RollbackFailed:
            case TimeoutRollbacked:
            case TimeoutRollbackFailed:
            default:
        }
    }
    dataContext.setInTransaction(true);
}
Also used : DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) GlobalStatus(io.seata.core.model.GlobalStatus) Map(java.util.Map) SneakyThrows(lombok.SneakyThrows)

Example 18 with GlobalStatus

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

the class SessionHelper method endRollbacked.

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

Example 19 with GlobalStatus

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

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 20 with GlobalStatus

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

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)

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