Search in sources :

Example 11 with BaseTransaction

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

the class TransactionWorkInfo method getMessage.

/**
 * Return the message. The message is only cached when it is loaded from the backing buffer the first time. It will be
 * set to null after it is retrieved. From then on, we always read it from the backing buffer again.
 */
synchronized BaseTransaction getMessage() throws IOException {
    if (msg == null) {
        if (vrecord != null) {
            // read from backing buffer
            try {
                return parseTransactionWork(vrecord);
            } catch (IOException e) {
                logger.log(logger.ERROR, parent.storeName + ":failed to parse message from vrecord(" + vrecord + ")", e);
                throw e;
            }
        } else {
            try {
                byte[] data = parent.loadData(tid);
                return parseTransactionWork(data);
            } catch (IOException e) {
                logger.log(logger.ERROR, parent.storeName + ":failed to parse message from byte array", e);
                throw e;
            }
        }
    } else {
        BaseTransaction pkt = msg;
        msg = null;
        return pkt;
    }
}
Also used : BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) IOException(java.io.IOException)

Example 12 with BaseTransaction

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

the class ClusterTransactionManager method replayTransactionEvent.

@Override
void replayTransactionEvent(TransactionEvent txnEvent, HashSet dstLoadedSet) throws BrokerException, IOException {
    if (Store.getDEBUG()) {
        Globals.getLogger().log(Logger.DEBUG, getPrefix() + " replayTransactionEvent");
    }
    ClusterTransactionEvent clusterTxnEvent = (ClusterTransactionEvent) txnEvent;
    // replay to store on commit
    ClusterTransaction clusterTxn = clusterTxnEvent.clusterTransaction;
    int state = clusterTxn.getState();
    TransactionUID tid = clusterTxn.getTid();
    if (clusterTxnEvent.getSubType() == ClusterTransactionEvent.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 " + clusterTxn;
                Globals.getLogger().log(Logger.DEBUG, msg);
            }
        } else {
            addToIncompleteUnstored(clusterTxn);
        }
    } else if (clusterTxnEvent.getSubType() == ClusterTransactionEvent.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)
            if (state == TransactionState.ROLLEDBACK) {
                existingWork = removeFromIncompleteUnstored(tid);
            } else if (state == TransactionState.COMMITTED) {
                existingWork = incompleteUnstored.get(tid);
                existingWork.getTransactionDetails().setState(state);
                existingWork.getTransactionState().setState(state);
            }
        } 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) {
            if (state == TransactionState.COMMITTED) {
                transactionLogManager.transactionLogReplayer.replayTransactionWork(existingWork.getTransactionWork(), tid, dstLoadedSet);
            }
        } else {
            logger.log(Logger.ERROR, "Could not find prepared work for completing two-phase transaction " + clusterTxn.getTid());
        }
    }
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) ClusterTransaction(com.sun.messaging.jmq.jmsserver.data.ClusterTransaction)

Example 13 with BaseTransaction

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

the class LocalTransactionManager method replayTransactionEvent.

@Override
void replayTransactionEvent(TransactionEvent txnEvent, HashSet dstLoadedSet) throws BrokerException, IOException {
    if (Store.getDEBUG()) {
        Globals.getLogger().log(Logger.DEBUG, getPrefix() + " replayTransactionEvent");
    }
    LocalTransactionEvent localTxnEvent = (LocalTransactionEvent) txnEvent;
    // replay to store on commit
    LocalTransaction localTxn = localTxnEvent.localTransaction;
    int state = localTxn.getState();
    TransactionUID tid = localTxn.getTid();
    if (localTxnEvent.getSubType() == LocalTransactionEvent.Type1PCommitEvent) {
        // one phase commit
        // Just replay it now
        transactionLogManager.transactionLogReplayer.replayTransactionWork(localTxn.getTransactionWork(), tid, dstLoadedSet);
    } else if (localTxnEvent.getSubType() == LocalTransactionEvent.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 " + localTxn;
                Globals.getLogger().log(Logger.DEBUG, msg);
            }
        } else {
            addToIncompleteUnstored(localTxn);
        }
    } else if (localTxnEvent.getSubType() == LocalTransactionEvent.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) {
            if (state == TransactionState.COMMITTED) {
                transactionLogManager.transactionLogReplayer.replayTransactionWork(existingWork.getTransactionWork(), tid, dstLoadedSet);
            }
        } else {
            logger.log(Logger.ERROR, "Could not find prepared work for completing two-phase transaction " + localTxn.getTid());
        }
    }
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) LocalTransaction(com.sun.messaging.jmq.jmsserver.data.LocalTransaction) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction)

Example 14 with BaseTransaction

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

the class BaseTransactionManager method getAllTransactionsMap.

public HashMap getAllTransactionsMap() {
    List<BaseTransaction> txns = getAllIncompleteTransactions();
    HashMap map = new HashMap(txns.size());
    Iterator<BaseTransaction> itr = txns.iterator();
    while (itr.hasNext()) {
        BaseTransaction txn = itr.next();
        TransactionState txnState = new TransactionState(txn.getTransactionState());
        map.put(txn.getTid(), txnState);
    }
    return map;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) HashMap(java.util.HashMap) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction)

Example 15 with BaseTransaction

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

the class BaseTransactionManager method processTxnCompletion.

BaseTransaction processTxnCompletion(TransactionUID tid, int state, boolean fullyComplete) throws IOException, BrokerException {
    // If it is mark it as committed, so that it can be cleaned up after next checkpoint
    if (state == TransactionState.COMMITTED) {
        this.playingToMessageStore.add(tid);
        if (Store.getDEBUG()) {
            String msg = getPrefix() + " add transaction to  playingToMessageStore." + " tid=" + tid + " size = " + playingToMessageStore.size();
            logger.log(Logger.DEBUG, msg);
        }
    }
    BaseTransaction existingTxn = null;
    boolean stored = false;
    existingTxn = incompleteUnstored.get(tid);
    if (existingTxn == null) {
        existingTxn = incompleteStored.get(tid);
        if (existingTxn != null) {
            stored = true;
        } else {
            String msg = getPrefix() + " processTxnCompletion: Could not find txn for " + tid;
            logger.log(Logger.WARNING, msg);
            throw new BrokerException(msg);
        }
    }
    existingTxn.getTransactionDetails().setState(state);
    if (stored) {
        // update the stored transaction from prepared to committed/rolledback state
        // update state on file by writing at fixed offset
        updateStoredState(tid, state);
        if (fullyComplete) {
            incompleteStored.remove(tid);
            completeStored.put(tid, existingTxn);
        }
    } else {
        if (fullyComplete) {
            removeFromIncompleteUnstored(tid);
        }
    }
    messageListLogged(existingTxn);
    return existingTxn;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction)

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