Search in sources :

Example 6 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class InboundBridgeRecoveryModule method getUidsToRecover.

/**
 * Returns UIDs of JTA subordinate transactions with format id specified in inbound bridge class which were found in
 * transaction log.
 *
 * @return Set<Uid>
 */
private Set<Uid> getUidsToRecover() {
    if (LOG.isTraceEnabled()) {
        LOG.trace("InboundBridgeRecoveryModule.getUidsToRecover");
    }
    final Set<Uid> uids = new HashSet<Uid>();
    try {
        final RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        final InputObjectState states = new InputObjectState();
        // Only look in the JCA section of the object store
        if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && states.notempty()) {
            boolean finished = false;
            do {
                final Uid uid = UidHelper.unpackFrom(states);
                if (uid.notEquals(Uid.nullUid())) {
                    final SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
                    if (saa.getXid().getFormatId() == InboundBridge.XARESOURCE_FORMAT_ID) {
                        uids.add(uid);
                    }
                } else {
                    finished = true;
                }
            } while (!finished);
        }
    } catch (Exception e) {
        LOG.warn(e.getMessage(), e);
    }
    return uids;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) SubordinateAtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) XAException(javax.transaction.xa.XAException) HashSet(java.util.HashSet)

Example 7 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class ShadowingStore method read_state.

protected InputObjectState read_state(Uid objUid, String tName, int ft) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("ShadowingStore.read_state(" + objUid + ", " + tName + ", " + StateType.stateTypeString(ft) + ")");
    }
    InputObjectState new_image = null;
    if (tName != null) {
        int state = currentState(objUid, tName);
        if ((state == StateStatus.OS_COMMITTED) || (state == StateStatus.OS_UNCOMMITTED)) {
            if (((state == StateStatus.OS_COMMITTED) && (ft != StateType.OS_ORIGINAL)) || ((state == StateStatus.OS_UNCOMMITTED) && (ft != StateType.OS_SHADOW))) {
                /*
                     * Print out a warning/info if the state has changed to help explain the null
                     * value that is returned.
                     */
                tsLogger.logger.info("Object state " + objUid + " for type " + tName + " has changed on disk from what was expected.");
                return null;
            }
            String fname = genPathName(objUid, tName, ft);
            File fd = openAndLock(fname, FileLock.F_RDLCK, false);
            if (fd != null) {
                int imageSize = (int) fd.length();
                byte[] buffer = new byte[imageSize];
                FileInputStream ifile = null;
                try {
                    ifile = new FileInputStream(fd);
                } catch (FileNotFoundException e) {
                    closeAndUnlock(fd, ifile, null);
                    tsLogger.logger.info("ObjectStore record was deleted during restoration, users should not deleted records manually: " + fd.getAbsolutePath(), e);
                    return null;
                }
                try {
                    if ((buffer != null) && (ifile.read(buffer, 0, imageSize) == imageSize)) {
                        new_image = new InputObjectState(objUid, tName, buffer);
                    } else {
                        tsLogger.i18NLogger.warn_objectstore_ShadowingStore_7();
                    }
                } catch (IOException e) {
                    closeAndUnlock(fd, ifile, null);
                    throw new ObjectStoreException("ShadowingStore::read_state failed: " + e, e);
                }
                if (!closeAndUnlock(fd, ifile, null)) {
                    tsLogger.i18NLogger.warn_objectstore_ShadowingStore_8(fname);
                }
            } else {
                tsLogger.i18NLogger.warn_objectstore_ShadowingStore_5(fname);
            }
        } else {
            if (tsLogger.logger.isTraceEnabled())
                tsLogger.logger.trace("ShadowingStore.read_state could not find committed or uncommitted state for " + objUid + " instead found state " + StateStatus.stateStatusString(state));
        }
    } else
        throw new ObjectStoreException("ShadowStore::read_state - " + tsLogger.i18NLogger.get_objectstore_notypenameuid() + objUid);
    return new_image;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class JDBCImple_driver method read_state.

public InputObjectState read_state(Uid objUid, String typeName, int stateType) throws ObjectStoreException {
    InputObjectState result = null;
    // Taken this requirement from ObjStoreBrowser
    if (typeName.startsWith("/"))
        typeName = typeName.substring(1);
    if ((stateType == StateStatus.OS_COMMITTED) || (stateType == StateStatus.OS_UNCOMMITTED)) {
        ResultSet rs = null;
        Connection connection = null;
        PreparedStatement pstmt = null;
        try {
            connection = jdbcAccess.getConnection();
            pstmt = connection.prepareStatement("SELECT ObjectState FROM " + tableName + " WHERE TypeName = ? AND UidString = ? AND StateType = ?");
            pstmt.setString(1, typeName);
            pstmt.setString(2, objUid.stringForm());
            pstmt.setInt(3, stateType);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                byte[] buffer = rs.getBytes(1);
                if (buffer != null) {
                    result = new InputObjectState(objUid, typeName, buffer);
                } else {
                    tsLogger.i18NLogger.warn_objectstore_JDBCImple_readfailed();
                    throw new ObjectStoreException(tsLogger.i18NLogger.warn_objectstore_JDBCImple_readfailed_message());
                }
            }
            connection.commit();
        } catch (Exception e) {
            tsLogger.i18NLogger.warn_objectstore_JDBCImple_14(e);
            throw new ObjectStoreException(e);
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
        }
    } else {
        throw new ObjectStoreException(tsLogger.i18NLogger.unexpected_state_type(stateType));
    }
    return result;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) NamingException(javax.naming.NamingException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SQLException(java.sql.SQLException)

Example 9 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState 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 10 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class LogStore method read_state.

/**
 * Shouldn't be called during normal execution only during recovery.
 */
protected InputObjectState read_state(Uid u, String tn, int s) throws ObjectStoreException {
    /*
           * In case of asynchronous removals of state, let's trigger the purger
           * thread to flush its cache now. Try to avoid false positives during
           * recovery wherever possible!
           */
    _purger.trigger();
    /*
           * It's possible that recovery got hold of a state id while it was
           * being deleted (marker written and pruning thread not yet active).
           * In which case when it comes to do a read it's not going to find
           * the state there any longer. Conversely it's possible that it could do
           * a read on a state that is about to be deleted. Recovery should be
           * able to cope with these edge cases.
           */
    TransactionData td = getLogName(u, tn, -1);
    if (td == null)
        throw new ObjectStoreException();
    ArrayList<InputObjectState> states = scanLog(td.container.getName(), tn);
    if ((states == null) || (states.size() == 0))
        return null;
    for (int i = 0; i < states.size(); i++) {
        if (states.get(i).stateUid().equals(u))
            return states.get(i);
    }
    return null;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) TransactionData(com.arjuna.ats.internal.arjuna.objectstore.LogInstance.TransactionData)

Aggregations

InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)133 Uid (com.arjuna.ats.arjuna.common.Uid)83 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)55 Test (org.junit.Test)47 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)42 IOException (java.io.IOException)30 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)23 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)17 XidImple (com.arjuna.ats.jta.xa.XidImple)9 XAException (javax.transaction.xa.XAException)9 ArrayList (java.util.ArrayList)8 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)7 Xid (javax.transaction.xa.Xid)6 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)5 Date (java.util.Date)5 Vector (java.util.Vector)5 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)4 HashedActionStore (com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore)4 NullActionStore (com.arjuna.ats.internal.arjuna.objectstore.NullActionStore)4 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)4