Package com.sun.messaging.jmq.jmsserver.persist

Examples of com.sun.messaging.jmq.jmsserver.persist.TransactionInfo


    HashMap getAllRemoteTransactionStates() throws IOException {
  HashMap map = new HashMap(tidMap.size());
        Iterator itr = tidMap.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry entry = (Map.Entry)itr.next();
            TransactionInfo txnInfo = (TransactionInfo)entry.getValue();
            int type = txnInfo.getType();
            if (type == TransactionInfo.TXN_REMOTE) {
                map.put(entry.getKey(), (new TransactionState(txnInfo.getTransactionState())));
            }
        }

        return map;
    }
View Full Code Here


            // that never had a chance to complete processing the acks).
            // Check for those "orphaned" ack transactions here. We check
            // state here too just to be anal.
            TransactionUID[] tids = txnAckList.getAllTids();
            for (int i = 0; i < tids.length; i++) {
                TransactionInfo txnInfo = (TransactionInfo)tidMap.get(tids[i]);
                if (txnInfo == null || txnInfo.getTransactionStateValue() != state) {
                    // Orphan. Remove from txnList
                    try {
                        txnAckList.removeAcks(tids[i], sync);
                    } catch (BrokerException e) {
                        // TxnAckList Logs error
View Full Code Here

        Iterator itr = tidMap.entrySet().iterator();
        while (itr.hasNext()) {
            Throwable ex = null;
            Map.Entry entry = (Map.Entry)itr.next();
            Object key = entry.getKey();
            TransactionInfo value = (TransactionInfo)entry.getValue();
            byte[] cData = null;
            try {
                cData = ((PHashMapMMF)tidMap).getClientData(key);
                if (cData != null && cData.length > 0) {
                    int state = (int)cData[0]; // 1st byte is the modified state
                    value.getTransactionState().setState(state); // update txn state

                    // Now read in modified txn broker states
                    TransactionBroker[] bkrs = value.getTransactionBrokers();
                    if (bkrs != null) {
                        for (int i = 0, len = bkrs.length; i < len; i++) {
                            TransactionBroker bkr = bkrs[i];

                            // update bkr's state
View Full Code Here

     * @throws BrokerException
     */
    public TransactionInfo getTransactionInfo( Connection conn,
        TransactionUID txnUID ) throws BrokerException {

        TransactionInfo txnInfo = null;
        long id = txnUID.longValue();

        boolean myConn = false;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Exception myex = null;
        try {
            // Get a connection
            if ( conn == null ) {
                conn = DBManager.getDBManager().getConnection( true );
                myConn = true;
            }

            pstmt = conn.prepareStatement( selectTxnInfoSQL );
            pstmt.setLong( 1, id );

            rs = pstmt.executeQuery();
            if ( rs.next() ) {
                int type = rs.getInt( 1 );
                int state = rs.getInt( 2 );

                TransactionState txnState =
                    (TransactionState)Util.readObject( rs, 3 );

                // update state in TransactionState object
                txnState.setState( state );

                BrokerAddress txnHomeBroker =
                    (BrokerAddress)Util.readObject( rs, 4 );
                TransactionBroker[] txnBrokers =
                    (TransactionBroker[])Util.readObject( rs, 5 );

                txnInfo = new TransactionInfo( txnState, txnHomeBroker,
                    txnBrokers, type );
            } else {
                throw new BrokerException(
                    br.getKString( BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE,
                    String.valueOf( id ) ), Status.NOT_FOUND );
View Full Code Here

                    TransactionBroker[] txnBrokers =
                        (TransactionBroker[])Util.readObject( rs, 5 );
                   
                    map.put( new TransactionUID( id ),
                             new TransactionInfo(txnState, null, txnBrokers, type) );
                } catch ( IOException e ) {
                    // fail to parse TransactionState object; just log it
                    logger.logStack( Logger.ERROR,
                        BrokerResources.X_PARSE_TRANSACTION_FAILED, e );
                }
View Full Code Here

        // 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 = store.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) {
                     store.removeTransactionAck(tid, false);
                 }
                 TransactionAcknowledgement  ta[] = store.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);
                 }
            } 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 = store.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[] = store.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[0]),
                       ti.getTransactionHomeBroker(), true, false, false);
                 if (ts.getState() == TransactionState.COMMITTED) {
                     txnReaper.addRemoteTransaction(tid, true);
                 }
            } catch (Exception ex) {
                 logger.logStack(Logger.ERROR,
View Full Code Here

        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, BrokerResources.E_INTERNAL_ERROR,
                               "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 {
                        store.storeTransaction(tid, ts, false);
                    } catch (Exception ex) {
                        logger.logStack(Logger.WARNING, BrokerResources.E_INTERNAL_ERROR,
                                        "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 {
                        store.storeTransaction(tid, ts, false);
                    } catch (Exception ex) {
                        logger.logStack(Logger.WARNING, BrokerResources.E_INTERNAL_ERROR,
                                        "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 {
                        store.storeTransaction(tid, ts, false);
                    } catch (Exception ex) {
                        logger.logStack(Logger.WARNING, BrokerResources.E_INTERNAL_ERROR,
                                        "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());
                    store.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());
                    store.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 = Globals.getStore().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,
                         BrokerResources.E_INTERNAL_ERROR,
                         "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,
                            ta.toString());
                    processing = processing.getNextException();
                    continue;
                }
                //ta == null, nothing we can do, remove it
                logger.log(Logger.WARNING,
                           BrokerResources.W_TRANS_ACK_CORRUPT,
                           tid.toString());
                try {
                    store.removeTransactionAck(tid, false);
                } catch (Exception ex) {
                    logger.logStack(Logger.WARNING, BrokerResources.E_INTERNAL_ERROR,
                                    "Error updating transaction acks " + tid, ex);
                }
            } // end while
        }

        logger.log(Logger.INFO, BrokerResources.I_PROCESSING_TRANS);
        // OK -> first load the list of pending
        // transactions
        HashMap trans = store.getAllTransactionStates();

        // Write some info about the transactions to the log file
        // for informational purposes.
        logTransactionInfo(trans, AUTO_ROLLBACK);

        // 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 totalN = 0, clusterN = 0, remoteN = 0;
        int prepareN = 0, commitN = 0, rollbackN = 0;
        int prepareCN = 0, commitCN = 0, commitWaitCN = 0;
        Iterator itr = trans.entrySet().iterator();
        while (itr.hasNext()) {
          totalN++;
          try {
             Map.Entry entry = (Map.Entry)itr.next();
             TransactionUID tid = (TransactionUID)entry.getKey();
             TransactionInfo tif = (TransactionInfo)entry.getValue();
             TransactionState ts = tif.getTransactionState();
             TransactionAcknowledgement  ta[] = store.getTransactionAcks(tid);
             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:
                     prepareN++;
                     // 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);
                         // put messages in the orphan list
                         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);
                     rollbackN++;
                     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:
                     commitN++;
                     committingTransactions.put(tid, "");
                     if (tif.getType() == TransactionInfo.TXN_CLUSTER) {
                         commitCN++;
                         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);
            }
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.persist.TransactionInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.