Search in sources :

Example 31 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class RecoveryXids method nextScan.

/**
 * Update our tracking with results of a new recovery scan pass
 * @param trans the Xids seen during the new scan.
 */
public final void nextScan(Xid[] trans) {
    long currentTime = System.currentTimeMillis();
    // record the new information:
    if (trans != null) {
        for (Xid xid : trans) {
            XidImple xidImple = new XidImple(xid);
            if (!_whenFirstSeen.containsKey(xidImple)) {
                _whenFirstSeen.put(xidImple, currentTime);
                if (tsLogger.logger.isTraceEnabled())
                    tsLogger.logger.trace("RecoveryXids _whenFirstSeen put nextScan " + _xares + " " + currentTime + " === " + xidImple);
            }
            _whenLastSeen.put(xidImple, currentTime);
        }
    }
    // garbage collect the stale information:
    Set<XidImple> candidates = new HashSet<XidImple>(_whenFirstSeen.keySet());
    for (XidImple candidate : candidates) {
        if (_whenLastSeen.get(candidate) != currentTime) {
            // seen it previously but it's gone now so we can forget it:
            _whenFirstSeen.remove(candidate);
            if (tsLogger.logger.isTraceEnabled())
                tsLogger.logger.trace("RecoveryXids _whenFirstSeen remove nextScan" + _xares + " " + currentTime + " === " + candidate);
            _whenLastSeen.remove(candidate);
        }
    }
// gc note: transient errors in distributed RMs may cause values to disappear in one scan and then reappear later.
// under the current model we'll recover Xids only if they stick around for enough consecutive scans to
// span the safely interval. In the unlikely event that causes problems, we'll need to postpone gc for a given
// interval and take care to include only Xids seen in the most recent scan when returning candidates for recovery.
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Xid(javax.transaction.xa.Xid) HashSet(java.util.HashSet)

Example 32 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class JTAActionStatusServiceXAResourceOrphanFilter method checkXid.

@Override
public Vote checkXid(Xid xid) {
    if (xid.getFormatId() != XATxConverter.FORMAT_ID) {
        // we only care about Xids created by the JTA
        return Vote.ABSTAIN;
    }
    XidImple theXid = new XidImple(xid);
    Uid u = theXid.getTransactionUid();
    List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
    String nodeName = XAUtils.getXANodeName(xid);
    if (jtaLogger.logger.isDebugEnabled()) {
        jtaLogger.logger.debug("node name of " + xid + " is " + nodeName);
    }
    if (xaRecoveryNodes == null || xaRecoveryNodes.size() == 0 || (!xaRecoveryNodes.contains(nodeName) && !xaRecoveryNodes.contains(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES))) {
        return Vote.ABSTAIN;
    }
    String process_id = u.getHexPid();
    if (process_id.equals(LOCAL_UID.getHexPid())) {
        ActionStatusService ass = new ActionStatusService();
        int transactionStatus = ass.getTransactionStatus("", u.stringForm());
        if (transactionStatus == ActionStatus.ABORTED) {
            // Known about and completed
            return Vote.ROLLBACK;
        } else if (transactionStatus == ActionStatus.NO_ACTION) {
            // Not used by current implementation but possible in protocol
            return Vote.ABSTAIN;
        } else {
            // Local transaction in-flight
            return Vote.LEAVE_ALONE;
        }
    } else {
        // For a different JVM
        return Vote.ABSTAIN;
    }
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) ActionStatusService(com.arjuna.ats.arjuna.recovery.ActionStatusService)

Example 33 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class SubordinationManagerXAResourceOrphanFilter method checkXid.

@Override
public Vote checkXid(Xid xid) {
    if (xid.getFormatId() != XATxConverter.FORMAT_ID) {
        // we only care about Xids created by the JTA
        return Vote.ABSTAIN;
    }
    List<String> _xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
    if (_xaRecoveryNodes == null || _xaRecoveryNodes.size() == 0) {
        jtaLogger.i18NLogger.info_recovery_noxanodes();
        return Vote.ABSTAIN;
    }
    String nodeName = XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID());
    if (jtaLogger.logger.isDebugEnabled()) {
        jtaLogger.logger.debug("subordinate node name of " + xid + " is " + nodeName);
    }
    if (!_xaRecoveryNodes.contains(nodeName)) {
        // It either doesn't have a subordinate node name or isn't for this server
        return Vote.ABSTAIN;
    }
    if (!getSubordinateAtomicActionRecoveryModule().isRecoveryScanCompletedWithoutError()) {
        // Xid alone
        return Vote.LEAVE_ALONE;
    }
    XidImple theXid = new XidImple(xid);
    SubordinateTransaction importedTransaction = null;
    try {
        importedTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(theXid);
    } catch (XAException e) {
        return Vote.LEAVE_ALONE;
    }
    if (importedTransaction != null) {
        return Vote.LEAVE_ALONE;
    } else {
        return Vote.ROLLBACK;
    }
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) XAException(javax.transaction.xa.XAException) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)

Example 34 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class XAResourceRecordUnitTest method testRecovery.

@Test
public void testRecovery() throws Exception {
    DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
    Object[] params = new Object[1];
    params[XAResourceRecord.XACONNECTION] = rc;
    DummyXAResourceRecord xares = new DummyXAResourceRecord(new TransactionImple(), new DummyXA(false), new XidImple(new Uid()), params);
    assertEquals(xares.getRecoveryCoordinator(), null);
    assertEquals(xares.recover(), XARecoveryResource.FAILED_TO_RECOVER);
    xares.setXAResource(null);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) DummyRecoverableXAConnection(com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection) Uid(com.arjuna.ats.arjuna.common.Uid) DummyXA(com.hp.mwtests.ts.jta.jts.common.DummyXA) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) Test(org.junit.Test)

Example 35 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class XAResourceRecordUnitTest method testPackUnpack.

@Test
public void testPackUnpack() throws Exception {
    ThreadActionData.purgeActions();
    OTSImpleManager.current().contextManager().purgeActions();
    XAResourceRecord xares;
    DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
    Object[] params = new Object[1];
    params[XAResourceRecord.XACONNECTION] = rc;
    xares = new XAResourceRecord(new TransactionImple(), new DummyXA(false), new XidImple(new Uid()), params);
    OutputObjectState os = new OutputObjectState();
    assertTrue(xares.saveState(os));
    xares = new XAResourceRecord();
    InputObjectState is = new InputObjectState(os);
    assertTrue(xares.restoreState(is));
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) DummyRecoverableXAConnection(com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) DummyXA(com.hp.mwtests.ts.jta.jts.common.DummyXA) XAResourceRecord(com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Aggregations

XidImple (com.arjuna.ats.jta.xa.XidImple)90 Uid (com.arjuna.ats.arjuna.common.Uid)71 Test (org.junit.Test)71 Xid (javax.transaction.xa.Xid)35 XAException (javax.transaction.xa.XAException)28 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)27 Transaction (javax.transaction.Transaction)16 XATerminator (javax.resource.spi.XATerminator)15 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)12 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)10 IOException (java.io.IOException)10 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)9 XAOnePhaseResource (com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource)9 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)9 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)8 SampleOnePhaseResource (com.hp.mwtests.ts.jta.common.SampleOnePhaseResource)8 RollbackException (javax.transaction.RollbackException)8 SystemException (javax.transaction.SystemException)8 XAResource (javax.transaction.xa.XAResource)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7