Search in sources :

Example 6 with GlobalStatus

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

the class WriteStoreMultithreadTest method main.

public static void main(String[] args) throws Exception {
    TransactionStoreManager transactionStoreManager = new FileTransactionStoreManager("data", new SessionManager() {

        @Override
        public void destroy() {
        }

        @Override
        public void addGlobalSession(GlobalSession session) throws TransactionException {
        }

        @Override
        public GlobalSession findGlobalSession(String xid) {
            return null;
        }

        @Override
        public GlobalSession findGlobalSession(String xid, boolean withBranchSessions) {
            return null;
        }

        @Override
        public void updateGlobalSessionStatus(GlobalSession session, GlobalStatus status) throws TransactionException {
        }

        @Override
        public void removeGlobalSession(GlobalSession session) throws TransactionException {
        }

        @Override
        public void addBranchSession(GlobalSession globalSession, BranchSession session) throws TransactionException {
        }

        @Override
        public void updateBranchSessionStatus(BranchSession session, BranchStatus status) throws TransactionException {
        }

        @Override
        public void removeBranchSession(GlobalSession globalSession, BranchSession session) throws TransactionException {
        }

        @Override
        public Collection<GlobalSession> allSessions() {
            return null;
        }

        @Override
        public List<GlobalSession> findGlobalSessions(SessionCondition condition) {
            List<GlobalSession> globalSessions = new ArrayList<>();
            int begin = 10000;
            int num = 1000;
            for (int i = begin; i < begin + num; i++) {
                BranchSession branchSession1 = new BranchSession();
                branchSession1.setTransactionId(i);
                branchSession1.setBranchId(begin + num + (i - begin) * 2);
                branchSession1.setResourceId("mockDbkeY1");
                BranchSession branchSession2 = new BranchSession();
                branchSession2.setTransactionId(i);
                branchSession2.setBranchId(begin + num + (i - begin) * 2 + 1);
                branchSession2.setResourceId("mockDbkeY2");
                GlobalSession globalSession = new GlobalSession(appname, vgroup, instname, 60000);
                try {
                    globalSession.add(branchSession1);
                    globalSession.add(branchSession2);
                    globalSessions.add(globalSession);
                } catch (Exception exx) {
                }
            }
            return globalSessions;
        }

        @Override
        public <T> T lockAndExecute(GlobalSession globalSession, GlobalSession.LockCallable<T> lockCallable) throws TransactionException {
            return null;
        }

        @Override
        public void onBegin(GlobalSession globalSession) throws TransactionException {
        }

        @Override
        public void onStatusChange(GlobalSession globalSession, GlobalStatus status) throws TransactionException {
        }

        @Override
        public void onBranchStatusChange(GlobalSession globalSession, BranchSession branchSession, BranchStatus status) throws TransactionException {
        }

        @Override
        public void onAddBranch(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
        }

        @Override
        public void onRemoveBranch(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
        }

        @Override
        public void onClose(GlobalSession globalSession) throws TransactionException {
        }

        @Override
        public void onEnd(GlobalSession globalSession) throws TransactionException {
        }
    });
    long beginWriteMills = System.currentTimeMillis();
    for (int i = 0; i < threadNum; i++) {
        final int threadNo = i;
        Thread thread = new Thread(() -> {
            write(transactionStoreManager, threadNo);
        });
        thread.start();
    }
    countDownLatch.await();
    long endWriteMills = System.currentTimeMillis();
    System.out.println("thread nums:" + threadNum + ", per_thread_trx_num:" + per_thread_trx_num + " ,cost" + (endWriteMills - beginWriteMills));
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus) SessionManager(io.seata.server.session.SessionManager) BranchSession(io.seata.server.session.BranchSession) SessionCondition(io.seata.server.session.SessionCondition) TransactionException(io.seata.core.exception.TransactionException) TransactionStoreManager(io.seata.server.store.TransactionStoreManager) FileTransactionStoreManager(io.seata.server.storage.file.store.FileTransactionStoreManager) TransactionException(io.seata.core.exception.TransactionException) GlobalSession(io.seata.server.session.GlobalSession) Collection(java.util.Collection) BranchStatus(io.seata.core.model.BranchStatus) ArrayList(java.util.ArrayList) List(java.util.List) FileTransactionStoreManager(io.seata.server.storage.file.store.FileTransactionStoreManager)

Example 7 with GlobalStatus

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

the class AbstractGlobalEndResponseCodec method encode.

@Override
public <T> void encode(T t, ByteBuf in) {
    super.encode(t, in);
    AbstractGlobalEndResponse abstractGlobalEndResponse = (AbstractGlobalEndResponse) t;
    GlobalStatus globalStatus = abstractGlobalEndResponse.getGlobalStatus();
    in.writeByte(globalStatus.getCode());
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus) AbstractGlobalEndResponse(io.seata.core.protocol.transaction.AbstractGlobalEndResponse)

Example 8 with GlobalStatus

use of io.seata.core.model.GlobalStatus 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 9 with GlobalStatus

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

the class FileSessionManager method washSessions.

private void washSessions() {
    if (sessionMap.size() > 0) {
        Iterator<Map.Entry<String, GlobalSession>> iterator = sessionMap.entrySet().iterator();
        while (iterator.hasNext()) {
            GlobalSession globalSession = iterator.next().getValue();
            GlobalStatus globalStatus = globalSession.getStatus();
            switch(globalStatus) {
                case UnKnown:
                case Committed:
                case CommitFailed:
                case Rollbacked:
                case RollbackFailed:
                case TimeoutRollbacked:
                case TimeoutRollbackFailed:
                case Finished:
                    // Remove all sessions finished
                    iterator.remove();
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : GlobalStatus(io.seata.core.model.GlobalStatus)

Example 10 with GlobalStatus

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

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