Search in sources :

Example 6 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class OTM method updateTransactions.

@SuppressWarnings("unchecked")
public synchronized void updateTransactions() {
    if (scanningNode != null) {
        DefaultMutableTreeNode top = (DefaultMutableTreeNode) topTran.getFirstChild();
        DefaultTreeModel model = (DefaultTreeModel) transactions.getModel();
        try {
            RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
            InputObjectState types = new InputObjectState();
            startSweep();
            if (recoveryStore.allTypes(types)) {
                String fullPathName = null;
                boolean found = false;
                try {
                    boolean endOfList = false;
                    DefaultMutableTreeNode currentNode = null;
                    DefaultMutableTreeNode currentRoot = top;
                    while (!endOfList) {
                        fullPathName = types.unpackString();
                        if (fullPathName.compareTo("") == 0)
                            endOfList = true;
                        else {
                            found = true;
                            InputObjectState uids = new InputObjectState();
                            String nodeName = stripName(fullPathName);
                            boolean added = false;
                            currentNode = findNode(fullPathName);
                            if (currentNode == null) {
                                currentNode = new DefaultMutableTreeNode(nodeName);
                                addDirectory(currentNode, fullPathName);
                                currentRoot.add(currentNode);
                                /*
                                     * New, so update view.
                                     */
                                int[] i = new int[1];
                                i[0] = currentRoot.getChildCount() - 1;
                                model.nodesWereInserted(currentRoot, i);
                                added = true;
                            }
                            currentRoot = findRoot(top, currentNode);
                            if (added)
                                currentRoot.add(currentNode);
                            if (recoveryStore.allObjUids(fullPathName, uids)) {
                                Uid theUid = new Uid(Uid.nullUid());
                                try {
                                    boolean endOfUids = false;
                                    boolean first = true;
                                    boolean haveUids = false;
                                    while (!endOfUids) {
                                        theUid = UidHelper.unpackFrom(uids);
                                        if (theUid.equals(Uid.nullUid())) {
                                            if (!haveUids) {
                                                if (emptyDirectory(currentNode)) {
                                                    currentNode.removeAllChildren();
                                                    model.nodeChanged(currentNode);
                                                }
                                            }
                                            endOfUids = true;
                                        } else {
                                            haveUids = true;
                                            if (first) {
                                                currentNode.removeAllChildren();
                                                first = false;
                                            }
                                            DefaultMutableTreeNode tranID = new DefaultMutableTreeNode(theUid.stringForm());
                                            tranID.add(new DefaultMutableTreeNode(new String("status: " + statusToString(recoveryStore.currentState(theUid, fullPathName)))));
                                            currentNode.add(tranID);
                                            added = true;
                                        }
                                    }
                                } catch (Exception e) {
                                // end of uids!
                                }
                                if (added)
                                    model.nodeChanged(currentNode);
                            }
                        }
                        if (!found)
                            currentRoot.add(emptyTx);
                    }
                } catch (Exception e) {
                // end of list!
                }
            }
            try {
                endSweep();
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(0);
            }
        } catch (Exception e) {
            System.err.println(e);
        }
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) UnknownHostException(java.net.UnknownHostException)

Example 7 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class RemoveCachedTest method test.

@Test
public void test() throws IOException, ObjectStoreException {
    boolean passed = true;
    RecoveryStore store = new CacheStore(new ObjectStoreEnvironmentBean());
    String type = "ArjunaMS/Destinations/a3d6227_dc656_3b77ce7e_2/Messages";
    InputObjectState buff = new InputObjectState();
    if (store.allObjUids(type, buff, StateStatus.OS_COMMITTED)) {
        Uid toRemove = new Uid(Uid.nullUid());
        do {
            toRemove = UidHelper.unpackFrom(buff);
            if (toRemove.notEquals(Uid.nullUid())) {
                System.err.println("Removing " + toRemove + "\n");
                if (store.remove_committed(toRemove, type))
                    passed = true;
                else {
                    System.err.println("Failed for " + toRemove);
                    passed = false;
                }
            }
        } while (toRemove.notEquals(Uid.nullUid()));
    }
    assertTrue(passed);
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) CacheStore(com.arjuna.ats.internal.arjuna.objectstore.CacheStore) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Example 8 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class LogStoreTest method test.

@Test
public void test() {
    arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(LogStore.class.getName());
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    final int numberOfTransactions = 1000;
    final Uid[] ids = new Uid[numberOfTransactions];
    final int fakeData = 0xdeedbaaf;
    final String type = "/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/Test";
    for (int i = 0; i < numberOfTransactions; i++) {
        OutputObjectState dummyState = new OutputObjectState();
        try {
            dummyState.packInt(fakeData);
            ids[i] = new Uid();
            recoveryStore.write_committed(ids[i], type, dummyState);
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }
    InputObjectState ios = new InputObjectState();
    boolean passed = false;
    try {
        if (recoveryStore.allObjUids(type, ios, StateStatus.OS_UNKNOWN)) {
            Uid id = new Uid(Uid.nullUid());
            int numberOfEntries = 0;
            do {
                try {
                    id = UidHelper.unpackFrom(ios);
                } catch (Exception ex) {
                    id = Uid.nullUid();
                }
                if (id.notEquals(Uid.nullUid())) {
                    passed = true;
                    System.err.println("Located transaction log " + id + " in object store.");
                    numberOfEntries++;
                    boolean found = false;
                    for (int i = 0; i < ids.length; i++) {
                        if (id.equals(ids[i]))
                            found = true;
                    }
                    if (passed && !found) {
                        passed = false;
                        System.err.println("Found unexpected transaction!");
                    }
                }
            } while (id.notEquals(Uid.nullUid()));
            if ((numberOfEntries != ids.length) && passed) {
                passed = false;
                System.err.println("Expected " + ids.length + " and got " + numberOfEntries);
            }
        }
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
    assertTrue(passed);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) LogStore(com.arjuna.ats.internal.arjuna.objectstore.LogStore) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Example 9 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class XATerminatorImple method doRecover.

/**
 * Return a list of indoubt transactions. This may include those
 * transactions that are currently in-flight and running 2PC and do not need
 * recovery invoked on them.
 *
 * @param nodeName
 * 				Only recover transactions for this node (unless set to NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
 * @throws XAException
 *             thrown if any error occurs.
 * @return a list of potentially indoubt transactions or <code>null</code>.
 */
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException {
    /*
         * Requires going through the objectstore for the states of imported
         * transactions. Our own crash recovery takes care of transactions
         * imported via CORBA, Web Services etc.
         */
    Xid[] indoubt = null;
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && (states.notempty())) {
            Stack<Xid> values = new Stack<Xid>();
            boolean finished = false;
            do {
                Uid uid = null;
                try {
                    uid = UidHelper.unpackFrom(states);
                } catch (IOException ex) {
                    ex.printStackTrace();
                    finished = true;
                }
                if (uid.notEquals(Uid.nullUid())) {
                    if (parentNodeName != null) {
                        SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
                        XidImple loadedXid = (XidImple) saa.getXid();
                        if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
                            String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
                            if ((loadedXidSubordinateNodeName == null && loadedXidSubordinateNodeName == TxControl.getXANodeName()) || loadedXidSubordinateNodeName.equals(TxControl.getXANodeName())) {
                                if (parentNodeName.equals(saa.getParentNodeName())) {
                                    if (jtaLogger.logger.isDebugEnabled()) {
                                        jtaLogger.logger.debug("Found record for " + saa);
                                    }
                                    // TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                                    values.push(loadedXid);
                                }
                            }
                        }
                    } else if (xid == null) {
                        TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                        if (tx != null)
                            values.push(tx.baseXid());
                    } else {
                        SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
                        XidImple loadedXid = (XidImple) saa.getXid();
                        if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
                            String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
                            if (XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID()).equals(loadedXidSubordinateNodeName)) {
                                if (Arrays.equals(loadedXid.getGlobalTransactionId(), xid.getGlobalTransactionId())) {
                                    if (jtaLogger.logger.isDebugEnabled()) {
                                        jtaLogger.logger.debug("Found record for " + saa);
                                    }
                                    TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                                    values.push(loadedXid);
                                }
                            }
                        }
                    }
                } else
                    finished = true;
            } while (!finished);
            if (values.size() > 0) {
                int index = 0;
                indoubt = new Xid[values.size()];
                while (!values.empty()) {
                    indoubt[index] = values.pop();
                    index++;
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return indoubt;
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) IOException(java.io.IOException) SubordinateAtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) IOException(java.io.IOException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException) Stack(java.util.Stack) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid)

