Search in sources :

Example 66 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class PersistenceTest method test.

@Test
public void test() {
    boolean passed = false;
    boolean threaded = false;
    long stime = Calendar.getInstance().getTime().getTime();
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    for (int i = 0; i < 1000; i++) {
        try {
            ParticipantStore store = null;
            if (!threaded)
                store = new ShadowingStore(objectStoreEnvironmentBean);
            else
                store = new CacheStore(objectStoreEnvironmentBean);
            byte[] data = new byte[10240];
            OutputObjectState state = new OutputObjectState();
            Uid u = new Uid();
            state.packBytes(data);
            if (store.write_committed(u, "/StateManager/LockManager/foo", state)) {
                passed = true;
            } else
                passed = false;
        } catch (ObjectStoreException e) {
            System.out.println(e.getMessage());
            passed = false;
        } catch (IOException ex) {
            ex.printStackTrace();
            passed = false;
        }
    }
    try {
        Thread.currentThread().sleep(1000);
    } catch (Exception ex) {
    }
    long ftime = Calendar.getInstance().getTime().getTime();
    long timeTaken = ftime - stime;
    System.out.println("time for 1000 write transactions is " + timeTaken);
    try {
        Thread.currentThread().sleep(1000);
    } catch (Exception ex) {
    }
    assertTrue(passed);
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) IOException(java.io.IOException) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) Uid(com.arjuna.ats.arjuna.common.Uid) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ShadowingStore(com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore) CacheStore(com.arjuna.ats.internal.arjuna.objectstore.CacheStore) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) Test(org.junit.Test)

Example 67 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class RecoveredTransactionalObject method findHoldingTransaction.

/**
 * Determine which transaction got this into uncommitted state return true
 * if there is such a transaction
 */
private final boolean findHoldingTransaction() {
    InputObjectState uncommittedState = null;
    _originalProcessUid = new Uid(Uid.nullUid());
    try {
        uncommittedState = _participantStore.read_uncommitted(_ourUid, _type);
    } catch (ObjectStoreException e) {
        txojLogger.i18NLogger.warn_recovery_RecoveredTransactionalObject_6(e);
        // probably
        return false;
    }
    /*
         * Get the transaction and original process information from the saved
         * state.
         */
    _originalProcessUid = null;
    _owningTransactionUid = null;
    try {
        Header hdr = new Header();
        unpackHeader(uncommittedState, hdr);
        _originalProcessUid = hdr.getProcessId();
        _owningTransactionUid = hdr.getTxId();
        if (txojLogger.logger.isDebugEnabled()) {
            txojLogger.logger.debug("RecoveredTransactionalObject::findHoldingTransaction - uid is " + _owningTransactionUid);
        }
        return _owningTransactionUid.notEquals(Uid.nullUid());
    } catch (Exception e) {
        txojLogger.i18NLogger.warn_recovery_RecoveredTransactionalObject_8(e);
    }
    return false;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) Header(com.arjuna.ats.internal.arjuna.Header) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 68 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class SubordinateAtomicActionRecoveryModule method periodicWorkFirstPass.

@Override
public void periodicWorkFirstPass() {
    /*
         * Requires going through the objectstore for the states of imported
         * transactions - this is just to make sure the server control are loaded into memory.
         *
         * The EIS will call XATerminator::recover() for actual crash recovery
         */
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    InputObjectState states = new InputObjectState();
    // only look in the JCA section of the object store
    Uid uid = null;
    try {
        if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && (states.notempty())) {
            while (true) {
                uid = UidHelper.unpackFrom(states);
                if (uid.notEquals(Uid.nullUid())) {
                    SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                } else {
                    break;
                }
            }
        }
        recoveryScanCompletedWithoutError = true;
    } catch (ObjectStoreException | XAException | IOException e) {
        jtaLogger.i18NLogger.warn_could_not_recover_subordinate(uid, e);
        recoveryScanCompletedWithoutError = false;
    }
    if (!validatePosition()) {
        recoveryScanCompletedWithoutError = false;
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) XAException(javax.transaction.xa.XAException) IOException(java.io.IOException) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore)

