Search in sources :

Example 46 with TransactionList

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

the class ProtocolImpl method recoverTransaction.

/**
 * Recover a transaction.
 *
 * @param id id to recover or null if all
 */
@Override
public JMQXid[] recoverTransaction(TransactionUID id) {
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.RECOVER TRANSACTION:TID=" + id);
    }
    // TransactionHandler handler = (TransactionHandler)
    // pr.getHandler(PacketType.START_TRANSACTION);
    TransactionList[] tls = DL.getTransactionList(null);
    TransactionList tl = null;
    TransactionState ts = null;
    Map<TransactionList, Vector> map = new LinkedHashMap<>();
    Vector v = null;
    for (int i = 0; i < tls.length; i++) {
        tl = tls[i];
        if (id == null) {
            v = tl.getTransactions(TransactionState.PREPARED);
            map.put(tl, v);
        } else {
            ts = tl.retrieveState(id);
            if (ts == null) {
                continue;
            }
            if (ts.getState() == TransactionState.PREPARED) {
                v = new Vector();
                v.add(id);
                map.put(tl, v);
                break;
            }
        }
    }
    ArrayList xids = new ArrayList();
    for (Map.Entry<TransactionList, Vector> pair : map.entrySet()) {
        tl = pair.getKey();
        v = pair.getValue();
        Iterator itr = v.iterator();
        while (itr.hasNext()) {
            TransactionUID tuid = (TransactionUID) itr.next();
            TransactionState _ts = tl.retrieveState(tuid);
            if (_ts == null) {
                // Should never happen
                continue;
            }
            JMQXid _xid = _ts.getXid();
            xids.add(_xid);
        }
    }
    return (JMQXid[]) xids.toArray(new JMQXid[xids.size()]);
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) JMQXid(com.sun.messaging.jmq.util.JMQXid) LinkedHashMap(java.util.LinkedHashMap) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) Iterator(java.util.Iterator) Vector(java.util.Vector) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 47 with TransactionList

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

the class RaptorProtocol method receivedTransactionInfo.

