Search in sources :

Example 6 with SessionCondition

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

the class FileTransactionStoreManager method findTimeoutAndSave.

private boolean findTimeoutAndSave() throws IOException {
    List<GlobalSession> globalSessionsOverMaxTimeout = sessionManager.findGlobalSessions(new SessionCondition(MAX_TRX_TIMEOUT_MILLS));
    if (CollectionUtils.isEmpty(globalSessionsOverMaxTimeout)) {
        return true;
    }
    for (GlobalSession globalSession : globalSessionsOverMaxTimeout) {
        TransactionWriteStore globalWriteStore = new TransactionWriteStore(globalSession, LogOperation.GLOBAL_ADD);
        byte[] data = globalWriteStore.encode();
        if (!writeDataFrame(data)) {
            return false;
        }
        List<BranchSession> branchSessIonsOverMaXTimeout = globalSession.getSortedBranches();
        if (branchSessIonsOverMaXTimeout != null) {
            for (BranchSession branchSession : branchSessIonsOverMaXTimeout) {
                try {
                    MDC.put(MDC_KEY_BRANCH_ID, String.valueOf(branchSession.getBranchId()));
                    TransactionWriteStore branchWriteStore = new TransactionWriteStore(branchSession, LogOperation.BRANCH_ADD);
                    data = branchWriteStore.encode();
                    if (!writeDataFrame(data)) {
                        return false;
                    }
                } finally {
                    MDC.remove(MDC_KEY_BRANCH_ID);
                }
            }
        }
    }
    if (flushWriteBuffer(writeBuffer)) {
        currFileChannel.force(false);
        return true;
    }
    return false;
}
Also used : TransactionWriteStore(io.seata.server.storage.file.TransactionWriteStore) GlobalSession(io.seata.server.session.GlobalSession) BranchSession(io.seata.server.session.BranchSession) SessionCondition(io.seata.server.session.SessionCondition)

Example 7 with SessionCondition

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

the class FileTransactionStoreManager method findTimeoutAndSave.

private boolean findTimeoutAndSave() throws IOException {
    List<GlobalSession> globalSessionsOverMaxTimeout = sessionManager.findGlobalSessions(new SessionCondition(MAX_TRX_TIMEOUT_MILLS));
    if (CollectionUtils.isEmpty(globalSessionsOverMaxTimeout)) {
        return true;
    }
    for (GlobalSession globalSession : globalSessionsOverMaxTimeout) {
        TransactionWriteStore globalWriteStore = new TransactionWriteStore(globalSession, LogOperation.GLOBAL_ADD);
        byte[] data = globalWriteStore.encode();
        if (!writeDataFrame(data)) {
            return false;
        }
        List<BranchSession> branchSessIonsOverMaXTimeout = globalSession.getSortedBranches();
        if (branchSessIonsOverMaXTimeout != null) {
            for (BranchSession branchSession : branchSessIonsOverMaXTimeout) {
                TransactionWriteStore branchWriteStore = new TransactionWriteStore(branchSession, LogOperation.BRANCH_ADD);
                data = branchWriteStore.encode();
                if (!writeDataFrame(data)) {
                    return false;
                }
            }
        }
    }
    if (flushWriteBuffer(writeBuffer)) {
        currFileChannel.force(false);
        return true;
    }
    return false;
}
Also used : TransactionWriteStore(io.seata.server.storage.file.TransactionWriteStore) GlobalSession(io.seata.server.session.GlobalSession) BranchSession(io.seata.server.session.BranchSession) SessionCondition(io.seata.server.session.SessionCondition)

Aggregations

BranchSession (io.seata.server.session.BranchSession)7 GlobalSession (io.seata.server.session.GlobalSession)7 SessionCondition (io.seata.server.session.SessionCondition)7 GlobalStatus (io.seata.core.model.GlobalStatus)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 TransactionException (io.seata.core.exception.TransactionException)2 BranchStatus (io.seata.core.model.BranchStatus)2 SessionManager (io.seata.server.session.SessionManager)2 TransactionWriteStore (io.seata.server.storage.file.TransactionWriteStore)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 SessionStorable (io.seata.server.store.SessionStorable)1 LogOperation (io.seata.server.store.TransactionStoreManager.LogOperation)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1