Search in sources :

Example 6 with TransactionInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo in project openmq by eclipse-ee4j.

the class TidList method updateClusterTransaction.

/**
 * Update transaction's participant brokers.
 *
 * @param id the id of the transaction to be updated
 * @param brokers the transaction's participant brokers
 * @exception BrokerException if the transaction is not found in the store
 */
public void updateClusterTransaction(TransactionUID id, TransactionBroker[] brokers, boolean sync) throws BrokerException {
    try {
        TransactionInfo txnInfo = (TransactionInfo) tidMap.get(id);
        if (txnInfo == null) {
            logger.log(Logger.ERROR, BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id);
            throw new BrokerException(br.getString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id), Status.NOT_FOUND);
        }
        txnInfo.setType(TransactionInfo.TXN_CLUSTER);
        txnInfo.setTransactionBrokers(brokers);
        tidMap.put(id, txnInfo);
        if (sync) {
            sync(id);
        }
    } catch (RuntimeException e) {
        logger.log(logger.ERROR, br.X_PERSIST_TRANSACTION_FAILED, id, e);
        throw new BrokerException(br.getString(br.X_PERSIST_TRANSACTION_FAILED, id), e);
    }
}
Also used : TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)

Example 7 with TransactionInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo in project openmq by eclipse-ee4j.

the class TidList method storeClusterTransaction.

/**
 * Store a cluster transaction.
 *
 * @param id the id of the transaction to be persisted
 * @param ts the transaction's state to be persisted
 * @param brokers the transaction's participant brokers
 * @exception BrokerException if an error occurs while persisting or the same transaction id exists the store already
 * @exception NullPointerException if <code>id</code> is <code>null</code>
 */