public void receivedTransactionInfo(GPacket pkt, BrokerAddress sender, MessageBusCallback cb) {
    ClusterTxnInfoInfo ii = ClusterTxnInfoInfo.newInstance(pkt, c);
    BrokerAddress from = sender;
    UID msgss = ii.getMessageStoreSessionUID();
    if (msgss != null) {
        from = (BrokerAddress) sender.clone();
        from.setStoreSessionUID(msgss);
    }
    if (DEBUG_CLUSTER_TXN) {
        logger.log(logger.INFO, Globals.getBrokerResources().getString(BrokerResources.I_RECEIVED_TXN_INFO, from.toString(), ii.toString()));
    }
    Long tid = ii.getTransactionID();
    TransactionUID tuid = new TransactionUID(tid.longValue());
    int s = ii.getTransactionState();
    TransactionList tl = null;
    TransactionState mystate = null;
    Object[] oo = TransactionList.getTransListAndState(tuid, null, true, false);
    if (oo != null) {
        tl = (TransactionList) oo[0];
        mystate = (TransactionState) oo[1];
    }
    if (!ii.isOwner() || (ii.isOwner() && from.equals(selfAddress))) {
        if (mystate != null && mystate.getState() == TransactionState.COMMITTED) {
            if (tl.getClusterTransactionBroker(tuid, from) != null) {
                if (s == TransactionState.COMMITTED || (!ii.isOwner() && s == TransactionState.NULL)) {
                    if (DEBUG_CLUSTER_TXN) {
                        logger.log(logger.INFO, "Update broker " + from + " for committed cluster transaction " + tuid);
                    }
                    try {
                        tl.completeClusterTransactionBrokerState(tuid, TransactionState.COMMITTED, from, true);
                        if (!ii.isOwner() && s != TransactionState.NULL) {
                            sendClusterTransactionInfo(tuid, from, null);
                        }
                    } catch (Exception e) {
                        logger.logStack(logger.WARNING, "Unable to update transaction broker state for " + from + ", TUID=" + tuid, e);
                        if (!ii.isOwner()) {
                            return;
                        }
                    }
                }
            } else {
                if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO, "Broker " + from + " is not a transaction broker for TUID=" + tuid);
                }
            }
            if (!ii.isOwner()) {
                return;
            }
        }
    }
    if (s == TransactionState.NULL && !ii.isOwner()) {
        return;
    }
    List<Object[]> list = TransactionList.getTransListsAndRemoteTranStates(tuid);
    if (list == null && !ii.isOwner()) {
        return;
    }
    if (list == null && ii.isOwner()) {
        try {
            if (ii.getWaitfor() != null && ii.isWaitedfor((selfAddress))) {
                sendRemoteTransactionInfo(tuid, from, null, true);
                return;
            }
        } catch (Exception e) {
            logger.logStack(logger.WARNING, e.getMessage(), e);
            return;
        }
        // for rollback pending unprepared
        if (s != TransactionState.NULL) {
            return;
        }
    }
    int type = -1;
    switch(s) {
        case TransactionState.ROLLEDBACK:
        case TransactionState.FAILED:
            type = ClusterGlobals.MB_MSG_TXN_ROLLEDBACK;
            break;
        case TransactionState.NULL:
            logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_REMOTE_TXN_PRESUMED_ROLLBACK, tuid, from));
            type = ClusterGlobals.MB_MSG_TXN_ROLLEDBACK;
            break;
        case TransactionState.COMMITTED:
            type = ClusterGlobals.MB_MSG_CONSUMED;
            break;
        default:
            return;
    }
    try {
        cb.processRemoteAck2P(null, null, type, null, tid, from);
        if (s == TransactionState.COMMITTED && ii.isOwner()) {
            BrokerAddress[] brokers = ii.getBrokers();
            List waitfor = ii.getWaitfor();
            if (brokers == null && waitfor == null) {
                return;
            }
            if (waitfor != null) {
                sendRemoteTransactionInfo(tuid, from, null, true);
            }
        }
    } catch (Exception e) {
        if (DEBUG_CLUSTER_TXN) {
            logger.logStack(logger.WARNING, e.getMessage(), e);
        } else {
            logger.log(logger.WARNING, e.getMessage());
        }
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) HandshakeInProgressException(com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 48 with TransactionList

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

the class CallbackDispatcher method processCommitAck.

private boolean processCommitAck(final BrokerAddress sender, final GPacket pkt) {
    if (!ClusterMessageAckInfo.isAckAckAsync(pkt)) {
        return false;
    }
    Integer acktype = ClusterMessageAckInfo.getAckAckType(pkt);
    if (acktype == null || acktype.intValue() != ClusterGlobals.MB_MSG_CONSUMED) {
        return false;
    }
    Long transactionID = ClusterMessageAckInfo.getAckAckTransactionID(pkt);
    if (transactionID == null) {
        return false;
    }
    if (ClusterMessageAckInfo.getAckAckStatus(pkt) != Status.OK) {
        logger.log(logger.WARNING, br.getKString(br.W_CLUSTER_MSG_ACK_FAILED_FROM_HOME, sender, ClusterMessageAckInfo.toString(pkt)));
        return true;
    }
    if (DEBUG_CLUSTER_TXN || DEBUG) {
        logger.log(logger.INFO, "processCommitAck: Received " + ProtocolGlobals.getPacketTypeDisplayString(pkt.getType()) + " from " + sender + ": " + ClusterMessageAckInfo.toString(pkt));
    }
    if (fi.FAULT_INJECTION) {
        ClusterMessageAckInfo.CHECKFAULT(new HashMap(), ClusterGlobals.MB_MSG_CONSUMED, transactionID, FaultInjection.MSG_REMOTE_ACK_P, FaultInjection.STAGE_3);
    }
    try {
        final TransactionUID tuid = new TransactionUID(transactionID.longValue());
        final UID ss = ClusterMessageAckInfo.getAckAckStoreSessionUID(pkt);
        commitAckExecutor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    BrokerAddress addr = sender;
                    if (ss != null) {
                        addr = (BrokerAddress) sender.clone();
                        addr.setStoreSessionUID(ss);
                    }
                    Object[] oo = TransactionList.getTransListAndState(tuid, null, true, false);
                    if (oo == null) {
                        logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.W_TXN_NOT_FOUND_ON_UPDATE_TXN_COMPLETION_FOR_BKR, tuid, addr));
                        return;
                    }
                    TransactionList tl = (TransactionList) oo[0];
                    tl.completeClusterTransactionBrokerState(tuid, TransactionState.COMMITTED, addr, true);
                } catch (Throwable t) {
                    Object[] args = { tuid, sender + "[" + ClusterMessageAckInfo.toString(pkt) + "]", t.getMessage() };
                    String emsg = br.getKString(br.W_UNABLE_UPDATE_CLUSTER_TXN_COMPLETE_STATE, args);
                    if (t instanceof BrokerException) {
                        if (((BrokerException) t).getStatusCode() == Status.NOT_FOUND) {
                            if (DEBUG_CLUSTER_TXN || DEBUG) {
                                logger.log(logger.WARNING, emsg + " - already completed");
                            }
                            return;
                        }
                    }
                    logger.logStack(logger.WARNING, emsg, t);
                }
            }
        });
    } catch (Throwable t) {
        if (stopThread) {
            logger.log(logger.DEBUG, "Cluster shutdown, ignore event " + ClusterMessageAckInfo.toString(pkt) + " from " + sender);
        } else {
            logger.logStack(logger.WARNING, "Exception in submitting for processing " + ClusterMessageAckInfo.toString(pkt) + " from " + sender, t);
        }
    }
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) UID(com.sun.messaging.jmq.util.UID) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID)

Aggregations

TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)48 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)25 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)23 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)23 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)9 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)9 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)8 TransactionHandler (com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)8 List (java.util.List)8 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)7 IOException (java.io.IOException)7 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)6 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)6 JMQXid (com.sun.messaging.jmq.util.JMQXid)6 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)6 Iterator (java.util.Iterator)6 Map (java.util.Map)6 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)5