Search in sources :

Example 1 with XAException

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

the class TxManager method commit.

private void commit(Thread thread, TransactionImpl tx) throws SystemException, HeuristicMixedException, HeuristicRollbackException {
    // mark as commit in log done TxImpl.doCommit()
    Throwable commitFailureCause = null;
    int xaErrorCode = -1;
    if (tx.getResourceCount() == 0) {
        tx.setStatus(Status.STATUS_COMMITTED);
    } else {
        try {
            tx.doCommit();
        } catch (XAException e) {
            xaErrorCode = e.errorCode;
            e.printStackTrace();
            log.severe("Commit failed, status=" + getTxStatusAsString(tx.getStatus()) + ", errorCode=" + xaErrorCode);
            if (tx.getStatus() == Status.STATUS_COMMITTED) {
                // this should never be
                setTmNotOk();
                throw new TransactionFailureException("commit threw exception but status is committed?", e);
            }
        } catch (Throwable t) {
            t.printStackTrace();
            commitFailureCause = t;
        }
    }
    if (tx.getStatus() != Status.STATUS_COMMITTED) {
        try {
            tx.doRollback();
        } catch (XAException e) {
            e.printStackTrace();
            log.severe("Unable to rollback transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
            setTmNotOk();
            if (commitFailureCause != null) {
                commitFailureCause.printStackTrace();
            }
            throw new HeuristicMixedException("Unable to rollback ---> error code in commit: " + xaErrorCode + " ---> error code for rollback: " + e.errorCode);
        }
        tx.doAfterCompletion();
        txThreadMap.remove(thread);
        try {
            if (tx.isGlobalStartRecordWritten()) {
                getTxLog().txDone(tx.getGlobalId());
            }
        } catch (IOException e) {
            e.printStackTrace();
            log.severe("Error writing transaction log");
            setTmNotOk();
            throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
        }
        tx.setStatus(Status.STATUS_NO_TRANSACTION);
        if (commitFailureCause == null) {
            throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + "error code was: " + xaErrorCode);
        } else {
            throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + commitFailureCause);
        }
    }
    tx.doAfterCompletion();
    txThreadMap.remove(thread);
    try {
        if (tx.isGlobalStartRecordWritten()) {
            getTxLog().txDone(tx.getGlobalId());
        }
    } catch (IOException e) {
        e.printStackTrace();
        log.severe("Error writing transaction log");
        setTmNotOk();
        throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
    }
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) IOException(java.io.IOException)

Example 2 with XAException

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

the class XaLogicalLog method done.

// [DONE][identifier]
public synchronized void done(int identifier) throws XAException {
    if (backupSlave) {
        return;
    }
    assert xidIdentMap.get(identifier) != null;
    try {
        LogIoUtils.writeDone(writeBuffer, identifier);
        xidIdentMap.remove(identifier);
    } catch (IOException e) {
        throw new XAException("Logical log unable to mark as done [" + identifier + "] " + e);
    }
}
Also used : XAException(javax.transaction.xa.XAException) IOException(java.io.IOException)

Example 3 with XAException

use of javax.transaction.xa.XAException 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)

Example 4 with XAException

use of javax.transaction.xa.XAException in project neo4j-mobile-android by neo4j-contrib.

the class XaDataSourceManager method getBranchId.

synchronized byte[] getBranchId(XAResource xaResource) {
    if (xaResource instanceof XaResource) {
        byte[] branchId = ((XaResource) xaResource).getBranchId();
        if (branchId != null) {
            return branchId;
        }
    }
    Iterator<Map.Entry<String, XaDataSource>> itr = dataSources.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry<String, XaDataSource> entry = itr.next();
        XaDataSource dataSource = entry.getValue();
        XAResource resource = dataSource.getXaConnection().getXaResource();
        try {
            if (resource.isSameRM(xaResource)) {
                String name = entry.getKey();
                return sourceIdMapping.get(name);
            }
        } catch (XAException e) {
            throw new TransactionFailureException("Unable to check is same resource", e);
        }
    }
    throw new TransactionFailureException("Unable to find mapping for XAResource[" + xaResource + "]");
}
Also used : XAResource(javax.transaction.xa.XAResource) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) XAException(javax.transaction.xa.XAException) XaResource(org.neo4j.kernel.impl.transaction.xaframework.XaResource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with XAException

use of javax.transaction.xa.XAException 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)

Aggregations

XAException (javax.transaction.xa.XAException)68 IOException (java.io.IOException)20 Xid (javax.transaction.xa.Xid)19 SystemException (javax.transaction.SystemException)14 TransactionContext (com.hazelcast.transaction.TransactionContext)12 RollbackException (javax.transaction.RollbackException)8 XAResource (javax.transaction.xa.XAResource)8 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 Test (org.junit.Test)6 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 HashMap (java.util.HashMap)5 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)4 ArrayList (java.util.ArrayList)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)3 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)3 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)3