Search in sources :

Example 26 with GlobalSession

use of io.seata.server.session.GlobalSession 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 27 with GlobalSession

use of io.seata.server.session.GlobalSession in project seata by seata.

the class DefaultCoreTest method releaseSessionManager.

/**
 * Release session manager.
 *
 * @throws Exception the exception
 */
@AfterEach
public void releaseSessionManager() throws Exception {
    Collection<GlobalSession> globalSessions = SessionHolder.getRootSessionManager().allSessions();
    Collection<GlobalSession> asyncGlobalSessions = SessionHolder.getAsyncCommittingSessionManager().allSessions();
    for (GlobalSession asyncGlobalSession : asyncGlobalSessions) {
        asyncGlobalSession.closeAndClean();
    }
    for (GlobalSession globalSession : globalSessions) {
        globalSession.closeAndClean();
    }
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) AfterEach(org.junit.jupiter.api.AfterEach)

Example 28 with GlobalSession

use of io.seata.server.session.GlobalSession in project seata by seata.

the class SessionConverter method convertGlobalSession.

public static GlobalSession convertGlobalSession(GlobalTransactionDO globalTransactionDO) {
    if (globalTransactionDO == null) {
        return null;
    }
    GlobalSession session = new GlobalSession(globalTransactionDO.getApplicationId(), globalTransactionDO.getTransactionServiceGroup(), globalTransactionDO.getTransactionName(), globalTransactionDO.getTimeout());
    session.setXid(globalTransactionDO.getXid());
    session.setTransactionId(globalTransactionDO.getTransactionId());
    session.setStatus(GlobalStatus.get(globalTransactionDO.getStatus()));
    session.setApplicationData(globalTransactionDO.getApplicationData());
    session.setBeginTime(globalTransactionDO.getBeginTime());
    return session;
}
Also used : GlobalSession(io.seata.server.session.GlobalSession)

Example 29 with GlobalSession

use of io.seata.server.session.GlobalSession in project seata by seata.

the class SessionConverter method convertGlobalTransactionDO.

public static GlobalTransactionDO convertGlobalTransactionDO(SessionStorable session) {
    if (session == null || !(session instanceof GlobalSession)) {
        throw new IllegalArgumentException("The parameter of SessionStorable is not available, SessionStorable:" + StringUtils.toString(session));
    }
    GlobalSession globalSession = (GlobalSession) session;
    GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
    globalTransactionDO.setXid(globalSession.getXid());
    globalTransactionDO.setStatus(globalSession.getStatus().getCode());
    globalTransactionDO.setApplicationId(globalSession.getApplicationId());
    globalTransactionDO.setBeginTime(globalSession.getBeginTime());
    globalTransactionDO.setTimeout(globalSession.getTimeout());
    globalTransactionDO.setTransactionId(globalSession.getTransactionId());
    globalTransactionDO.setTransactionName(globalSession.getTransactionName());
    globalTransactionDO.setTransactionServiceGroup(globalSession.getTransactionServiceGroup());
    globalTransactionDO.setApplicationData(globalSession.getApplicationData());
    return globalTransactionDO;
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) GlobalSession(io.seata.server.session.GlobalSession)

Example 30 with GlobalSession

use of io.seata.server.session.GlobalSession in project XHuiCloud by sindaZeng.

the class DataBaseTransactionStoreManager method readSession.

@Override
public List<GlobalSession> readSession(SessionCondition sessionCondition) {
    if (StringUtils.isNotBlank(sessionCondition.getXid())) {
        GlobalSession globalSession = readSession(sessionCondition.getXid());
        if (globalSession != null) {
            List<GlobalSession> globalSessions = new ArrayList<>();
            globalSessions.add(globalSession);
            return globalSessions;
        }
    } else if (sessionCondition.getTransactionId() != null) {
        GlobalSession globalSession = readSession(sessionCondition.getTransactionId());
        if (globalSession != null) {
            List<GlobalSession> globalSessions = new ArrayList<>();
            globalSessions.add(globalSession);
            return globalSessions;
        }
    } else if (CollectionUtils.isNotEmpty(sessionCondition.getStatuses())) {
        return readSession(sessionCondition.getStatuses());
    }
    return null;
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

GlobalSession (io.seata.server.session.GlobalSession)73 BranchSession (io.seata.server.session.BranchSession)33 Test (org.junit.jupiter.api.Test)32 Connection (java.sql.Connection)10 TransactionException (io.seata.core.exception.TransactionException)9 ArrayList (java.util.ArrayList)8 SessionCondition (io.seata.server.session.SessionCondition)7 GlobalTransactionEvent (io.seata.core.event.GlobalTransactionEvent)6 BranchStatus (io.seata.core.model.BranchStatus)6 ResultSet (java.sql.ResultSet)6 GlobalTransactionDO (io.seata.core.store.GlobalTransactionDO)5 LockManager (io.seata.server.lock.LockManager)5 FileLockManagerForTest (io.seata.server.lock.file.FileLockManagerForTest)5 FileTransactionStoreManager (io.seata.server.storage.file.store.FileTransactionStoreManager)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 BranchTransactionException (io.seata.core.exception.BranchTransactionException)4 TransactionWriteStore (io.seata.server.storage.file.TransactionWriteStore)4 GlobalStatus (io.seata.core.model.GlobalStatus)3 SessionManager (io.seata.server.session.SessionManager)3