Search in sources :

Example 21 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class XAResourceImpl method commit.

@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
    List<TransactionContext> contexts = xidContextMap.remove(xid);
    if (contexts == null && onePhase) {
        throw new XAException("There is no TransactionContexts for the given xid: " + xid);
    }
    if (contexts == null) {
        finalizeTransactionRemotely(xid, true);
        return;
    }
    for (TransactionContext context : contexts) {
        Transaction transaction = getTransaction(context);
        if (onePhase) {
            transaction.prepare();
        }
        transaction.commit();
    }
    clearRemoteTransactions(xid);
}
Also used : XAException(javax.transaction.xa.XAException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 22 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class XAResourceImpl method finalizeTransactionRemotely.

private void finalizeTransactionRemotely(Xid xid, boolean isCommit) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();
    SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    Data xidData = nodeEngine.toData(serializableXID);
    int partitionId = partitionService.getPartitionId(xidData);
    FinalizeRemoteTransactionOperation operation = new FinalizeRemoteTransactionOperation(xidData, isCommit);
    InternalCompletableFuture<Integer> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
    Integer errorCode;
    try {
        errorCode = future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
    if (errorCode != null) {
        throw new XAException(errorCode);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) XAException(javax.transaction.xa.XAException) IPartitionService(com.hazelcast.spi.partition.IPartitionService) Data(com.hazelcast.nio.serialization.Data) OperationService(com.hazelcast.spi.OperationService) FinalizeRemoteTransactionOperation(com.hazelcast.transaction.impl.xa.operations.FinalizeRemoteTransactionOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) MemberLeftException(com.hazelcast.core.MemberLeftException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ExecutionException(java.util.concurrent.ExecutionException) XAException(javax.transaction.xa.XAException)

Example 23 with XAException

use of javax.transaction.xa.XAException in project aries by apache.

the class NamedXAResourceImpl method handleException.

private XAException handleException(Exception e) throws XAException {
    if (e instanceof XAException) {
        XAException xae = (XAException) e;
        if (xae.errorCode == 0) {
            if (original) {
                // We are the originally enlisted resource, and will play some tricks to attempt recovery 
                if (transactionManager.getNamedResource(name) == null) {
                    logger.error("The XA resource named {} threw an XAException but did not set the error code. There is also no RecoverableXAResource available with the name {}. It is not possible to recover from this situation and so the transaction will have to be resolved by an operator.", name, name, xae);
                    xae.errorCode = XAException.XAER_RMERR;
                } else {
                    logger.warn("The XA resource named {} threw an XAException but did not set the error code. Changing it to be an \"RM_FAIL\" to permit recovery attempts", name, xae);
                    xae.errorCode = XAException.XAER_RMFAIL;
                }
            } else {
                logger.warn("The XA resource named {} threw an XAException but did not set the error code. Recovery has already been attempted for this resource and it has not been possible to recover from this situation. The transaction will have to be resolved by an operator.", name, xae);
                xae.errorCode = XAException.XAER_RMERR;
            }
        }
        return xae;
    } else {
        logger.warn("The recoverable XA resource named {} threw an Exception which is not permitted by the interface. Changing it to be a \"Resource Manager Error\" XAException which prevents recovery", name, e);
        XAException xaException = new XAException(XAException.XAER_RMERR);
        xaException.initCause(e);
        return xaException;
    }
}
Also used : XAException(javax.transaction.xa.XAException)

Example 24 with XAException

use of javax.transaction.xa.XAException in project aries by apache.

the class TransactionContextImpl method finish.

@Override
public void finish() {
    if (!resources.isEmpty()) {
        XAResource localResource = new LocalXAResourceImpl();
        try {
            currentTransaction.enlistResource(localResource);
        } catch (Exception e) {
            safeSetRollbackOnly();
            recordFailure(e);
            try {
                localResource.rollback(null);
            } catch (XAException e1) {
                recordFailure(e1);
            }
        }
    }
    try {
        TxListener listener = new TxListener();
        try {
            transactionManager.registerInterposedSynchronization(listener);
            if (getRollbackOnly()) {
                // GERONIMO-4449 says that we get no beforeCompletion 
                // callback for rollback :(
                listener.beforeCompletion();
                transactionManager.rollback();
            } else {
                transactionManager.commit();
            }
        } catch (Exception e) {
            recordFailure(e);
        }
    } finally {
        try {
            transactionManager.resume(oldTran);
        } catch (Exception e) {
            recordFailure(e);
        }
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) TransactionException(org.osgi.service.transaction.control.TransactionException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException)

Example 25 with XAException

use of javax.transaction.xa.XAException in project geode by apache.

the class XAResourceAdaptor method testXAExceptionRollback.

@Test
public void testXAExceptionRollback() throws Exception {
    utx.begin();
    Thread thread = Thread.currentThread();
    Transaction txn = (Transaction) tm.getTransactionMap().get(thread);
    txn.registerSynchronization(new Synchronization() {

        public void beforeCompletion() {
            fail("Notify Before Completion should not be called in rollback");
        }

        public void afterCompletion(int status) {
            assertTrue(status == Status.STATUS_ROLLEDBACK);
        }
    });
    txn.enlistResource(new XAResourceAdaptor() {

        public void commit(Xid arg0, boolean arg1) throws XAException {
        }

        public void rollback(Xid arg0) throws XAException {
            throw new XAException(6);
        }
    });
    try {
        utx.rollback();
        fail("The rollback should have thrown SystemException");
    } catch (SystemException expected) {
    // success
    }
    assertTrue(tm.getGlobalTransactionMap().isEmpty());
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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