Example 69 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class CommitMarkableResourceRecordRecoveryModule method periodicWorkFirstPass.

@Override
public synchronized void periodicWorkFirstPass() {
    if (inFirstPass) {
        return;
    }
    inFirstPass = true;
    // TODO - this is one shot only due to a
    // remove in the function, if this delete fails only normal
    // recovery is possible
    Map<String, List<Xid>> completedBranches2 = new HashMap<String, List<Xid>>();
    synchronized (completedBranches) {
        completedBranches2.putAll(completedBranches);
        completedBranches.clear();
    }
    for (Map.Entry<String, List<Xid>> e : completedBranches2.entrySet()) delete(e.getKey(), e.getValue());
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("CommitMarkableResourceRecordRecoveryModule::periodicWorkFirstPass");
    }
    this.committedXidsToJndiNames.clear();
    this.queriedResourceManagers.clear();
    this.jndiNamesToPossibleXidsForGC.clear();
    // committed
    try {
        Iterator<String> iterator = jndiNamesToContact.iterator();
        while (iterator.hasNext()) {
            String jndiName = iterator.next();
            try {
                if (tsLogger.logger.isTraceEnabled()) {
                    tsLogger.logger.trace("CommitMarkableResourceRecordRecoveryModule::connecting to: " + jndiName);
                }
                DataSource dataSource = (DataSource) context.lookup(jndiName);
                Connection connection = dataSource.getConnection();
                try {
                    Statement createStatement = connection.createStatement();
                    try {
                        String tableName = commitMarkableResourceTableNameMap.get(jndiName);
                        if (tableName == null) {
                            tableName = defaultTableName;
                        }
                        ResultSet rs = createStatement.executeQuery("SELECT xid,actionuid from " + tableName + whereFilter);
                        try {
                            int i = 0;
                            while (rs.next()) {
                                i++;
                                byte[] xidAsBytes = rs.getBytes(1);
                                ByteArrayInputStream bais = new ByteArrayInputStream(xidAsBytes);
                                DataInputStream dis = new DataInputStream(bais);
                                XID _theXid = new XID();
                                _theXid.formatID = dis.readInt();
                                _theXid.gtrid_length = dis.readInt();
                                _theXid.bqual_length = dis.readInt();
                                int dataLength = dis.readInt();
                                _theXid.data = new byte[dataLength];
                                dis.read(_theXid.data, 0, dataLength);
                                XidImple xid = new XidImple(_theXid);
                                byte[] actionuidAsBytes = new byte[Uid.UID_SIZE];
                                byte[] bytes = rs.getBytes(2);
                                System.arraycopy(bytes, 0, actionuidAsBytes, 0, bytes.length);
                                committedXidsToJndiNames.put(xid, jndiName);
                                if (tsLogger.logger.isTraceEnabled()) {
                                    tsLogger.logger.trace("committedXidsToJndiNames.put" + xid + " " + jndiName);
                                }
                                // Populate the map of possible GCable Xids
                                Uid actionuid = new Uid(actionuidAsBytes);
                                Map<Xid, Uid> map = jndiNamesToPossibleXidsForGC.get(jndiName);
                                if (map == null) {
                                    map = new HashMap<Xid, Uid>();
                                    jndiNamesToPossibleXidsForGC.put(jndiName, map);
                                }
                                map.put(xid, actionuid);
                            }
                        } finally {
                            try {
                                rs.close();
                            } catch (SQLException e) {
                                tsLogger.logger.warn("Could not close resultset", e);
                            }
                        }
                    } finally {
                        try {
                            createStatement.close();
                        } catch (SQLException e) {
                            tsLogger.logger.warn("Could not close statement", e);
                        }
                    }
                    queriedResourceManagers.add(jndiName);
                } finally {
                    try {
                        connection.close();
                    } catch (SQLException e) {
                        tsLogger.logger.warn("Could not close connection", e);
                    }
                }
            } catch (NamingException e) {
                tsLogger.logger.debug("Could not lookup CommitMarkableResource: " + jndiName, e);
            } catch (SQLException e) {
                tsLogger.logger.warn("Could not handle connection", e);
            } catch (IOException e) {
                tsLogger.logger.warn("Could not lookup write data to select", e);
            }
        }
        // reference
        try {
            InputObjectState uidList = new InputObjectState();
            recoveryStore.allObjUids(CONNECTABLE_ATOMIC_ACTION_TYPE, uidList);
            Uid currentUid = UidHelper.unpackFrom(uidList);
            while (Uid.nullUid().notEquals(currentUid)) {
                // Make sure it isn't garbage from a failure to move before:
                InputObjectState state = recoveryStore.read_committed(currentUid, ATOMIC_ACTION_TYPE);
                if (state != null) {
                    if (!recoveryStore.remove_committed(currentUid, CONNECTABLE_ATOMIC_ACTION_TYPE)) {
                        tsLogger.logger.debug("Could not remove a: " + CONNECTABLE_ATOMIC_ACTION_TYPE + " uid: " + currentUid);
                    }
                } else {
                    state = recoveryStore.read_committed(currentUid, CONNECTABLE_ATOMIC_ACTION_TYPE);
                    // TX may have been in progress and cleaned up by now
                    if (state != null) {
                        RecoverConnectableAtomicAction rcaa = new RecoverConnectableAtomicAction(CONNECTABLE_ATOMIC_ACTION_TYPE, currentUid, state);
                        if (rcaa.containsIncompleteCommitMarkableResourceRecord()) {
                            String commitMarkableResourceJndiName = rcaa.getCommitMarkableResourceJndiName();
                            // Check if the resource manager is online yet
                            if (queriedResourceManagers.contains(commitMarkableResourceJndiName)) {
                                // If it is remove the CRR and move it back and
                                // let
                                // the
                                // next stage update it
                                moveRecord(currentUid, CONNECTABLE_ATOMIC_ACTION_TYPE, ATOMIC_ACTION_TYPE);
                            }
                        } else {
                            if (tsLogger.logger.isTraceEnabled()) {
                                tsLogger.logger.trace("Moving " + currentUid + " back to being an AA");
                            }
                            // It is now safe to move it back to being an AA so that it can call getNewXAResourceRecord
                            moveRecord(currentUid, CONNECTABLE_ATOMIC_ACTION_TYPE, ATOMIC_ACTION_TYPE);
                        }
                    }
                }
                currentUid = UidHelper.unpackFrom(uidList);
            }
        } catch (ObjectStoreException | IOException ex) {
            tsLogger.logger.warn("Could not query objectstore: ", ex);
        }
        // moved in stage 2
        if (tsLogger.logger.isDebugEnabled()) {
            tsLogger.logger.debug("processing " + ATOMIC_ACTION_TYPE + " transactions");
        }
        try {
            InputObjectState uidList = new InputObjectState();
            recoveryStore.allObjUids(ATOMIC_ACTION_TYPE, uidList);
            Uid currentUid = UidHelper.unpackFrom(uidList);
            while (Uid.nullUid().notEquals(currentUid)) {
                // process.
                if (!isTransactionInMidFlight(transactionStatusConnectionMgr.getTransactionStatus(ATOMIC_ACTION_TYPE, currentUid))) {
                    InputObjectState state = recoveryStore.read_committed(currentUid, ATOMIC_ACTION_TYPE);
                    if (state != null) {
                        // Try to load it is a BasicAction that has a
                        // ConnectedResourceRecord
                        RecoverConnectableAtomicAction rcaa = new RecoverConnectableAtomicAction(ATOMIC_ACTION_TYPE, currentUid, state);
                        // Check if it did have a ConnectedResourceRecord
                        if (rcaa.containsIncompleteCommitMarkableResourceRecord()) {
                            String commitMarkableResourceJndiName = rcaa.getCommitMarkableResourceJndiName();
                            // online
                            if (!queriedResourceManagers.contains(commitMarkableResourceJndiName)) {
                                // If the resource manager wasn't online, move
                                // it
                                moveRecord(currentUid, ATOMIC_ACTION_TYPE, CONNECTABLE_ATOMIC_ACTION_TYPE);
                            } else {
                                // Update the completed outcome for the 1PC
                                // resource
                                rcaa.updateCommitMarkableResourceRecord(committedXidsToJndiNames.get(rcaa.getXid()) != null);
                                // Swap the type to avoid the rest of recovery round processing this TX as it already called getNewXAResourceRecord
                                moveRecord(currentUid, ATOMIC_ACTION_TYPE, CONNECTABLE_ATOMIC_ACTION_TYPE);
                            }
                        }
                    }
                }
                currentUid = UidHelper.unpackFrom(uidList);
            }
        } catch (ObjectStoreException | IOException ex) {
            tsLogger.logger.warn("Could not query objectstore: ", ex);
        }
    } catch (IllegalStateException e) {
        // Thrown when AS is shutting down and we attempt a lookup
        tsLogger.logger.debug("Could not lookup datasource, AS is shutting down: " + e.getMessage(), e);
    }
    inFirstPass = false;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) NamingException(javax.naming.NamingException) XidImple(com.arjuna.ats.jta.xa.XidImple) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) DataSource(javax.sql.DataSource) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) XID(com.arjuna.ats.internal.jta.xa.XID) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) Map(java.util.Map)