public void storeClusterTransaction(TransactionUID id, TransactionState ts, TransactionBroker[] brokers, boolean sync) throws BrokerException {
    TransactionInfo txnInfo = null;
    try {
        // TransactionState is mutable, so we must store a copy
        // See bug 4989708
        txnInfo = new TransactionInfo(new TransactionState(ts), null, brokers, TransactionInfo.TXN_CLUSTER);
        Object oldValue = tidMap.putIfAbsent(id, txnInfo);
        if (oldValue != null) {
            logger.log(Logger.ERROR, BrokerResources.E_TRANSACTIONID_EXISTS_IN_STORE, id);
            throw new BrokerException(br.getString(BrokerResources.E_TRANSACTIONID_EXISTS_IN_STORE, id));
        }
        if (sync) {
            sync(id);
        }
    } catch (RuntimeException e) {
        String msg = (txnInfo != null) ? id + " " + txnInfo : id.toString();
        logger.log(Logger.ERROR, BrokerResources.X_PERSIST_TRANSACTION_FAILED, msg, e);
        throw new BrokerException(br.getString(BrokerResources.X_PERSIST_TRANSACTION_FAILED, msg), e);
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo) SizeString(com.sun.messaging.jmq.util.SizeString)

Example 8 with TransactionInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo in project openmq by eclipse-ee4j.

the class TransactionList method loadTransactions.

public void loadTransactions() throws BrokerException, IOException {
    // before we do anything else, make sure we dont have any
    // unexpected exceptions
    // FIRST ... look at transaction table (tid,state)
    LoadException load_ex = pstore.getLoadTransactionException();
    if (load_ex != null) {
        // some messages could not be loaded
        LoadException processing = load_ex;
        while (processing != null) {
            TransactionUID tid = (TransactionUID) processing.getKey();
            TransactionInfo ti = (TransactionInfo) processing.getValue();
            if (tid == null && ti == null) {
                logger.log(Logger.WARNING, "LoadTransactionException: " + "Both key and value for a transactions entry" + " are corrupted with key exception " + processing.getKeyCause().getMessage() + " and value exception " + processing.getValueCause());
                processing = processing.getNextException();
                continue;
            }
            if (tid == null) {
                // at this point, there is nothing we can do ...
                // store with valid key
                // improve when we address 5060661
                logger.logStack(Logger.WARNING, BrokerResources.W_TRANS_ID_CORRUPT, ti.toString(), processing.getKeyCause());
                processing = processing.getNextException();
                continue;
            }
            if (ti == null) {
                // if we dont know ... so make it prepared
                logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_TRAN_INFO_CORRUPTED, tid.toString()));
                TransactionState ts = new TransactionState(AutoRollbackType.NOT_PREPARED, 0, true);
                ts.setState(TransactionState.PREPARED);
                try {
                    pstore.storeTransaction(tid, ts, false);
                } catch (Exception ex) {
                    logger.logStack(Logger.WARNING, "Error updating transaction " + tid, ex);
                }
                processing = processing.getNextException();
                continue;
            }
            if (ti.getType() == TransactionInfo.TXN_NOFLAG) {
                logger.logStack(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_TXN_TYPE_CORRUPTED, tid + "[" + ti.toString() + "]", TransactionInfo.toString(TransactionInfo.TXN_LOCAL)), processing.getValueCause());
                TransactionState ts = new TransactionState(AutoRollbackType.NOT_PREPARED, 0, true);
                ts.setState(TransactionState.PREPARED);
                try {
                    pstore.storeTransaction(tid, ts, false);
                } catch (Exception ex) {
                    logger.logStack(Logger.WARNING, "Error updating transaction " + tid, ex);
                }
                processing = processing.getNextException();
                continue;
            }
            if (ti.getTransactionState() == null) {
                logger.log(Logger.WARNING, BrokerResources.W_TRANS_STATE_CORRUPT, tid, processing.getValueCause());
                TransactionState ts = new TransactionState(AutoRollbackType.NOT_PREPARED, 0, true);
                ts.setState(TransactionState.PREPARED);
                try {
                    pstore.storeTransaction(tid, ts, false);
                } catch (Exception ex) {
                    logger.logStack(Logger.WARNING, "Error updating transaction " + tid, ex);
                }
                processing = processing.getNextException();
                continue;
            }
            if (ti.getType() == TransactionInfo.TXN_CLUSTER && ti.getTransactionBrokers() == null) {
                logger.log(Logger.WARNING, BrokerResources.W_CLUSTER_TXN_BROKER_INFO_CORRUPTED, tid, processing.getValueCause());
                pstore.storeClusterTransaction(tid, ti.getTransactionState(), null, false);
                processing = processing.getNextException();
                continue;
            }
            if (ti.getType() == TransactionInfo.TXN_REMOTE && ti.getTransactionHomeBroker() == null) {
                logger.log(Logger.WARNING, BrokerResources.W_REMOTE_TXN_HOME_BROKER_INFO_CORRUPTED, tid, processing.getValueCause());
                pstore.storeRemoteTransaction(tid, ti.getTransactionState(), null, null, false);
                processing = processing.getNextException();
                continue;
            }
            logger.log(Logger.ERROR, "XXXI18N Internal Error: unknown load error for TUID=" + tid + "[" + ti.toString() + "]");
        }
    // end while
    }
    // now look at acks load exception
    load_ex = pstore.getLoadTransactionAckException();
    if (load_ex != null) {
        // some messages could not be loaded
        LoadException processing = load_ex;
        while (processing != null) {
            TransactionUID tid = (TransactionUID) processing.getKey();
            TransactionAcknowledgement[] ta = (TransactionAcknowledgement[]) processing.getValue();
            if (tid == null && ta == null) {
                logger.log(Logger.WARNING, "LoadTransactionAckException: " + "both key and value for a Transaction Ack entry" + " are corrupted");
                processing = processing.getNextException();
                continue;
            }
            if (tid == null) {
                // at this point, there is nothing we can do ...
                // store with valid key
                // improve when we address 5060661
                logger.log(Logger.WARNING, BrokerResources.W_TRANS_ID_CORRUPT, Arrays.toString(ta));
                processing = processing.getNextException();
                continue;
            }
            // ta == null, nothing we can do, remove it
            logger.log(Logger.WARNING, BrokerResources.W_TRANS_ACK_CORRUPT, tid.toString());
            try {
                pstore.removeTransactionAck(tid, false);
            } catch (Exception ex) {
                logger.logStack(Logger.WARNING, "Error updating transaction acks " + tid, ex);
            }
        }
    // end while
    }
    logger.log(Logger.INFO, br.getKString(br.I_PROCESSING_TRANS) + logsuffix);
    // OK -> first load the list of pending
    // transactions
    HashMap trans = pstore.getAllTransactionStates();
    // Write some info about the transactions to the log file
    // for informational purposes.
    logTransactionInfo(trans, AUTO_ROLLBACK, logsuffix);
    // list of transactions which need to be cleaned up
    HashSet clearTrans = new HashSet(trans.size());
    HashSet clearAckOnlyTrans = new HashSet(trans.size());
    HashMap openTransactions = new HashMap();
    HashMap inprocessAcks = new HashMap();
    HashMap committingTransactions = new HashMap();
    // loop through the list of transactions
    // placing each on the various lists
    int prepareCN = 0, commitWaitCN = 0;
    Iterator itr = trans.entrySet().iterator();
    while (itr.hasNext()) {
        try {
            Map.Entry entry = (Map.Entry) itr.next();
            TransactionUID tid = (TransactionUID) entry.getKey();
            TransactionInfo tif = (TransactionInfo) entry.getValue();
            TransactionState ts = tif.getTransactionState();
            TransactionAcknowledgement[] ta = pstore.getTransactionAcks(tid);
            if (ta == null) {
                ta = new TransactionAcknowledgement[0];
            }
            int state = ts.getState();
            if (DEBUG) {
                logger.log(Logger.INFO, "Load transaction: TUID=" + tid + "[" + TransactionState.toString(state) + (ts.getCreationTime() == 0 ? "" : " createTime=" + ts.getCreationTime()) + "]");
            }
            switch(state) {
                // no longer valid, ignore
                case TransactionState.CREATED:
                    clearTrans.add(tid);
                    break;
                case TransactionState.PREPARED:
                    // if autorollback, fall through to rollback
                    if (!AUTO_ROLLBACK) {
                        // nothing happens w/ preparedTransactions
                        // they go back into the list
                        // We don't persist this because it is already
                        // in the store
                        addTransactionID(tid, ts, false);
                        if (tif.getType() == TransactionInfo.TXN_CLUSTER) {
                            logClusterTransaction(tid, ts, tif.getTransactionBrokers(), true, false);
                            prepareCN++;
                        }
                        openTransactions.put(tid, Boolean.TRUE);
                        if (ts.getOnephasePrepare()) {
                            addDetachedTransactionID(tid);
                        }
                        break;
                    }
                // rollback -> we didnt complete
                case TransactionState.STARTED:
                case TransactionState.COMPLETE:
                case TransactionState.ROLLEDBACK:
                case TransactionState.FAILED:
                case TransactionState.INCOMPLETE:
                    addTransactionID(tid, ts, false);
                    if (tif.getType() == TransactionInfo.TXN_CLUSTER) {
                        logClusterTransaction(tid, ts, tif.getTransactionBrokers(), true, false);
                    }
                    openTransactions.put(tid, Boolean.FALSE);
                    clearTrans.add(tid);
                    ts.setState(TransactionState.ROLLEDBACK);
                    if (state == TransactionState.PREPARED) {
                        clearAckOnlyTrans.add(tid);
                        try {
                            updateState(tid, TransactionState.ROLLEDBACK, true);
                        } catch (Exception e) {
                            logger.logStack(Logger.WARNING, "Unable to update auto-rollback PREPARED transaction " + tid + " state to ROLLEDBACK", e);
                        }
                    }
                    break;
                case TransactionState.COMMITTED:
                    committingTransactions.put(tid, "");
                    if (tif.getType() == TransactionInfo.TXN_CLUSTER) {
                        boolean completed = true;
                        TransactionBroker[] brokers = tif.getTransactionBrokers();
                        logClusterTransaction(tid, ts, brokers, false, false);
                        for (int i = 0; brokers != null && i < brokers.length; i++) {
                            completed = brokers[i].isCompleted();
                            if (!completed) {
                                if (DEBUG_CLUSTER_TXN) {
                                    logger.log(logger.INFO, "COMMITTED cluster transaction " + tid + ", incomplete broker:" + brokers[i]);
                                }
                                break;
                            }
                        }
                        if (!completed) {
                            commitWaitCN++;
                        }
                    } else {
                        addTransactionID(tid, ts, false);
                    }
                    clearTrans.add(tid);
                    break;
                default:
                    logger.log(logger.ERROR, "Internal Error unexpected transaction state:" + TransactionState.toString(state) + " TUID=" + tid + ", set to PREPARE");
                    addTransactionID(tid, ts, false);
                    if (tif.getType() == TransactionInfo.TXN_CLUSTER) {
                        logClusterTransaction(tid, ts, tif.getTransactionBrokers(), true, false);
                    }
                    updateState(tid, TransactionState.PREPARED, true);
                    openTransactions.put(tid, Boolean.TRUE);
            }
            for (int i = 0; i < ta.length; i++) {
                if (DEBUG) {
                    logger.log(Logger.INFO, "Load transaction ack " + ta[i] + " [TUID=" + tid + "]");
                }
                ConsumerUID cuid = ta[i].getConsumerUID();
                ConsumerUID scuid = ta[i].getStoredConsumerUID();
                SysMessageID sysid = ta[i].getSysMessageID();
                Map imap = (Map) inprocessAcks.get(sysid);
                if (scuid == null) {
                    logger.log(Logger.WARNING, "Internal Error: " + " Unable to locate stored ConsumerUID :" + Arrays.toString(ta));
                    scuid = cuid;
                }
                if (imap == null) {
                    imap = new HashMap();
                    inprocessAcks.put(sysid, imap);
                }
                imap.put(scuid, tid);
                if (openTransactions.get(tid) != null) {
                    TransactionInformation ti = (TransactionInformation) translist.get(tid);
                    if (ti == null) {
                        logger.log(Logger.INFO, "Unable to retrieve " + " transaction information " + ti + " for " + tid + " we may be clearing the transaction");
                        continue;
                    }
                    if (openTransactions.get(tid) == Boolean.TRUE) {
                        ti.addConsumedMessage(sysid, cuid, scuid);
                    }
                    ti.addOrphanAck(sysid, scuid);
                }
            }
        } catch (Exception ex) {
            logger.logStack(Logger.WARNING, BrokerResources.E_INTERNAL_BROKER_ERROR, "Error parsing transaction ", ex);
        }
    }
    {
        Object[] args = { Integer.valueOf(prepareCN), Integer.valueOf(commitWaitCN) };
        logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_NCLUSTER_TRANS, args));
    }
    HashMap remoteTrans = pstore.getAllRemoteTransactionStates();
    // list of transactions which need to be cleaned up
    HashSet clearRemoteTrans = new HashSet(remoteTrans.size());
    int prepareRN = 0, commitRN = 0, completeRN = 0;
    itr = remoteTrans.entrySet().iterator();
    while (itr.hasNext()) {
        try {
            Map.Entry entry = (Map.Entry) itr.next();
            TransactionUID tid = (TransactionUID) entry.getKey();
            TransactionState ts = (TransactionState) entry.getValue();
            TransactionAcknowledgement[] ta = pstore.getTransactionAcks(tid);
            int state = ts.getState();
            if (DEBUG) {
                logger.log(Logger.INFO, "Load remote transaction: TUID=" + tid + "[" + TransactionState.toString(state) + (ts.getCreationTime() == 0 ? "" : " createTime=" + ts.getCreationTime()) + "]");
            }
            switch(state) {
                case TransactionState.CREATED:
                    clearRemoteTrans.add(tid);
                    break;
                case TransactionState.PREPARED:
                    prepareRN++;
                    logRemoteTransaction(tid, ts, ta, pstore.getRemoteTransactionHomeBroker(tid), true, true, false);
                    openTransactions.put(tid, Boolean.TRUE);
                    break;
                case TransactionState.COMPLETE:
                    if (Globals.getHAEnabled() && ta != null && ta.length > 0) {
                        completeRN++;
                        ts.setState(TransactionState.PREPARED);
                        logRemoteTransaction(tid, ts, ta, pstore.getRemoteTransactionHomeBroker(tid), true, true, false);
                        openTransactions.put(tid, Boolean.TRUE);
                        break;
                    }
                case TransactionState.STARTED:
                case TransactionState.ROLLEDBACK:
                case TransactionState.FAILED:
                case TransactionState.INCOMPLETE:
                    openTransactions.put(tid, Boolean.FALSE);
                    clearRemoteTrans.add(tid);
                    break;
                case TransactionState.COMMITTED:
                    commitRN++;
                    logRemoteTransaction(tid, ts, ta, pstore.getRemoteTransactionHomeBroker(tid), true, true, false);
                    committingTransactions.put(tid, "");
                    break;
                default:
                    logger.log(logger.ERROR, "Internal Error unexpected transaction state:" + TransactionState.toString(state) + " TUID=" + tid + ", set to PREPARED");
                    logRemoteTransaction(tid, ts, ta, pstore.getRemoteTransactionHomeBroker(tid), true, true, false);
                    updateRemoteTransactionState(tid, TransactionState.PREPARED, true, true, true);
                    openTransactions.put(tid, Boolean.TRUE);
            }
            for (int i = 0; i < ta.length; i++) {
                if (DEBUG) {
                    logger.log(Logger.INFO, "Load remote transaction ack " + ta[i] + " [TUID=" + tid + "]");
                }
                ConsumerUID cuid = ta[i].getConsumerUID();
                ConsumerUID scuid = ta[i].getStoredConsumerUID();
                SysMessageID sysid = ta[i].getSysMessageID();
                Map imap = (Map) inprocessAcks.get(sysid);
                if (scuid == null) {
                    logger.log(Logger.WARNING, "Internal Error: " + " Unable to locate stored ConsumerUID :" + Arrays.toString(ta));
                    scuid = cuid;
                }
                if (imap == null) {
                    imap = new HashMap();
                    inprocessAcks.put(sysid, imap);
                }
                imap.put(scuid, tid);
            }
        } catch (Exception ex) {
            logger.logStack(Logger.WARNING, BrokerResources.E_INTERNAL_BROKER_ERROR, "Error parsing remote transaction ", ex);
        }
    }
    if (Globals.getHAEnabled()) {
        Object[] args = { String.valueOf(remoteTrans.size()), String.valueOf(prepareRN), String.valueOf(completeRN), String.valueOf(commitRN) };
        logger.log(logger.INFO, Globals.getBrokerResources().getString(BrokerResources.I_NREMOTE_TRANS_HA, args));
    } else {
        Object[] args = { String.valueOf(remoteTrans.size()), String.valueOf(prepareRN), String.valueOf(commitRN) };
        logger.log(logger.INFO, Globals.getBrokerResources().getString(BrokerResources.I_NREMOTE_TRANS, args));
    }
    // load the database now and fix it
    if (openTransactions.size() > 0 || inprocessAcks.size() > 0) {
        LinkedHashMap m = DL.processTransactions(inprocessAcks, openTransactions, committingTransactions);
        if (m != null && !m.isEmpty()) {
            Iterator meitr = m.entrySet().iterator();
            while (meitr.hasNext()) {
                Map.Entry me = (Map.Entry) meitr.next();
                TransactionInformation ti = (TransactionInformation) translist.get(me.getValue());
                ti.addPublishedMessage((SysMessageID) me.getKey());
            }
        }
    }
    // OK -> now clean up the cleared transactions
    // this removes them from the disk
    itr = clearTrans.iterator();
    while (itr.hasNext()) {
        TransactionUID tid = (TransactionUID) itr.next();
        logger.log(Logger.DEBUG, "Clearing transaction " + tid);
        if (!clearAckOnlyTrans.contains(tid)) {
            removeTransactionAck(tid);
            removeTransactionID(tid);
        } else {
            removeTransactionAck(tid, true);
        }
    }
    itr = clearRemoteTrans.iterator();
    while (itr.hasNext()) {
        TransactionUID tid = (TransactionUID) itr.next();
        try {
            logger.log(Logger.DEBUG, "Clearing remote transaction " + tid);
            removeRemoteTransactionAck(tid);
            removeRemoteTransactionID(tid, true);
        } catch (Exception e) {
            logger.log(logger.WARNING, "Failed to remove remote transaction TUID=" + tid + ": " + e.getMessage());
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IOException(java.io.IOException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) LinkedHashMap(java.util.LinkedHashMap) Iterator(java.util.Iterator) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with TransactionInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo in project openmq by eclipse-ee4j.

the class TransactionList method loadTakeoverTxns.

// returns transaction acks
public Map loadTakeoverTxns(List txns, List remoteTxns, Map<String, String> msgs) throws BrokerException, IOException {
    logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_PROCESSING_TAKEOVER_TRANS, Integer.valueOf(txns.size())));
    // hey process through the states
    Iterator itr = txns.iterator();
    Map acks = new HashMap();
    while (itr.hasNext()) {
        TransactionUID tid = (TransactionUID) itr.next();
        TransactionInfo ti = null;
        try {
            ti = pstore.getTransactionInfo(tid);
        } catch (Exception e) {
            String em = "Failed to get transaction " + tid + " information from store after takeover";
            logger.logStack(logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, em, e);
            throw new BrokerException(em);
        }
        TransactionState ts = ti.getTransactionState();
        logger.log(Logger.DEBUG, "Processing transaction " + tid + ti.toString());
        try {
            if (ts.getState() != TransactionState.COMMITTED && ts.getState() != TransactionState.PREPARED) {
                pstore.removeTransactionAck(tid, false);
            }
            TransactionAcknowledgement[] ta = pstore.getTransactionAcks(tid);
            logger.log(Logger.DEBUG, "Processing transaction acks " + tid + " number=" + ta.length);
            List l = Arrays.asList(ta);
            acks.put(tid, l);
            addTransactionID(tid, ts, true, ti.getType(), false);
            if (ti.getType() == TransactionInfo.TXN_CLUSTER) {
                logClusterTransaction(tid, ts, ti.getTransactionBrokers(), true, false);
            }
            if (ts.getState() == TransactionState.PREPARED && ts.getOnephasePrepare()) {
                addDetachedTransactionID(tid);
            }
        } catch (Exception ex) {
            logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "error taking over " + tid, ex);
            acks.remove(tid);
        }
    }
    itr = remoteTxns.iterator();
    while (itr.hasNext()) {
        TransactionUID tid = (TransactionUID) itr.next();
        if (txns.contains(tid)) {
            continue;
        }
        TransactionInfo ti = null;
        try {
            ti = pstore.getTransactionInfo(tid);
        } catch (Exception e) {
            String em = "Failed to get remote transaction " + tid + " information from store after takeover";
            logger.logStack(logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, em, e);
            throw new BrokerException(em);
        }
        TransactionState ts = ti.getTransactionState();
        if (DEBUG || DEBUG_CLUSTER_TXN) {
            logger.log(Logger.INFO, Globals.getBrokerResources().getString(BrokerResources.I_PROCESSING_REMOTE_TXN, tid + "[" + TransactionState.toString(ts.getState()) + "]" + ti.toString()));
        } else {
            logger.log(Logger.INFO, Globals.getBrokerResources().getString(BrokerResources.I_PROCESSING_REMOTE_TXN, tid + "[" + TransactionState.toString(ts.getState()) + "]"));
        }
        try {
            TransactionAcknowledgement[] ta = pstore.getTransactionAcks(tid);
            ArrayList l = new ArrayList();
            Iterator mitr = null;
            for (int i = 0; i < ta.length; i++) {
                mitr = msgs.keySet().iterator();
                while (mitr.hasNext()) {
                    String msgID = (String) mitr.next();
                    if (msgID.equals(ta[i].getSysMessageID().toString())) {
                        l.add(ta[i]);
                        if (DEBUG || DEBUG_CLUSTER_TXN) {
                            logger.log(Logger.INFO, "Processing remote transaction ack for TUID=" + tid + " " + ta[i].toString());
                        }
                    }
                }
            }
            if ((l.size() > 0)) {
                acks.put(tid, l);
                logger.log(Logger.INFO, "Processing remote transaction " + tid + "[" + TransactionState.toString(ts.getState()) + "] with acks " + l.size());
                if (ts.getState() != TransactionState.PREPARED && ts.getState() != TransactionState.COMMITTED) {
                    ts.setState(TransactionState.PREPARED);
                }
            }
            logRemoteTransaction(tid, ts, (TransactionAcknowledgement[]) l.toArray(new TransactionAcknowledgement[l.size()]), ti.getTransactionHomeBroker(), true, false, false);
            if (ts.getState() == TransactionState.COMMITTED) {
                txnReaper.addRemoteTransaction(tid, true);
            }
        } catch (Exception ex) {
            logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "error taking over " + tid, ex);
            acks.remove(tid);
        }
    }
    return acks;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Iterator(java.util.Iterator) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with TransactionInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo in project openmq by eclipse-ee4j.

