Search in sources :

Example 16 with TransactionState

use of com.sun.messaging.jmq.jmsserver.data.TransactionState 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 17 with TransactionState

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

the class TidList method loadClientDataOldFormat.

private void loadClientDataOldFormat() throws PHashMapLoadException {
    if (!updateOptimization) {
        // nothing to do
        return;
    }
    PHashMapLoadException loadException = null;
    Iterator itr = tidMap.entrySet().iterator();
    while (itr.hasNext()) {
        Throwable ex = null;
        Map.Entry entry = (Map.Entry) itr.next();
        Object key = entry.getKey();
        TransactionState value = (TransactionState) entry.getValue();
        byte[] cData = null;
        try {
            cData = ((PHashMapMMF) tidMap).getClientData(key);
            if (cData != null && cData.length > 0) {
                // 1st byte is the modified state
                int state = cData[0];
                // update txn state
                value.setState(state);
            }
        } catch (Throwable e) {
            ex = e;
        }
        if (ex != null) {
            PHashMapLoadException le = new PHashMapLoadException("Failed to load client data [cData=" + Arrays.toString(cData) + "]");
            le.setKey(key);
            le.setValue(value);
            le.setNextException(loadException);
            le.initCause(ex);
            loadException = le;
        }
    }
    if (loadException != null) {
        throw loadException;
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) PHashMapLoadException(com.sun.messaging.jmq.io.disk.PHashMapLoadException) PHashMap(com.sun.messaging.jmq.io.disk.PHashMap)

Example 18 with TransactionState

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

the class AckHandler method handleTransaction.

public void handleTransaction(TransactionList translist, IMQConnection con, TransactionUID tid, SysMessageID[] ids, ConsumerUID[] cids, int deliverCnt) throws BrokerException {
    for (int i = 0; i < ids.length; i++) {
        Consumer consumer = null;
        try {
            // lookup the session by consumerUID
            Session s = Session.getSession(cids[i]);
            // look up the consumer by consumerUID
            consumer = Consumer.getConsumer(cids[i]);
            if (consumer == null) {
                throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.I_ACK_FAILED_NO_CONSUMER, cids[i]) + "[TID=" + tid + "]", Status.NOT_FOUND);
            }
            // try and find the stored consumerUID
            ConsumerUID sid = consumer.getStoredConsumerUID();
            // if we still dont have a session, attempt to find one
            if (s == null) {
                SessionUID suid = consumer.getSessionUID();
                s = Session.getSession(suid);
            }
            if (s == null) {
                if (BrokerStateHandler.isShutdownStarted()) {
                    throw new BrokerException(BrokerResources.I_ACK_FAILED_BROKER_SHUTDOWN);
                }
                throw new BrokerException(br.getKString(br.I_ACK_FAILED_NO_SESSION, "[" + ids[i] + ", " + cids[i] + "]TID=" + tid));
            }
            if (DEBUG) {
                logger.log(logger.INFO, "handleTransaction.addAck[" + i + ", " + ids.length + "]:tid=" + tid + ", sysid=" + ids[i] + ", cid=" + cids[i] + ", sid=" + sid + " on connection " + con);
            }
            boolean isxa = translist.addAcknowledgement(tid, ids[i], cids[i], sid);
            BrokerAddress addr = (BrokerAddress) s.ackInTransaction(cids[i], ids[i], tid, isxa, deliverCnt);
            if (addr != null && addr != Globals.getMyAddress()) {
                translist.setAckBrokerAddress(tid, ids[i], cids[i], addr);
            }
            if (fi.FAULT_INJECTION) {
                if (fi.checkFault(fi.FAULT_TXN_ACK_1_5, null)) {
                    fi.unsetFault(fi.FAULT_TXN_ACK_1_5);
                    TransactionAckExistException tae = new TransactionAckExistException("FAULT:" + fi.FAULT_TXN_ACK_1_5, Status.GONE);
                    tae.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
                    tae.setRemote(true);
                    consumer.recreationRequested();
                    throw tae;
                }
            }
        } catch (Exception ex) {
            String emsg = "[" + ids[i] + ", " + cids[i] + "]TUID=" + tid;
            if ((ex instanceof BrokerException) && ((BrokerException) ex).getStatusCode() != Status.ERROR) {
                logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
            } else {
                logger.log(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
            }
            int state = -1;
            JMQXid xid = null;
            try {
                TransactionState ts = translist.retrieveState(tid);
                if (ts != null) {
                    state = ts.getState();
                    xid = ts.getXid();
                }
                translist.updateState(tid, TransactionState.FAILED, true);
            } catch (Exception e) {
                if (!(e instanceof UnknownTransactionException)) {
                    String[] args = { TransactionState.toString(state), TransactionState.toString(TransactionState.FAILED), tid.toString(), (xid == null ? "null" : xid.toString()) };
                    logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_UPDATE_TRAN_STATE_FAIL, args));
                }
            }
            if (ex instanceof TransactionAckExistException) {
                PacketReference ref = DL.get(null, ids[i]);
                if (ref != null && (ref.isOverrided() || ref.isOverriding())) {
                    ((BrokerException) ex).overrideStatusCode(Status.GONE);
                    ((BrokerException) ex).setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
                    ((BrokerException) ex).setRemote(true);
                    consumer.recreationRequested();
                }
            }
            if (ex instanceof BrokerException) {
                throw (BrokerException) ex;
            }
            throw new BrokerException("Internal Error: Unable to " + " complete processing acknowledgements in a tranaction: " + ex, ex);
        }
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) SessionUID(com.sun.messaging.jmq.jmsserver.core.SessionUID) JMQXid(com.sun.messaging.jmq.util.JMQXid) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionAckExistException(com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionAckExistException(com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 19 with TransactionState

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

the class QBrowseHandler method getQBrowseList.

public ArrayList getQBrowseList(Destination d, String selectorstr) throws BrokerException, SelectorFormatException {
    Collection msgs = null;
    if (selectorstr == null) {
        msgs = d.getAll((Filter) null).values();
    } else {
        SelectorFilter f = new SelectorFilter(selectorstr);
        Map m = d.getAll(f);
        msgs = m.values();
    }
    // sort the messages
    ArrayList sorted = new ArrayList(msgs);
    Collections.sort(sorted, new RefCompare());
    TransactionList[] tls = DL.getTransactionList(d.getPartitionedStore());
    TransactionList tlist = tls[0];
    // remove any expired messages or messages in open txn
    Iterator itr = sorted.iterator();
    while (itr.hasNext()) {
        PacketReference p = (PacketReference) itr.next();
        if (p.isExpired()) {
            itr.remove();
        }
        if (!p.isDeliveryDue()) {
            itr.remove();
        }
        if (p.getTransactionID() != null) {
            // look up txn
            TransactionState ts = tlist.retrieveState(p.getTransactionID());
            if (ts != null && ts.getState() != TransactionState.COMMITTED) {
                // open txn, remove
                itr.remove();
            }
        }
        // check in takeover processing
        if (p.checkLock(false) == null) {
            itr.remove();
        }
    }
    ArrayList returnmsgs = new ArrayList();
    itr = sorted.iterator();
    while (itr.hasNext()) {
        PacketReference p = (PacketReference) itr.next();
        if (p == null) {
            continue;
        }
        returnmsgs.add(p.getSysMessageID());
    }
    return returnmsgs;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) SelectorFilter(com.sun.messaging.jmq.jmsserver.core.SelectorFilter) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 20 with TransactionState

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

the class TransactionHandler method doPrepare.

public BaseTransaction doPrepare(TransactionList translist, TransactionUID id, Integer xaFlags, TransactionState ts, int pktType, boolean onephasePrepare, TransactionWork txnWork, IMQConnection con) throws BrokerException {
    BaseTransaction baseTransaction = null;
    boolean persist = true;
    PartitionedStore pstore = translist.getPartitionedStore();
    if (Globals.isNewTxnLogEnabled()) {
        // don't persist transaction state as we are logging it instead
        persist = false;
        if (txnWork == null) {
            // prepare has been called directly from an end client
            // We need to construct the transactional work
            List plist = translist.retrieveSentMessages(id);
            HashMap cmap = translist.retrieveConsumedMessages(id);
            HashMap sToCmap = translist.retrieveStoredConsumerUIDs(id);
            txnWork = getTransactionWork2(pstore, plist, cmap, sToCmap);
        }
    }
    boolean prepared = false;
    int s = ts.nextState(pktType, xaFlags);
    try {
        TransactionState nextState = new TransactionState(ts);
        nextState.setState(s);
        nextState.setOnephasePrepare(true);
        baseTransaction = doRemotePrepare(translist, id, nextState, txnWork);
        if (baseTransaction == null) {
            // The end client must have called prepare
            if (Globals.isNewTxnLogEnabled()) {
                baseTransaction = new LocalTransaction();
                baseTransaction.setTransactionWork(txnWork);
                baseTransaction.setTransactionState(nextState);
                baseTransaction.getTransactionDetails().setTid(id);
                baseTransaction.getTransactionDetails().setXid(ts.getXid());
                baseTransaction.getTransactionDetails().setState(TransactionState.PREPARED);
                logTxn(pstore, baseTransaction);
            }
        }
        if (ts.getType() != AutoRollbackType.NEVER && Globals.isMinimumPersistLevel2()) {
            translist.updateStatePrepareWithWork(id, s, onephasePrepare, persist);
        } else {
            translist.updateState(id, s, onephasePrepare, persist);
        }
        prepared = true;
        if (fi.FAULT_INJECTION) {
            if (fi.checkFault(fi.FAULT_TXN_PREPARE_3_KILL_CLIENT, null)) {
                fi.unsetFault(fi.FAULT_TXN_PREPARE_3_KILL_CLIENT);
                Properties p = new Properties();
                p.setProperty("kill.jvm", "true");
                try {
                    DebugHandler.sendClientDEBUG(con, (new Hashtable()), p);
                } catch (IOException e) {
                    logger.log(logger.WARNING, "TransactionHandler: Unable to sendClientDEBUG: e.toString()");
                }
            } else if (fi.checkFault(fi.FAULT_TXN_PREPARE_3_CLOSE_CLIENT, null)) {
                fi.unsetFault(fi.FAULT_TXN_PREPARE_3_CLOSE_CLIENT);
                Properties p = new Properties();
                p.setProperty("close.conn", "true");
                try {
                    DebugHandler.sendClientDEBUG(con, (new Hashtable()), p);
                } catch (IOException e) {
                    logger.log(logger.WARNING, "TransactionHandler: Unable to sendClientDEBUG: e.toString()");
                }
            }
            fi.checkFaultAndExit(FaultInjection.FAULT_TXN_PREPARE_2_0, null, 2, false);
        }
        try {
            Agent agent = Globals.getAgent();
            if (agent != null) {
                agent.notifyTransactionPrepare(id);
            }
        } catch (Throwable t) {
            logger.log(Logger.WARNING, "XXXI18N - JMX agent notify transaction prepared failed: " + t.getMessage());
        }
    } finally {
        if (!prepared) {
            translist.updateState(id, TransactionState.FAILED, onephasePrepare, TransactionState.PREPARED, persist);
        }
    }
    return baseTransaction;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) LocalTransaction(com.sun.messaging.jmq.jmsserver.data.LocalTransaction) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) Hashtable(java.util.Hashtable) IOException(java.io.IOException) GlobalProperties(com.sun.messaging.jmq.jmsserver.GlobalProperties) Properties(java.util.Properties) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Aggregations

TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)49 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)25 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)22 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)14 JMQXid (com.sun.messaging.jmq.util.JMQXid)9 IOException (java.io.IOException)9 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)8 TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)8 TransactionHandler (com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)7 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 PHashMapLoadException (com.sun.messaging.jmq.io.disk.PHashMapLoadException)5 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)5 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)5 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)4 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)4 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)4 SizeString (com.sun.messaging.jmq.util.SizeString)4 Iterator (java.util.Iterator)4 PHashMap (com.sun.messaging.jmq.io.disk.PHashMap)3