Search in sources :

Example 1 with BaseTransaction

use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.

the class RemoteTransactionManager method replayTransactionEvent.

@Override
void replayTransactionEvent(TransactionEvent txnEvent, HashSet dstLoadedSet) throws BrokerException, IOException {
    if (Store.getDEBUG()) {
        Globals.getLogger().log(Logger.DEBUG, getPrefix() + " replayTransactionEvent");
    }
    RemoteTransactionEvent remoteTxnEvent = (RemoteTransactionEvent) txnEvent;
    // replay to store on commit
    RemoteTransaction remoteTxn = remoteTxnEvent.remoteTransaction;
    int state = remoteTxn.getState();
    TransactionUID tid = remoteTxn.getTid();
    if (remoteTxnEvent.getSubType() == RemoteTransactionEvent.Type2PPrepareEvent) {
        // in prepared txn store and resetting the transaction log
        if (incompleteStored.containsKey(tid)) {
            if (Store.getDEBUG()) {
                String msg = getPrefix() + " found matching txn in prepared store on replay " + remoteTxn;
                Globals.getLogger().log(Logger.DEBUG, msg);
            }
        } else {
            addToIncompleteUnstored(remoteTxn);
        }
    } else if (remoteTxnEvent.getSubType() == RemoteTransactionEvent.Type2PCompleteEvent) {
        // we are completing a transaction
        // the transaction could be
        // a) unstored (prepare replayed earlier)
        // b) stored incomplete (prepare occurred before last checkpoint,
        // completion not written to prepared store yet)
        // This should therefore be the last entry in log.
        // c) stored complete (prepare occurred before last checkpoint,
        // and failure occurred after completion stored in prepared store
        BaseTransaction existingWork = null;
        if (incompleteUnstored.containsKey(tid)) {
            // a) unstored (prepare replayed earlier)
            existingWork = removeFromIncompleteUnstored(tid);
        } else if (incompleteStored.containsKey(tid)) {
            // b) stored incomplete (prepare occurred before last checkpoint,
            // completion not written to prepared store yet)
            existingWork = removeFromIncompleteStored(tid);
            updateStoredState(tid, state);
            addToCompleteStored(existingWork);
        } else if (completeStored.containsKey(tid)) {
            // c) stored complete (prepare occurred before last checkpoint,
            // and failure occurred after completion stored in prepared store
            existingWork = completeStored.get(tid);
        }
        if (existingWork != null) {
            RemoteTransaction remoteTransaction = (RemoteTransaction) existingWork;
            if (state == TransactionState.COMMITTED) {
                TransactionAcknowledgement[] txnAcks = remoteTransaction.getTxnAcks();
                DestinationUID[] destIds = remoteTransaction.getDestIds();
                transactionLogManager.transactionLogReplayer.replayRemoteAcks(txnAcks, destIds, tid, dstLoadedSet);
            }
        } else {
            logger.log(Logger.ERROR, "Could not find prepared work for completing two-phase transaction " + remoteTxn.getTid());
        }
    }
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) RemoteTransaction(com.sun.messaging.jmq.jmsserver.data.RemoteTransaction) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction)

Example 2 with BaseTransaction

use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.

the class FromTxnLogConverter method convert.

void convert(BaseTransactionManager baseTxnManager, TxnConverter converter) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, getPrefix() + " converting trxns from TxnManager");
    }
    List<BaseTransaction> list = baseTxnManager.getAllIncompleteTransactions();
    Iterator<BaseTransaction> iter = list.iterator();
    while (iter.hasNext()) {
        BaseTransaction baseTxn = iter.next();
        try {
            converter.convert(baseTxn);
        } catch (BrokerException be) {
            logger.logStack(Logger.ERROR, be.getMessage(), be);
        } catch (IOException ie) {
            logger.logStack(Logger.ERROR, ie.getMessage(), ie);
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) IOException(java.io.IOException)

Example 3 with BaseTransaction

use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.

the class BaseTransactionManager method removeFromIncompleteStored.

BaseTransaction removeFromIncompleteStored(TransactionUID tid) {
    BaseTransaction result = incompleteStored.remove(tid);
    if (Store.getDEBUG()) {
        String msg = getPrefix() + " removing  " + tid + " from incompleteStored. Total = " + incompleteStored.size();
        logger.log(Logger.DEBUG, msg);
    }
    return result;
}
Also used : BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction)

