Search in sources :

Example 1 with LogOperation

use of io.seata.server.store.TransactionStoreManager.LogOperation in project seata by seata.

the class WriteStoreTest method main.

/**
 * The entry point of application.
 *
 * @param args the input arguments
 * @throws InterruptedException the interrupted exception
 * @throws IOException the io exception
 */
public static void main(String[] args) throws InterruptedException, IOException {
    TransactionStoreManager transactionStoreManager = new FileTransactionStoreManager("~/Documents/test/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();
    write(transactionStoreManager);
    long endWriteMills = System.currentTimeMillis();
    Thread.sleep(10 * 1000);
    long beginReadMills = System.currentTimeMillis();
    Map<SessionStorable, LogOperation> resultMap = readAll(transactionStoreManager);
    long endReadMills = System.currentTimeMillis();
    if ((resultMap.size() % (65535)) % 3000 == 0) {
        System.out.print("check success");
    } else {
        System.out.print("check failed");
    }
    System.out.print("write cost:" + (endWriteMills - beginWriteMills) + ",read cost:" + (endReadMills - beginReadMills));
}
Also used : LogOperation(io.seata.server.store.TransactionStoreManager.LogOperation) 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) IOException(java.io.IOException) 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) SessionStorable(io.seata.server.store.SessionStorable) 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 2 with LogOperation

use of io.seata.server.store.TransactionStoreManager.LogOperation in project seata by seata.

the class WriteStoreTest method readAll.

private static Map<SessionStorable, LogOperation> readAll(TransactionStoreManager transactionStoreManager) {
    Map<SessionStorable, LogOperation> resultMap = new HashMap<>(65535 * 5 * 9);
    while (((ReloadableStore) transactionStoreManager).hasRemaining(true)) {
        List<TransactionWriteStore> transactionWriteStores = ((ReloadableStore) transactionStoreManager).readWriteStore(2000, true);
        if (transactionWriteStores != null) {
            for (TransactionWriteStore transactionWriteStore : transactionWriteStores) {
                printLog(transactionWriteStore);
                resultMap.put(transactionWriteStore.getSessionRequest(), transactionWriteStore.getOperate());
            }
        }
    }
    while (((ReloadableStore) transactionStoreManager).hasRemaining(false)) {
        List<TransactionWriteStore> transactionWriteStores = ((ReloadableStore) transactionStoreManager).readWriteStore(2000, false);
        if (transactionWriteStores != null) {
            for (TransactionWriteStore transactionWriteStore : transactionWriteStores) {
                printLog(transactionWriteStore);
                resultMap.put(transactionWriteStore.getSessionRequest(), transactionWriteStore.getOperate());
            }
        }
    }
    return resultMap;
}
Also used : LogOperation(io.seata.server.store.TransactionStoreManager.LogOperation) HashMap(java.util.HashMap) TransactionWriteStore(io.seata.server.storage.file.TransactionWriteStore) SessionStorable(io.seata.server.store.SessionStorable) ReloadableStore(io.seata.server.storage.file.ReloadableStore)

Aggregations

SessionStorable (io.seata.server.store.SessionStorable)2 LogOperation (io.seata.server.store.TransactionStoreManager.LogOperation)2 TransactionException (io.seata.core.exception.TransactionException)1 BranchStatus (io.seata.core.model.BranchStatus)1 GlobalStatus (io.seata.core.model.GlobalStatus)1 BranchSession (io.seata.server.session.BranchSession)1 GlobalSession (io.seata.server.session.GlobalSession)1 SessionCondition (io.seata.server.session.SessionCondition)1 SessionManager (io.seata.server.session.SessionManager)1 ReloadableStore (io.seata.server.storage.file.ReloadableStore)1 TransactionWriteStore (io.seata.server.storage.file.TransactionWriteStore)1 FileTransactionStoreManager (io.seata.server.storage.file.store.FileTransactionStoreManager)1 TransactionStoreManager (io.seata.server.store.TransactionStoreManager)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1