Example 70 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class CommitMarkableResourceRecordRecoveryModule method periodicWorkSecondPass.

@Override
public synchronized void periodicWorkSecondPass() {
    /**
     * This is the list of AtomicActions that were prepared but not
     * completed.
     */
    Set<Uid> preparedAtomicActions = new HashSet<Uid>();
    InputObjectState aa_uids = new InputObjectState();
    try {
        // Refresh our list of all the indoubt atomic actions
        if (recoveryStore.allObjUids(ATOMIC_ACTION_TYPE, aa_uids)) {
            preparedAtomicActions.addAll(convertToList(aa_uids));
            // actions
            if (recoveryStore.allObjUids(CONNECTABLE_ATOMIC_ACTION_TYPE, aa_uids)) {
                preparedAtomicActions.addAll(convertToList(aa_uids));
                // Iterate the list that we were able to contact
                Iterator<String> jndiNames = queriedResourceManagers.iterator();
                while (jndiNames.hasNext()) {
                    String jndiName = jndiNames.next();
                    List<Xid> toDelete = new ArrayList<Xid>();
                    Map<Xid, Uid> map = jndiNamesToPossibleXidsForGC.get(jndiName);
                    if (map != null) {
                        for (Map.Entry<Xid, Uid> entry : map.entrySet()) {
                            Xid next = entry.getKey();
                            Uid uid = entry.getValue();
                            if (!preparedAtomicActions.contains(uid)) {
                                toDelete.add(next);
                            }
                        }
                    }
                    delete(jndiName, toDelete);
                }
            } else {
                tsLogger.logger.warn("Could not read data from object store");
            }
        } else {
            tsLogger.logger.warn("Could not read " + CONNECTABLE_ATOMIC_ACTION_TYPE + " from object store");
        }
    } catch (ObjectStoreException e) {
        tsLogger.logger.warn("Could not read " + ATOMIC_ACTION_TYPE + " from object store", e);
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) ArrayList(java.util.ArrayList) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)87 IOException (java.io.IOException)44 Uid (com.arjuna.ats.arjuna.common.Uid)35 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)34 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)23 File (java.io.File)11 Connection (java.sql.Connection)9 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 NamingException (javax.naming.NamingException)9 Enumeration (java.util.Enumeration)8 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)6 FileNotFoundException (java.io.FileNotFoundException)5 ResultSet (java.sql.ResultSet)5 ArrayList (java.util.ArrayList)5 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)4 XidImple (com.arjuna.ats.jta.xa.XidImple)4 RandomAccessFile (java.io.RandomAccessFile)3 SyncFailedException (java.io.SyncFailedException)3 Statement (java.sql.Statement)3