Search in sources :

Example 21 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class AtomicActionTestBase method testPrepareWithLRRSuccess.

protected void testPrepareWithLRRSuccess() {
    OnePhase onePhase = new OnePhase();
    AbstractRecord lastResourceRecord = new LastResourceRecord(onePhase);
    AbstractRecord basicRecord = new BasicRecord();
    executeTest(true, ActionStatus.COMMITTED, null, basicRecord, lastResourceRecord);
    Assert.assertEquals(OnePhase.COMMITTED, onePhase.status());
}
Also used : LastResourceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Example 22 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class EditableAtomicAction method deleteHeuristicParticipant.

/**
 * Delete a heuristic participant from the list.
 */
public void deleteHeuristicParticipant(int index) throws IndexOutOfBoundsException {
    if ((index < 0) || (index >= super.heuristicList.size()))
        throw new IndexOutOfBoundsException();
    else {
        if (super.heuristicList.size() == 0)
            throw new IndexOutOfBoundsException();
        RecordListIterator iter = new RecordListIterator(super.heuristicList);
        AbstractRecord rec = iter.iterate();
        for (int i = 0; i < index; i++) rec = iter.iterate();
        super.heuristicList.remove(rec);
        if (super.heuristicList.size() == 0)
            super.setHeuristicDecision(TwoPhaseOutcome.FINISH_OK);
        // if the log is not entry this call will delete the log automatically.
        super.updateState();
    }
}
Also used : RecordListIterator(com.arjuna.ats.arjuna.coordinator.RecordListIterator) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Example 23 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class TransactionImple method enlistResource.

