Search in sources :

Example 6 with Xid

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);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) IOException(java.io.IOException)

Example 7 with Xid

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);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) IOException(java.io.IOException)

Example 8 with Xid

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();
}
Also used : Xid(javax.transaction.xa.Xid) Logger(java.util.logging.Logger) StringLogger(org.neo4j.kernel.impl.util.StringLogger) LinkedList(java.util.LinkedList)

Example 9 with Xid

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();
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException)

Example 10 with Xid

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);
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Aggregations

Xid (javax.transaction.xa.Xid)63 Test (org.junit.Test)23 XAException (javax.transaction.xa.XAException)19 IOException (java.io.IOException)16 XAResource (javax.transaction.xa.XAResource)13 XidImpl (org.neo4j.kernel.impl.transaction.XidImpl)11 LinkedList (java.util.LinkedList)10 InOrder (org.mockito.InOrder)6 HashMap (java.util.HashMap)5 RelationshipType (org.neo4j.graphdb.RelationshipType)5 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)4 ArrayList (java.util.ArrayList)4 RollbackException (javax.transaction.RollbackException)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)4 TransactionContext (com.hazelcast.transaction.TransactionContext)3 SerializableXID (com.hazelcast.transaction.impl.xa.SerializableXID)3 SystemException (javax.transaction.SystemException)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 HashSet (java.util.HashSet)2