Search in sources :

Example 46 with ObjectStoreException

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

the class BasicActionFinalizer method prepare.

/**
 * Phase one of a two phase commit protocol. This function returns the
 * ouctome of the prepare operation. If all goes well it will be PREPARE_OK,
 * if not PREPARE_NOTOK. The value PREPARE_READONLY may also be returned if
 * all the records indicate that they are readonly records. Such records do
 * not take part in the second phase commit processing.
 *
 * @return <code>TwoPhaseOutcome</code> indicating outcome. Note that if
 * 1PC optimisation is enabled then it is possible for prepare to dynamically
 * optimise and commit if the first N-1 participants return read-only, causing the
 * protcol to commit the last participant rather than go through prepare.
 */
protected final synchronized int prepare(boolean reportHeuristics) {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("BasicAction::prepare () for action-id " + get_uid());
    }
    boolean commitAllowed = (actionStatus != ActionStatus.ABORT_ONLY);
    actionStatus = ActionStatus.PREPARING;
    if (!commitAllowed) {
        tsLogger.i18NLogger.warn_coordinator_BasicAction_43(get_uid());
        actionStatus = ActionStatus.PREPARED;
        return TwoPhaseOutcome.PREPARE_NOTOK;
    }
    if (actionType == ActionType.TOP_LEVEL) {
        if (getStore() == null) {
            actionStatus = ActionStatus.ABORT_ONLY;
            internalError = true;
            return TwoPhaseOutcome.PREPARE_NOTOK;
        }
    }
    criticalStart();
    createPreparedLists();
    /*
           * Here is the start of the hard work. Walk down the pendingList
           * invoking the appropriate prepare operation. If it succeeds put the
           * record on either the preparedList or the read_only list and continue
           * until the pendingList is exhausted.
           *
           * If prepare fails on any record stop processing immediately and put
           * the offending record back on the pendingList
           */
    int p = TwoPhaseOutcome.PREPARE_OK;
    if ((actionType == ActionType.TOP_LEVEL) && (TxControl.asyncPrepare)) {
        p = async_prepare(reportHeuristics);
    } else {
        // createPreparedLists will have ensured list exists, but it may be empty
        if (pendingList.size() > 0) {
            p = doPrepare(reportHeuristics);
        }
    }
    if ((p == TwoPhaseOutcome.PREPARE_READONLY) && (pendingList.size() == 1)) {
        onePhaseCommit(reportHeuristics);
        ActionManager.manager().remove(get_uid());
        return actionStatus == ActionStatus.ABORTED ? TwoPhaseOutcome.ONE_PHASE_ERROR : TwoPhaseOutcome.PREPARE_ONE_PHASE_COMMITTED;
    }
    if ((p != TwoPhaseOutcome.PREPARE_OK) && (p != TwoPhaseOutcome.PREPARE_READONLY)) {
        if ((actionType == ActionType.NESTED) && ((preparedList.size() > 0) && (p == TwoPhaseOutcome.ONE_PHASE_ERROR))) {
            /*
                     * For the OTS we must merge those records told to commit with
                     * the parent, as the rollback invocation must come from that
                     * since they have already been told this transaction has
                     * committed!
                     */
            AbstractRecord tmpRec = preparedList.getFront();
            while (tmpRec != null) {
                merge(tmpRec);
                tmpRec = preparedList.getFront();
            }
            if (parentAction != null)
                parentAction.preventCommit();
            else {
                tsLogger.i18NLogger.warn_coordinator_BasicAction_44();
            }
        }
        criticalEnd();
        return TwoPhaseOutcome.PREPARE_NOTOK;
    }
    /*
           * Now work out whether there is any state to save. Since we should be
           * single threaded once again, there is no need to protect the lists
           * with a synchronization.
           */
    /*
           * Could do this as we traverse the lists above, but would need some
           * compound class for return values.
           */
    boolean stateToSave = false;
    RecordListIterator iter = new RecordListIterator(preparedList);
    while (((recordBeingHandled = iter.iterate()) != null)) {
        if (!stateToSave)
            stateToSave = recordBeingHandled.doSave();
        if (stateToSave)
            break;
    }
    iter = null;
    if (!stateToSave) {
        iter = new RecordListIterator(heuristicList);
        while (((recordBeingHandled = heuristicList.getFront()) != null)) {
            if (!stateToSave)
                stateToSave = recordBeingHandled.doSave();
            if (stateToSave)
                break;
        }
        iter = null;
    }
    if (actionType == ActionType.TOP_LEVEL)
        actionStatus = preparedStatus();
    else
        actionStatus = ActionStatus.PREPARED;
    if ((actionType == ActionType.TOP_LEVEL) && (stateToSave) && ((preparedList.size() > 0) || (heuristicList.size() > 0))) {
        /* Only do this if we have some records worth saving! */
        Uid u = getSavingUid();
        String tn = type();
        OutputObjectState state = new OutputObjectState(u, tn);
        if (!save_state(state, ObjectType.ANDPERSISTENT)) {
            tsLogger.i18NLogger.warn_coordinator_BasicAction_45(get_uid());
            criticalEnd();
            internalError = true;
            return TwoPhaseOutcome.PREPARE_NOTOK;
        }
        if (state.notempty()) {
            try {
                if (!transactionStore.write_committed(u, tn, state)) {
                    tsLogger.i18NLogger.warn_coordinator_BasicAction_46(get_uid());
                    criticalEnd();
                    internalError = true;
                    return TwoPhaseOutcome.PREPARE_NOTOK;
                } else
                    savedIntentionList = true;
            } catch (ObjectStoreException e) {
                criticalEnd();
                internalError = true;
                return TwoPhaseOutcome.PREPARE_NOTOK;
            }
        }
    }
    criticalEnd();
    if ((preparedList.size() == 0) && (readonlyList.size() >= 0))
        return TwoPhaseOutcome.PREPARE_READONLY;
    else
        return TwoPhaseOutcome.PREPARE_OK;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState)

