Search in sources :

Example 1 with AtomicAction

use of com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction in project narayana by jbosstm.

the class JTATransactionLogXAResourceOrphanFilter method transactionLog.

/**
 * Is there a log file for this transaction?
 *
 * @param xid the transaction to check.
 *
 * @return <code>boolean</code>true if there is a log file,
 *         <code>false</code> if there isn't.
 * @throws ObjectStoreException If there is a problem accessing the object store
 * @throws IOException In case the data from the object store is corrupted
 */
private boolean transactionLog(Xid xid) throws ObjectStoreException, IOException {
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    String transactionType = new AtomicAction().type();
    XidImple theXid = new XidImple(xid);
    Uid u = theXid.getTransactionUid();
    if (jtaLogger.logger.isDebugEnabled()) {
        jtaLogger.logger.debug("Checking whether Xid " + theXid + " exists in ObjectStore.");
    }
    if (!u.equals(Uid.nullUid())) {
        if (jtaLogger.logger.isDebugEnabled()) {
            jtaLogger.logger.debug("Looking for " + u + " and " + transactionType);
        }
        if (containsCommitMarkableResourceRecord(u) || recoveryStore.currentState(u, transactionType) != StateStatus.OS_UNKNOWN) {
            if (jtaLogger.logger.isDebugEnabled()) {
                jtaLogger.logger.debug("Found record for " + theXid);
            }
            return true;
        } else {
            if (jtaLogger.logger.isDebugEnabled()) {
                jtaLogger.logger.debug("No record found for " + theXid);
            }
        }
    } else {
        jtaLogger.i18NLogger.info_recovery_notaxid(XAHelper.xidToString(xid));
    }
    return false;
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) AtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction) Uid(com.arjuna.ats.arjuna.common.Uid) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore)

Example 2 with AtomicAction

use of com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testRecoverFromMultipleXAResourceRecovery.

@Test
public void testRecoverFromMultipleXAResourceRecovery() throws Exception {
    // Make sure the file doesn't exist
    assertFalse(new File("XARR.txt").exists());
    ArrayList<String> r = new ArrayList<String>();
    AtomicAction aa = new AtomicAction();
    aa.begin();
    assertEquals(AddOutcome.AR_ADDED, aa.add(new XAResourceRecord(null, new XARRTestResource(), new XidImple(aa), null)));
    Class c = BasicAction.class;
    Method method = c.getDeclaredMethod("prepare", boolean.class);
    method.setAccessible(true);
    int result = (Integer) method.invoke(aa, new Object[] { true });
    assertEquals(result, TwoPhaseOutcome.PREPARE_OK);
    // Make sure the file exists
    assertTrue(new File("XARR.txt").exists());
    // AtomicActionRecoveryModule aaRecoveryModule = new AtomicActionRecoveryModule();
    // aaRecoveryModule.periodicWorkFirstPass();
    // aaRecoveryModule.periodicWorkSecondPass();
    RecordTypeManager.manager().add(new RecordTypeMap() {

        @SuppressWarnings("unchecked")
        public Class getRecordClass() {
            return XAResourceRecord.class;
        }

        public int getType() {
            return RecordType.JTA_RECORD;
        }
    });
    List<String> xarn = new ArrayList<String>();
    xarn.add(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES);
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xarn);
    XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    Field safetyIntervalMillis = RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
    safetyIntervalMillis.setAccessible(true);
    safetyIntervalMillis.set(null, 0);
    xaRecoveryModule.addXAResourceRecoveryHelper(new XARROne());
    xaRecoveryModule.addXAResourceRecoveryHelper(new XARRTwo());
    xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter());
    xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter());
    RecoveryManager.manager().addModule(xaRecoveryModule);
    // This is done rather than using the AtomicActionRecoveryModule as the transaction is inflight
    RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(aa.get_uid(), ActionStatus.COMMITTED);
    rcvAtomicAction.replayPhase2();
    // The XARM would execute next
    xaRecoveryModule.periodicWorkFirstPass();
    xaRecoveryModule.periodicWorkSecondPass();
    // Make sure the file doesn't exist
    assertFalse(new File("XARR.txt").exists());
    aa.abort();
}
Also used : JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) ArrayList(java.util.ArrayList) AtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) Field(java.lang.reflect.Field) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) XidImple(com.arjuna.ats.jta.xa.XidImple) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) Method(java.lang.reflect.Method) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) File(java.io.File) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

AtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction)2 XidImple (com.arjuna.ats.jta.xa.XidImple)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)1 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)1 RecoverAtomicAction (com.arjuna.ats.arjuna.recovery.RecoverAtomicAction)1 JTANodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1