public boolean enlistResource(XAResource xaRes, Object[] params) throws RollbackException, IllegalStateException, javax.transaction.SystemException {
    if (jtaLogger.logger.isTraceEnabled()) {
        jtaLogger.logger.trace("TransactionImple.enlistResource ( " + xaRes + " )");
    }
    if (xaRes == null)
        throw new javax.transaction.SystemException("TransactionImple.enlistResource - " + jtaLogger.i18NLogger.get_transaction_arjunacore_nullres());
    int status = getStatus();
    switch(status) {
        case javax.transaction.Status.STATUS_MARKED_ROLLBACK:
            throw new RollbackException("TransactionImple.enlistResource - " + jtaLogger.i18NLogger.get_transaction_arjunacore_invalidstate());
        case javax.transaction.Status.STATUS_ACTIVE:
            break;
        default:
            throw new IllegalStateException(jtaLogger.i18NLogger.get_transaction_arjunacore_inactive());
    }
    XAModifier theModifier = null;
    if (params != null) {
        if (params.length >= XAMODIFIER + 1) {
            if (params[XAMODIFIER] instanceof XAModifier) {
                theModifier = (XAModifier) params[XAMODIFIER];
            }
        }
    }
    try {
        /*
			 * For each transaction we maintain a list of resources registered
			 * with it. Each element on this list also contains a list of
			 * threads which have registered this resource, and what their XID
			 * was for that registration.
			 */
        TxInfo info = null;
        try {
            synchronized (this) {
                info = (TxInfo) _resources.get(xaRes);
                if (info == null) {
                    /*
						 * Null info means it's not in the main resources list,
						 * but may be in the duplicates.
						 */
                    info = (TxInfo) _duplicateResources.get(xaRes);
                }
            }
            if (info != null) {
                switch(info.getState()) {
                    case TxInfo.ASSOCIATION_SUSPENDED:
                        {
                            /*
						 * Have seen resource before, so do a resume. The
						 * Resource instance will still be registered with the
						 * transaction though.
						 */
                            int xaStartResume = ((theModifier == null) ? XAResource.TMRESUME : theModifier.xaStartParameters(XAResource.TMRESUME));
                            xaRes.start(info.xid(), xaStartResume);
                            info.setState(TxInfo.ASSOCIATED);
                            synchronized (this) {
                                _suspendCount--;
                            }
                            // already registered resource with this
                            return true;
                        // transaction!
                        }
                    case TxInfo.ASSOCIATED:
                        {
                            return true;
                        }
                    case TxInfo.NOT_ASSOCIATED:
                        {
                            /*
						 * Resource was associated, but was presumably delisted.
						 */
                            int xaStartJoin = ((theModifier == null) ? XAResource.TMJOIN : theModifier.xaStartParameters(XAResource.TMJOIN));
                            xaRes.start(info.xid(), xaStartJoin);
                            info.setState(TxInfo.ASSOCIATED);
                            return true;
                        }
                    default:
                        {
                            throw new IllegalStateException("TransactionImple.enlistResource - " + jtaLogger.i18NLogger.get_transaction_arjunacore_illresstate() + ":" + info.getState());
                        }
                }
            }
        } catch (IllegalStateException ex) {
            // we threw it in the first place
            throw ex;
        } catch (XAException exp) {
            if (info != null)
                info.setState(TxInfo.FAILED);
            jtaLogger.i18NLogger.warn_transaction_arjunacore_enlisterror("TransactionImple.enlistResource", XAHelper.printXAErrorCode(exp));
            return false;
        }
        // if (threadIsActive(xaRes))
        // return true; // this thread has already registered a resource for
        // this db
        /*
			 * We definitely haven't seen this specific resource instance
			 * before, but that doesn't mean that we haven't seen the RM it is
			 * connected to.
			 */
        Xid xid = null;
        TxInfo existingRM = isNewRM(xaRes);
        if (existingRM == null) {
            /*
				 * New RM, so create xid with new branch.
				 */
            boolean branchRequired = true;
            synchronized (this) {
                if (// first ever, so no need for
                _resources.size() == 0) // branch
                {
                    // branchRequired = false;
                    branchRequired = true;
                }
            }
            xid = createXid(branchRequired, theModifier, xaRes);
            boolean associatedWork = false;
            int retry = 20;
            while (!associatedWork) {
                try {
                    if (_xaTransactionTimeoutEnabled) {
                        int timeout = _theTransaction.getTimeout();
                        if (timeout > 0) {
                            try {
                                xaRes.setTransactionTimeout(timeout);
                            } catch (XAException te) {
                                jtaLogger.i18NLogger.warn_transaction_arjunacore_timeouterror("TransactionImple.enlistResource", XAHelper.xidToString(xid), XAHelper.printXAErrorCode(te), te);
                            }
                        }
                    }
                    int xaStartNormal = ((theModifier == null) ? XAResource.TMNOFLAGS : theModifier.xaStartParameters(XAResource.TMNOFLAGS));
                    // Pay attention now, this bit is hairy. We need to add a new AbstractRecord (XAResourceRecord)
                    // to the BasicAction, which will thereafter drive its completion. However, the transaction
                    // core is not directly XA aware, so it's our job to start the XAResource. Problem is, if
                    // adding the record fails, BasicAction will never end the resource via the XAResourceRecord,
                    // so we must do so directly.  start may fail due to dupl xid or other reason, and transactions
                    // may rollback async, for which reasons we can't call add before start.
                    // The xid will change on each pass of the loop, so we need to create a new record on each pass.
                    // The add will fail in the case of multiple last resources being disallowed
                    // see JBTM-362 and JBTM-363
                    AbstractRecord abstractRecord = createRecord(xaRes, params, xid);
                    if (abstractRecord != null) {
                        xaRes.start(xid, xaStartNormal);
                        if (_theTransaction.add(abstractRecord) == AddOutcome.AR_ADDED) {
                            _resources.put(xaRes, new TxInfo(xid));
                            // dive out, no need to set associatedWork = true;
                            return true;
                        } else {
                            // we called start on the resource, but _theTransaction did not accept it.
                            // we therefore have a mess which we must now clean up by ensuring the start is undone:
                            abstractRecord.topLevelAbort();
                        }
                    }
                    // if we get to here, something other than a failure of xaRes.start probably went wrong.
                    // so we don't loop and retry, we just give up.
                    markRollbackOnly();
                    return false;
                } catch (XAException e) {
                    if ((e.errorCode == XAException.XAER_DUPID) || (e.errorCode == XAException.XAER_RMERR)) {
                        if (retry > 0)
                            xid = createXid(true, theModifier, xaRes);
                        retry--;
                    } else {
                        /*
							 * Can't do start, so set transaction to rollback
							 * only.
							 */
                        jtaLogger.i18NLogger.warn_transaction_arjunacore_enliststarterror("TransactionImple.enlistResource", XAHelper.xidToString(xid), XAHelper.printXAErrorCode(e), e);
                        markRollbackOnly();
                        throw e;
                    }
                    if (retry < 0) {
                        jtaLogger.i18NLogger.warn_transaction_arjunacore_enliststarterror("TransactionImple.enlistResource", XAHelper.xidToString(xid), XAHelper.printXAErrorCode(e), e);
                        markRollbackOnly();
                        throw new javax.transaction.SystemException("TransactionImple.enlistResource - XAResource.start " + jtaLogger.i18NLogger.get_transaction_arjunacore_couldnotregister() + ": " + xid);
                    }
                }
            }
        } else {
            /*
				 * Have seen this RM before, so ignore this instance. The first
				 * registered RM instance will be used to drive the transaction
				 * completion. We add it to the duplicateResource list so we can
				 * delist it correctly later though.
				 */
            /*
				 * Re-create xid.
				 */
            xid = existingRM.xid();
            try {
                int xaStartJoin = ((theModifier == null) ? XAResource.TMJOIN : theModifier.xaStartParameters(XAResource.TMJOIN));
                xaRes.start(xid, xaStartJoin);
            } catch (XAException ex) {
                jtaLogger.i18NLogger.warn_transaction_arjunacore_xastart("TransactionImple.enlistResource - xa_start ", XAHelper.xidToString(xid), XAHelper.printXAErrorCode(ex), ex);
                markRollbackOnly();
                throw ex;
            }
            /*
				 * Add to duplicate resources list so we can keep track of it
				 * (particularly if we later have to delist).
				 */
            _duplicateResources.put(xaRes, new TxInfo(xid));
            return true;
        }
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        /*
			 * Some exceptional condition arose and we probably could not enlist
			 * the resouce. So, for safety mark the transaction as rollback
			 * only.
			 */
        markRollbackOnly();
        return false;
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) TxInfo(com.arjuna.ats.internal.jta.xa.TxInfo) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) XAModifier(com.arjuna.ats.jta.xa.XAModifier) RollbackException(javax.transaction.RollbackException) InactiveTransactionException(com.arjuna.ats.jta.exceptions.InactiveTransactionException) RollbackException(javax.transaction.RollbackException) InvalidTerminationStateException(com.arjuna.ats.jta.exceptions.InvalidTerminationStateException) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException)