Example 47 with ObjectStoreException

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

the class ObjStoreBrowser method getUids.

private Collection<Uid> getUids(String type) throws MBeanException {
    Collection<Uid> uids = new ArrayList<Uid>();
    try {
        ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), type);
        while (true) {
            Uid u = iter.iterate();
            if (u == null || Uid.nullUid().equals(u))
                break;
            uids.add(u);
        }
    } catch (ObjectStoreException | IOException e) {
        throw new MBeanException(e);
    }
    return uids;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) ObjectStoreIterator(com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator) MBeanException(javax.management.MBeanException) IOException(java.io.IOException)

Example 48 with ObjectStoreException

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

the class VolatileStore method allObjUids.

/**
 * Obtain all of the Uids for a specified type.
 *
 * @param s The type to scan for.
 * @param buff The object state in which to store the Uids
 * @param m The file type to look for (e.g., committed, shadowed).
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 */
public boolean allObjUids(String s, InputObjectState buff, int m) throws ObjectStoreException {
    if (stateTypes == null)
        throw new ObjectStoreException("Operation not supported by this implementation");
    OutputObjectState store = new OutputObjectState();
    for (Map.Entry<Uid, String> entry : stateTypes.entrySet()) if (entry.getValue().equals(s))
        packUid(store, entry.getKey());
    packUid(store, Uid.nullUid());
    buff.setBuffer(store.buffer());
    return true;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) Uid(com.arjuna.ats.arjuna.common.Uid) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 49 with ObjectStoreException

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

the class HornetqJournalStore method remove_committed.

/**
 * Remove the object's committed state.
 *
 * @param uid  The object to work on.
 * @param typeName The type of the object to work on.
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 * @throws ObjectStoreException if things go wrong.
 */
public boolean remove_committed(Uid uid, String typeName) throws ObjectStoreException {
    try {
        RecordInfo record = getContentForType(typeName).remove(uid);
        long id = (record != null ? record.id : getId(uid, typeName));
        journal.appendDeleteRecord(id, syncDeletes);
        return true;
    } catch (IllegalStateException e) {
        tsLogger.i18NLogger.warn_hornetqobjectstore_remove_state_exception(e);
        return false;
    } catch (Exception e) {
        throw new ObjectStoreException(e);
    }
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 50 with ObjectStoreException

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

the class HornetqJournalStore method read_committed.

/**
 * Read the object's committed state.
 *
 * @param uid  The object to work on.
 * @param typeName The type of the object to work on.
 * @return the state of the object.
 * @throws ObjectStoreException if things go wrong.
 */
public InputObjectState read_committed(Uid uid, String typeName) throws ObjectStoreException {
    RecordInfo record = getContentForType(typeName).get(uid);
    if (record == null) {
        return null;
    }
    // not too much of an issue as log reads are done for recovery only.
    try {
        InputBuffer inputBuffer = new InputBuffer(record.data);
        UidHelper.unpackFrom(inputBuffer);
        inputBuffer.unpackString();
        return new InputObjectState(uid, typeName, inputBuffer.unpackBytes());
    } catch (Exception e) {
        throw new ObjectStoreException(e);
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

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