Search in sources :

Example 1 with Xid

use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.

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 2 with Xid

use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.

the class LogIoUtils method readTxStartEntry.

private static LogEntry.Start readTxStartEntry(ByteBuffer buf, ReadableByteChannel channel) throws IOException, ReadPastEndException {
    byte globalIdLength = readNextByte(buf, channel);
    byte branchIdLength = readNextByte(buf, channel);
    byte[] globalId = new byte[globalIdLength];
    readIntoBufferAndFlip(ByteBuffer.wrap(globalId), channel, globalIdLength);
    byte[] branchId = new byte[branchIdLength];
    readIntoBufferAndFlip(ByteBuffer.wrap(branchId), channel, branchIdLength);
    int identifier = readNextInt(buf, channel);
    int formatId = readNextInt(buf, channel);
    // re-create the transaction
    Xid xid = new XidImpl(globalId, branchId, formatId);
    return new LogEntry.Start(xid, identifier, -1);
}
Also used : Xid(javax.transaction.xa.Xid) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl)

Example 3 with Xid

use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.

the class XaLogicalLog method applyDoneEntry.

private void applyDoneEntry(LogEntry.Done done) throws IOException {
    // get the tx identifier
    int identifier = done.getIdentifier();
    LogEntry.Start entry = xidIdentMap.get(identifier);
    if (entry == null) {
        throw new IOException("Unknown xid for identifier " + identifier);
    }
    Xid xid = entry.getXid();
    xaRm.pruneXid(xid);
    xidIdentMap.remove(identifier);
    recoveredTxMap.remove(identifier);
}
Also used : Xid(javax.transaction.xa.Xid) IOException(java.io.IOException)

Example 4 with Xid

use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.

the class XaLogicalLog method applyPrepareEntry.

private void applyPrepareEntry(LogEntry.Prepare prepareEntry) throws IOException {
    // get the tx identifier
    int identifier = prepareEntry.getIdentifier();
    LogEntry.Start entry = xidIdentMap.get(identifier);
    if (entry == null) {
        throw new IOException("Unknown xid for identifier " + identifier);
    }
    Xid xid = entry.getXid();
    if (xaRm.injectPrepare(xid)) {
        // read only we can remove
        xidIdentMap.remove(identifier);
        recoveredTxMap.remove(identifier);
    }
}
Also used : Xid(javax.transaction.xa.Xid) IOException(java.io.IOException)

Example 5 with Xid

use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.

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);
        msgLog.logMessage("Injected two phase commit, txId=" + commit.getTxId(), true);
    } catch (XAException e) {
        e.printStackTrace();
        throw new IOException(e.getMessage());
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) IOException(java.io.IOException)

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