Example 4 with BaseTransaction

use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.

the class TransactionWorkInfo method parseTransactionWork.

private BaseTransaction parseTransactionWork(VRecordRAF r) throws IOException {
    try {
        r.rewind();
        txnDataSize = r.readInt();
        byte[] data = new byte[txnDataSize];
        r.read(data);
        BaseTransaction txnWork = TransactionWorkFactory.readFromBytes(data);
        return txnWork;
    } catch (Throwable t) {
        logger.log(logger.ERROR, parent.storeName + ":failed to parse message(size=" + txnDataSize + ") from vrecord(" + r + ")", t);
        IOException e = new IOException(t.toString());
        e.setStackTrace(t.getStackTrace());
        throw e;
    }
}
Also used : BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) IOException(java.io.IOException)

Example 5 with BaseTransaction

use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.

the class TransactionLogManager method removeCommittedTransactionsOnStartup.

void removeCommittedTransactionsOnStartup() throws BrokerException {
    if (Store.getDEBUG()) {
        String msg = getPrefix() + " removeCommitedTransactionsInPreparedTxnStore";
        logger.log(Logger.DEBUG, msg);
    }
    // for now just report on any transactions
    Enumeration<BaseTransaction> transactions = preparedTxnStore.txnEnumeration();
    List<BaseTransaction> committed = new ArrayList<>();
    while (transactions.hasMoreElements()) {
        BaseTransaction baseTxn = transactions.nextElement();
        if (baseTxn.getState() == TransactionState.COMMITTED) {
            if (baseTxn.getType() == BaseTransaction.CLUSTER_TRANSACTION_TYPE && !baseTxn.getTransactionDetails().isComplete()) {
                if (Store.getDEBUG()) {
                    String msg = getPrefix() + " not removing incomplete cluster transaction " + baseTxn.getTransactionDetails();
                    logger.log(Logger.DEBUG, msg);
                }
            } else {
                if (Store.getDEBUG()) {
                    String msg = getPrefix() + " removing transaction " + baseTxn.getTransactionDetails();
                    logger.log(Logger.DEBUG, msg);
                }
                committed.add(baseTxn);
            }
        }
    }
    Iterator<BaseTransaction> iter = committed.iterator();
    while (iter.hasNext()) {
        BaseTransaction baseTxn = iter.next();
        TransactionUID tid = baseTxn.getTid();
        preparedTxnStore.removeTransaction(tid, true);
        if (Store.getDEBUG()) {
            String msg = getPrefix() + " removed committed transaction from preparedTxnStore. Tid=" + tid;
            logger.log(Logger.DEBUG, msg);
        }
    }
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ArrayList(java.util.ArrayList) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) SizeString(com.sun.messaging.jmq.util.SizeString)

Aggregations

BaseTransaction (com.sun.messaging.jmq.jmsserver.data.BaseTransaction)17 IOException (java.io.IOException)8 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)6 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)5 LocalTransaction (com.sun.messaging.jmq.jmsserver.data.LocalTransaction)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)2 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)2 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)2 Agent (com.sun.messaging.jmq.jmsserver.management.agent.Agent)2 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)2 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)2 SizeString (com.sun.messaging.jmq.util.SizeString)2 List (java.util.List)2 Packet (com.sun.messaging.jmq.io.Packet)1 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)1 GlobalProperties (com.sun.messaging.jmq.jmsserver.GlobalProperties)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)1