Search in sources :

Example 11 with AbstractRecord

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

the class AtomicActionTestBase method testPrepareWithLRRFailOn2PCAwareResourcePrepare.

protected void testPrepareWithLRRFailOn2PCAwareResourcePrepare() {
    OnePhase onePhase = new OnePhase();
    AbstractRecord lastResourceRecord = new LastResourceRecord(onePhase);
    AbstractRecord shutdownRecord = new ShutdownRecord(ShutdownRecord.FAIL_IN_PREPARE);
    executeTest(true, ActionStatus.ABORTED, null, shutdownRecord, lastResourceRecord);
    Assert.assertEquals(OnePhase.ROLLEDBACK, onePhase.status());
}
Also used : LastResourceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Example 12 with AbstractRecord

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

the class OrderedOnePhaseResourcesUnitTest method testOrderedOnePhase.

@Test
public void testOrderedOnePhase() throws Exception {
    System.setProperty("com.arjuna.ats.arjuna.common.propertiesFile", "jbossts-properties.xml");
    Uid firstToCommit = new Uid();
    Uid secondToCommit = new Uid();
    AtomicAction A = new AtomicAction();
    // These user defined records could wrap anything such as 1PC JDBC or messages
    OrderedOnePhaseAbstractRecord rec1 = new OrderedOnePhaseAbstractRecord(secondToCommit);
    OrderedOnePhaseAbstractRecord rec2 = new OrderedOnePhaseAbstractRecord(firstToCommit);
    A.begin();
    // Doesn't matter of the order
    A.add(rec1);
    A.add(rec2);
    // Do some work you could save some concept of the work in the abstract record save_state
    // rec1.sendMessage
    // rec2.doSQL
    // This is just so we can see the opportunity for failure recovery
    rec1.causeTransientFailure();
    // Commit, this would make sure the database (rec2) was committed first
    A.commit();
    // This shows recovery working, we should see Uid2 called again, if you had encoded some information in rec2 you could
    // maybe
    // retry the sending of a message or similar
    RecordTypeManager.manager().add(new RecordTypeMap() {

        @Override
        public int getType() {
            return OrderedOnePhaseAbstractRecord.typeId();
        }

        @Override
        public Class<? extends AbstractRecord> getRecordClass() {
            return OrderedOnePhaseAbstractRecord.class;
        }
    });
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT).addModule(new AtomicActionRecoveryModule());
    RecoveryManager.manager().scan();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) OrderedOnePhaseAbstractRecord(com.hp.mwtests.ts.arjuna.abstractrecords.OrderedOnePhaseAbstractRecord) OrderedOnePhaseAbstractRecord(com.hp.mwtests.ts.arjuna.abstractrecords.OrderedOnePhaseAbstractRecord) Test(org.junit.Test)

Example 13 with AbstractRecord

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

the class RecoveredServerTransaction method addResourceRecord.

/**
 * Allows a new Resource to be added to the transaction. Typically this is
 * used to replace a Resource that has failed and cannot be recovered on
 * it's original IOR.
 */
public void addResourceRecord(Uid rcUid, Resource r) {
    Coordinator coord = null;
    AbstractRecord corbaRec = createOTSRecord(true, r, coord, rcUid);
    addRecord(corbaRec);
}
Also used : AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) Coordinator(org.omg.CosTransactions.Coordinator)

Example 14 with AbstractRecord

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

the class StateManager method cleanup.

/**
 * Object cleanup. Attempt sane cleanup when object is deleted. Handle
 * perverse cases where multiple actions are still active as object dies.
 *
 * @param fromTerminate
 *            indicates whether this method is being called from the
 *            <code>terminate</code> method, or from elsewhere.
 * @see StateManager#terminate
 */
