use of javax.transaction.xa.Xid in project neo4j-mobile-android by neo4j-contrib.
the class XaLogicalLog method applyOnePhaseCommitEntry.
private void applyOnePhaseCommitEntry(LogEntry.OnePhaseCommit commit) throws IOException {
int identifier = commit.getIdentifier();
long txId = commit.getTxId();
LogEntry.Start startEntry = xidIdentMap.get(identifier);
if (startEntry == null) {
throw new IOException("Unknown xid for identifier " + identifier);
}
Xid xid = startEntry.getXid();
try {
XaTransaction xaTx = xaRm.getXaTransaction(xid);
xaTx.setCommitTxId(txId);
xaRm.injectOnePhaseCommit(xid);
registerRecoveredTransaction(txId);
} catch (XAException e) {
throw new IOException(e);
}
}
use of javax.transaction.xa.Xid in project neo4j-mobile-android by neo4j-contrib.
the class XaLogicalLog method applyTwoPhaseCommitEntry.
private void applyTwoPhaseCommitEntry(LogEntry.TwoPhaseCommit commit) throws IOException {
int identifier = commit.getIdentifier();
long txId = commit.getTxId();
LogEntry.Start startEntry = xidIdentMap.get(identifier);
if (startEntry == null) {
throw new IOException("Unknown xid for identifier " + identifier);
}
Xid xid = startEntry.getXid();
if (xid == null) {
throw new IOException("Xid null for identifier " + identifier);
}
try {
XaTransaction xaTx = xaRm.getXaTransaction(xid);
xaTx.setCommitTxId(txId);
xaRm.injectTwoPhaseCommit(xid);
registerRecoveredTransaction(txId);
} catch (XAException e) {
throw new IOException(e);
}
}
use of javax.transaction.xa.Xid in project neo4j-mobile-android by neo4j-contrib.
the class XaResourceManager method checkXids.
synchronized void checkXids() throws IOException {
msgLog.logMessage("XaResourceManager[" + name + "] sorting " + xidMap.size() + " xids");
Iterator<Xid> keyIterator = xidMap.keySet().iterator();
LinkedList<Xid> xids = new LinkedList<Xid>();
while (keyIterator.hasNext()) {
xids.add(keyIterator.next());
}
// comparator only used here
Collections.sort(xids, new Comparator<Xid>() {
public int compare(Xid o1, Xid o2) {
Integer id1 = txOrderMap.get(o1);
Integer id2 = txOrderMap.get(o2);
if (id1 == null && id2 == null) {
return 0;
}
if (id1 == null) {
return Integer.MAX_VALUE;
}
if (id2 == null) {
return Integer.MIN_VALUE;
}
return id1 - id2;
}
});
// = null;
txOrderMap.clear();
Logger logger = Logger.getLogger(tf.getClass().getName());
while (!xids.isEmpty()) {
Xid xid = xids.removeFirst();
XidStatus status = xidMap.get(xid);
TransactionStatus txStatus = status.getTransactionStatus();
XaTransaction xaTransaction = txStatus.getTransaction();
int identifier = xaTransaction.getIdentifier();
if (xaTransaction.isRecovered()) {
if (txStatus.commitStarted()) {
logger.fine("Marking 1PC [" + name + "] tx " + identifier + " as done");
log.doneInternal(identifier);
xidMap.remove(xid);
recoveredTxCount--;
} else if (!txStatus.prepared()) {
logger.fine("Rolling back non prepared tx [" + name + "]" + "txIdent[" + identifier + "]");
log.doneInternal(xaTransaction.getIdentifier());
xidMap.remove(xid);
recoveredTxCount--;
} else {
logger.fine("2PC tx [" + name + "] " + txStatus + " txIdent[" + identifier + "]");
}
}
}
checkIfRecoveryComplete();
}
use of javax.transaction.xa.Xid in project neo4j-mobile-android by neo4j-contrib.
the class XaResourceManager method fail.
synchronized void fail(XAResource xaResource, Xid xid) throws XAException {
if (xidMap.get(xid) == null) {
throw new XAException("Unknown xid[" + xid + "]");
}
Xid xidEntry = xaResourceMap.remove(xaResource);
if (xidEntry == null) {
throw new XAException("Resource[" + xaResource + "] not enlisted");
}
XidStatus status = xidMap.get(xid);
status.getTransactionStatus().markAsRollback();
}
use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
the class TestXa method testLogicalLogPrePrepared.
@Test
public void testLogicalLogPrePrepared() throws Exception {
Xid xid = new XidImpl(new byte[3], new byte[3]);
XAResource xaRes = xaCon.getXaResource();
xaRes.start(xid, XAResource.TMNOFLAGS);
long node1 = ds.nextId(Node.class);
xaCon.getNodeConsumer().createNode(node1);
long node2 = ds.nextId(Node.class);
xaCon.getNodeConsumer().createNode(node2);
long n1prop1 = ds.nextId(PropertyStore.class);
xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string1");
int relType1 = (int) ds.nextId(RelationshipType.class);
xaCon.getRelationshipTypeConsumer().addRelationshipType(relType1, "relationshiptype1");
long rel1 = ds.nextId(Relationship.class);
xaCon.getRelationshipConsumer().createRelationship(rel1, node1, node2, relType1);
long r1prop1 = ds.nextId(PropertyStore.class);
xaCon.getRelationshipConsumer().addProperty(rel1, r1prop1, index("prop1"), "string1");
xaCon.getNodeConsumer().changeProperty(node1, n1prop1, "string2");
xaCon.getRelationshipConsumer().changeProperty(rel1, r1prop1, "string2");
xaRes.end(xid, XAResource.TMSUCCESS);
xaCon.clearAllTransactions();
copyLogicalLog(path());
ds.close();
deleteLogicalLogIfExist();
renameCopiedLogicalLog(path());
ds = newNeoStore();
// ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
// lockManager, lockReleaser );
xaCon = (NeoStoreXaConnection) ds.getXaConnection();
xaRes = xaCon.getXaResource();
assertEquals(0, xaRes.recover(XAResource.TMNOFLAGS).length);
}
Aggregations