Search in sources :

Example 21 with TransactionUID

use of com.sun.messaging.jmq.jmsserver.data.TransactionUID 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)

Example 22 with TransactionUID

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

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

the class ConsumerStateDAOImpl method getAllTransactionAcks.

/**
 * Retrieve all transaction acknowledgements for all transactions.
 *
 * @param conn database connection
 * @return HashMap of containing all acknowledgement
 */
@Override
public HashMap getAllTransactionAcks(Connection conn) throws BrokerException {
    HashMap data = new HashMap(100);
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectAllTransactionAcksSQL);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            TransactionUID txnUID = new TransactionUID(rs.getLong(1));
            ConsumerUID conID = new ConsumerUID(rs.getLong(2));
            try {
                SysMessageID msgID = SysMessageID.get(rs.getString(3));
                List ackList = (List) data.get(txnUID);
                if (ackList == null) {
                    // Create a new list of acks for this txn
                    ackList = new ArrayList(25);
                    data.put(txnUID, ackList);
                }
                // Added ack to the list of acks
                ackList.add(new TransactionAcknowledgement(msgID, conID, conID));
            } catch (Exception e) {
                // fail to parse one object; just log it
                logger.logStack(Logger.ERROR, BrokerResources.X_PARSE_TXNACK_FAILED, txnUID, e);
            }
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + selectAllTransactionAcksSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_LOAD_TXNACK_FAILED), ex);
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    // Transforms HashMap value to TransactionAcknowledgement[] instead of List
    Set keySet = data.keySet();
    if (!keySet.isEmpty()) {
        Iterator itr = keySet.iterator();
        while (itr.hasNext()) {
            TransactionUID txnUID = (TransactionUID) itr.next();
            List ackList = (List) data.get(txnUID);
            data.put(txnUID, ackList.toArray(new TransactionAcknowledgement[ackList.size()]));
        }
    }
    return data;
}
Also used : TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 24 with TransactionUID

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

the class BaseTransactionManager method removeCompleteTransactionsAfterCheckpoint.

void removeCompleteTransactionsAfterCheckpoint() throws BrokerException {
    if (Store.getDEBUG()) {
        String msg = getPrefix() + " removeCompleteTransactionsAfterCheckpoint" + " num completeStored=" + completeStored.size();
        logger.log(Logger.DEBUG, msg);
    }
    ArrayList cmptids = null;
    synchronized (completeStored) {
        cmptids = new ArrayList(completeStored.keySet());
    }
    Iterator<TransactionUID> iter = cmptids.iterator();
    while (iter.hasNext()) {
        TransactionUID tid = iter.next();
        if (preparedTxnStore.containsTransaction(tid)) {
            preparedTxnStore.removeTransaction(tid, true);
            if (Store.getDEBUG()) {
                String msg = getPrefix() + " removed transaction " + tid;
                logger.log(Logger.DEBUG, msg);
            }
        } else {
            if (Store.getDEBUG()) {
                String msg = getPrefix() + " Could not find transaction in preparedTxnStore " + tid;
                logger.log(Logger.DEBUG, msg);
            }
        }
    }
    completeStored.clear();
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ArrayList(java.util.ArrayList)

Example 25 with TransactionUID

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

the class JMSServiceImpl method redeliverMessages.

/**
 * Redeliver messages for a Session.
 * <p>
 * All the messages that are specified by the parameters will be redelivered by the broker.
 *
 * @param connectionId The Id of the connection in which the messages were received
 * @param sessionId The Id of the session in which the messages were received
 * @param messageIDs The array of SysMessageID objects for the messages that were received and are to be redelivered
 * @param consumerIds The array of consumerId longs for the messages that were received and are to be redelivered
 * @param transactionId The Id of the transaction in which the messages were received
 * @param setRedelivered Indicates whether to set the Redelivered flag when redelivering the messages.<br>
 * If <code>true</code> then the Redelivered flag must be set for the messages when they are redelivered.<br>
 * If <code>false</code>, then the Redelivered flag must not be set for the messages when they are redelivered.
 *
 * @throws JMSServiceException If broker encounters an error.<br>
 * {@link JMSServiceException#getJMSServiceReply} should be used to obtain the broker reply in case of an exception.<br>
 * The reason for the exception can be obtained from {@link JMSServiceReply.Status}
 */
@Override
public JMSServiceReply redeliverMessages(long connectionId, long sessionId, SysMessageID[] messageIDs, Long[] consumerIds, long transactionId, boolean setRedelivered) throws JMSServiceException {
    JMSServiceReply reply;
    IMQConnection cxn;
    HashMap props = new HashMap();
    ConsumerUID[] conUIDs = null;
    TransactionUID txnUID = null;
    // Session session;
    cxn = checkConnectionId(connectionId, "redeliverMessages");
    // session = checkSessionId(sessionId, "redeliverMessages");
    checkSessionId(sessionId, "redeliverMessages");
    if (consumerIds != null) {
        conUIDs = new ConsumerUID[consumerIds.length];
        for (int i = 0; i < consumerIds.length; ++i) {
            conUIDs[i] = new ConsumerUID(consumerIds[i]);
        }
    }
    if (transactionId != -1) {
        txnUID = new TransactionUID(transactionId);
    }
    try {
        protocol.redeliver(conUIDs, messageIDs, cxn, txnUID, setRedelivered);
    } catch (Exception e) {
        String errStr = "redeliverMessages: Redeliver failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", transaction ID: " + transactionId;
        logger.logStack(Logger.ERROR, errStr, e);
        props.put("JMQStatus", getErrorReplyStatus(e));
        throw new JMSServiceException(errStr, e, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException)

Aggregations

TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)71 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)23 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)22 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)19 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)18 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)15 JMQXid (com.sun.messaging.jmq.util.JMQXid)13 IOException (java.io.IOException)13 HashMap (java.util.HashMap)12 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)10 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)10 ArrayList (java.util.ArrayList)10 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)8 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)7 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)7 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)7 Iterator (java.util.Iterator)7 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)6