the class TransactionList method logTransactionInfo.

public static void logTransactionInfo(HashMap transactions, boolean autorollback, String logsuffix) {
    Logger logger = Globals.getLogger();
    BrokerResources br = Globals.getBrokerResources();
    /*
         * Loop through all transactions and count how many are in what state. This is done strictly for informational purposes.
         */
    // Number of transactions rolledback
    int nRolledBack = 0;
    // Number of prepared transactions
    int nPrepared = 0;
    // Number of committed transactions
    int nCommitted = 0;
    if (transactions != null && transactions.size() > 0) {
        Iterator itr = transactions.values().iterator();
        while (itr.hasNext()) {
            TransactionState _ts = ((TransactionInfo) itr.next()).getTransactionState();
            if (_ts.getState() == TransactionState.PREPARED) {
                nPrepared++;
                if (autorollback) {
                    nRolledBack++;
                }
            } else if (_ts.getState() != TransactionState.COMMITTED) {
                nRolledBack++;
            } else {
                nCommitted++;
            }
        }
        logger.log(Logger.INFO, br.getKString(br.I_NTRANS, Integer.valueOf(transactions.size()), Integer.valueOf(nRolledBack)) + logsuffix);
        Object[] args = { Integer.valueOf(transactions.size()), Integer.valueOf(nPrepared), Integer.valueOf(nCommitted) };
        logger.log(Logger.INFO, br.getKString(br.I_NPREPARED_TRANS, args) + logsuffix);
        if (nPrepared > 0) {
            if (autorollback) {
                logger.log(Logger.INFO, br.getKString(br.I_PREPARED_ROLLBACK) + logsuffix);
            } else {
                logger.log(Logger.INFO, br.getKString(br.I_PREPARED_NOROLLBACK) + logsuffix);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo) Logger(com.sun.messaging.jmq.util.log.Logger) BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources)

Aggregations

TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)17 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)8 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)6 PHashMapLoadException (com.sun.messaging.jmq.io.disk.PHashMapLoadException)5 PHashMap (com.sun.messaging.jmq.io.disk.PHashMap)4 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)4 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)4 IOException (java.io.IOException)4 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)3 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)3 Iterator (java.util.Iterator)3 JMSBridgeStore (com.sun.messaging.bridge.api.JMSBridgeStore)2 Packet (com.sun.messaging.jmq.io.Packet)2 PHashMapMMF (com.sun.messaging.jmq.io.disk.PHashMapMMF)2 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)2 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)2 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)2 ChangeRecordInfo (com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)2 HABrokerInfo (com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo)2