Example 24 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class JTSObjStoreBrowserTest method startTest.

// create 2 participants, start the action and enlist both participants
private ExtendedCrashRecord[] startTest(TwoPhaseCoordinator A) throws Exception {
    ThreadActionData.purgeActions();
    ExtendedCrashRecord[] recs = { new ExtendedCrashRecord(ExtendedCrashRecord.CrashLocation.NoCrash, ExtendedCrashRecord.CrashType.Normal), new ExtendedCrashRecord(ExtendedCrashRecord.CrashLocation.CrashInCommit, ExtendedCrashRecord.CrashType.HeuristicHazard) };
    RecordTypeManager.manager().add(new RecordTypeMap() {

        public Class<? extends AbstractRecord> getRecordClass() {
            return ExtendedCrashRecord.class;
        }

        public int getType() {
            return RecordType.USER_DEF_FIRST0;
        }
    });
    A.start();
    for (ExtendedCrashRecord rec : recs) A.add(rec);
    return recs;
}
Also used : ExtendedCrashRecord(com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass)

Example 25 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class ArjunaTransactionImple method createOTSRecord.

protected final AbstractRecord createOTSRecord(boolean propagate, Resource resource, Coordinator coord, Uid recCoordUid) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::createOTSRecord for " + get_uid());
    }
    /*
		 * If the resource is an ArjunaOTS.OTSAbstractRecord or an
		 * ArjunaOTS.ArjunaSubtranAwareResource then we can do better record
		 * manipulation, and proper nested actions.
		 *
		 * Based on the type of resource we create the right abstract record to
		 * handle it, rather than a single abstract record which switches
		 * protocols internally.
		 */
    ArjunaSubtranAwareResource absRec = null;
    AbstractRecord corbaRec = null;
    if (resource != null) {
        try {
            absRec = com.arjuna.ArjunaOTS.ArjunaSubtranAwareResourceHelper.narrow(resource);
            if (absRec == null)
                throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
        } catch (Exception e) {
            // can't be an ArjunaOTS.ArjunaSubtranAwareResource
            absRec = null;
        }
    }
    if (absRec == null) {
        corbaRec = new ResourceRecord(propagate, resource, coord, recCoordUid, this);
    } else {
        Uid u = null;
        OTSAbstractRecord otsRec;
        try {
            otsRec = com.arjuna.ArjunaOTS.OTSAbstractRecordHelper.narrow(absRec);
            if (otsRec == null)
                throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
        } catch (Exception e) {
            otsRec = null;
        }
        if (otsRec != null) {
            try {
                u = new Uid(otsRec.uid());
            } catch (Exception e) {
                u = null;
            }
            if (u == null) {
                jtsLogger.i18NLogger.warn_orbspecific_coordinator_uidfail("ArjunaTransactionImple.createOTSRecord");
            }
        }
        if (u == null)
            u = new Uid();
        corbaRec = new ExtendedResourceRecord(propagate, u, absRec, coord, recCoordUid, this);
        otsRec = null;
        absRec = null;
        u = null;
    }
    return corbaRec;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) ArjunaSubtranAwareResource(com.arjuna.ArjunaOTS.ArjunaSubtranAwareResource) OTSAbstractRecord(com.arjuna.ArjunaOTS.OTSAbstractRecord) OTSAbstractRecord(com.arjuna.ArjunaOTS.OTSAbstractRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) BAD_PARAM(org.omg.CORBA.BAD_PARAM) ResourceRecord(com.arjuna.ats.internal.jts.resources.ResourceRecord) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) SystemException(org.omg.CORBA.SystemException)

Aggregations

AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)31 RecordListIterator (com.arjuna.ats.arjuna.coordinator.RecordListIterator)10 Coordinator (org.omg.CosTransactions.Coordinator)5 RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)4 OTSAbstractRecord (com.arjuna.ArjunaOTS.OTSAbstractRecord)3 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 Uid (com.arjuna.ats.arjuna.common.Uid)3 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)3 LastResourceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord)3 BAD_PARAM (org.omg.CORBA.BAD_PARAM)3 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)2 IOException (java.io.IOException)2 Enumeration (java.util.Enumeration)2 Test (org.junit.Test)2 SystemException (org.omg.CORBA.SystemException)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 UNKNOWN (org.omg.CORBA.UNKNOWN)2 Inactive (org.omg.CosTransactions.Inactive)2 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)2 SubtransactionsUnavailable (org.omg.CosTransactions.SubtransactionsUnavailable)2