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.
}
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;
}
}
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;
}
}
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);
}
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));
}
Aggregations