Example 10 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class XATerminatorImple method doRecover.

/**
 * <p>
 * Recovering /JCA section of object store.
 * The filtering functionality on xid or parentNodeName is not permitted and throws {@link NotSupportedException}.<br>
 * Expected to be called only with null parameters <code>doRecover(null, null)</code>
 *
 * @param xid has to be null
 * @param parentNodeName  has to be null
 * @return array of subordinate recovered xids
 * @throws XAException  if recovery operation fails for the XA protocol reason
 * @throws NotSupportedException  if not null params are passes as method parameters
 */
@Override
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException, NotSupportedException {
    if (xid != null || parentNodeName != null)
        throw new NotSupportedException("doRecover method works only with null arguments");
    Xid[] indoubt = null;
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        // only look in the JCA section of the object store
        if (recoveryStore.allObjUids(ServerTransaction.getType(), states) && (states.notempty())) {
            Stack<Transaction> values = new Stack<Transaction>();
            boolean finished = false;
            do {
                Uid uid = null;
                try {
                    uid = UidHelper.unpackFrom(states);
                } catch (IOException ex) {
                    jtsLogger.i18NLogger.info_fail_to_read_subordinate_uid(recoveryStore, states, ex);
                    finished = true;
                }
                if (uid.notEquals(Uid.nullUid())) {
                    Transaction tx = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                    if (tx != null)
                        values.push(tx);
                } else
                    finished = true;
            } while (!finished);
            if (values.size() > 0) {
                int index = 0;
                indoubt = new Xid[values.size()];
                while (!values.empty()) {
                    TransactionImple id = (TransactionImple) values.pop();
                    indoubt[index] = id.baseXid();
                    index++;
                }
            }
        }
    } catch (Exception ex) {
        jtsLogger.i18NLogger.info_fail_to_dorecover(xid, parentNodeName, ex);
    }
    return indoubt;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) IOException(java.io.IOException) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) IOException(java.io.IOException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException) Stack(java.util.Stack) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) ServerTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.coordinator.ServerTransaction) Transaction(javax.transaction.Transaction) SubordinateAtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction) NotSupportedException(javax.transaction.NotSupportedException)

Aggregations

RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)29 Uid (com.arjuna.ats.arjuna.common.Uid)27 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)23 IOException (java.io.IOException)10 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)9 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)8 Test (org.junit.Test)7 XAException (javax.transaction.xa.XAException)5 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)4 XidImple (com.arjuna.ats.jta.xa.XidImple)3 Stack (java.util.Stack)3 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)2 LogStore (com.arjuna.ats.internal.arjuna.objectstore.LogStore)2 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)2 UnknownHostException (java.net.UnknownHostException)2 HashSet (java.util.HashSet)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 HeuristicCommitException (javax.transaction.HeuristicCommitException)2 HeuristicMixedException (javax.transaction.HeuristicMixedException)2