protected final synchronized void cleanup(boolean fromTerminate) {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("StateManager::cleanup() for object-id " + get_uid());
    }
    if (myType == ObjectType.NEITHER)
        return;
    BasicAction action = null;
    synchronized (mutex) {
        createLists();
        if (usingActions.size() > 0) {
            Enumeration e = usingActions.keys();
            while (e.hasMoreElements()) {
                action = (BasicAction) usingActions.remove(e.nextElement());
                if (action != null) {
                    /*
                         * Pop actions off using list. Don't check if action is
                         * running below so that cadavers can be created in
                         * commit protocol too.
                         */
                    AbstractRecord record = null;
                    int rStatus = AddOutcome.AR_ADDED;
                    if ((currentStatus == ObjectStatus.ACTIVE_NEW) || (currentStatus == ObjectStatus.ACTIVE)) {
                        OutputObjectState state = null;
                        tsLogger.i18NLogger.warn_StateManager_11(objectUid, type());
                        if (fromTerminate) {
                            state = new OutputObjectState(objectUid, type());
                            if (!save_state(state, myType)) {
                                tsLogger.i18NLogger.warn_StateManager_12();
                                /* force action abort */
                                action.preventCommit();
                            }
                        } else {
                            /* otherwise force action abort */
                            action.preventCommit();
                        }
                        /*
                             * This should be unnecessary - but just in case.
                             */
                        setupStore(storeRoot);
                        record = new CadaverRecord(state, participantStore, this);
                        if ((rStatus = action.add(record)) != AddOutcome.AR_ADDED)
                            record = null;
                    }
                    if (currentlyActivated && (currentStatus != ObjectStatus.DESTROYED)) {
                        record = new CadaverActivationRecord(this);
                        if ((rStatus = action.add(record)) == AddOutcome.AR_ADDED) {
                            currentStatus = ObjectStatus.PASSIVE;
                        } else {
                            tsLogger.i18NLogger.warn_StateManager_6(action.get_uid());
                            record = null;
                        }
                    }
                }
            }
        }
    }
    if (currentStatus == ObjectStatus.ACTIVE_NEW) {
        if ((myType == ObjectType.RECOVERABLE) && (objectModel == ObjectModel.SINGLE)) {
            currentStatus = ObjectStatus.ACTIVE;
        } else {
            currentStatus = ObjectStatus.PASSIVE;
        }
    }
    currentlyActivated = false;
}
Also used : Enumeration(java.util.Enumeration) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) CadaverActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord) CadaverRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord)

Example 15 with AbstractRecord

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

the class ObjStoreBrowserTest method aaTest.

public void aaTest(boolean replay) throws Exception {
    ObjStoreBrowser osb = createObjStoreBrowser();
    AtomicAction A = new AtomicAction();
    CrashRecord[] recs = { new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal), new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard) };
    // register CrashRecord record type so that it is persisted in the object store correctly
    RecordTypeManager.manager().add(new RecordTypeMap() {

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

        public int getType() {
            return RecordType.USER_DEF_FIRST0;
        }
    });
    // create an atomic action, register crash records with it and then commit
    A.begin();
    for (CrashRecord rec : recs) A.add(rec);
    int outcome = A.commit();
    // the second participant should have generated a heuristic during commit
    assertEquals(ActionStatus.H_HAZARD, outcome);
    // generate MBeans representing the atomic action that was just committed
    osb.start();
    osb.probe();
    // there should be one MBean corresponding to the AtomicAction A
    UidWrapper w = osb.findUid(A.get_uid());
    assertNotNull(w);
    OSEntryBean ai = w.getMBean();
    assertNotNull(ai);
    // the MBean should wrap an ActionBean
    assertTrue(ai instanceof ActionBean);
    ActionBean actionBean = (ActionBean) ai;
    // and there should be one MBean corresponding to the CrashRecord that got the heuristic:
    int recCount = 0;
    for (CrashRecord rec : recs) {
        LogRecordWrapper lw = actionBean.getParticipant(rec);
        if (lw != null) {
            recCount += 1;
            assertTrue(lw.isHeuristic());
            // put the participant back onto the pending list
            lw.setStatus("PREPARED");
            // and check that the record is no longer in a heuristic state
            assertFalse(lw.isHeuristic());
        }
    }
    assertEquals(1, recCount);
    if (!replay) {
        actionBean.remove();
    } else {
        /*
			* prompt the recovery manager to replay the record that was
			* moved off the heuristic list and back onto the prepared list
			*/
        rcm.scan();
    }
    /*
		 * Since the recovery scan (or explicit remove request) will have successfully removed the record from
		 * the object store another probe should cause the MBean representing the record to be unregistered
		 */
    osb.probe();
    // look up the MBean and verify that it no longer exists
    w = osb.findUid(A.get_uid());
    assertNull(w);
    osb.dump(new StringBuilder());
    osb.stop();
}
Also used : OSEntryBean(com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) ActionBean(com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean) CrashRecord(com.hp.mwtests.ts.arjuna.resources.CrashRecord) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper) LogRecordWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper)

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