Search in sources :

Example 36 with XAException

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

the class XAResourceImpl method recover.

@Override
public Xid[] recover(int flag) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    XAService xaService = getService();
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    Collection<Member> memberList = clusterService.getMembers();
    List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
    for (Member member : memberList) {
        if (member.localMember()) {
            continue;
        }
        CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
        Address address = member.getAddress();
        InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
        futureList.add(future);
    }
    HashSet<SerializableXID> xids = new HashSet<SerializableXID>();
    xids.addAll(xaService.getPreparedXids());
    for (Future<SerializableList> future : futureList) {
        try {
            SerializableList xidSet = future.get();
            for (Data xidData : xidSet) {
                SerializableXID xid = nodeEngine.toObject(xidData);
                xids.add(xid);
            }
        } catch (InterruptedException e) {
            throw new XAException(XAException.XAER_RMERR);
        } catch (MemberLeftException e) {
            logger.warning("Member left while recovering", e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
                logger.warning("Member left while recovering", e);
            } else {
                throw new XAException(XAException.XAER_RMERR);
            }
        }
    }
    return xids.toArray(new SerializableXID[xids.size()]);
}
Also used : Address(com.hazelcast.nio.Address) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeEngine(com.hazelcast.spi.NodeEngine) CollectRemoteTransactionsOperation(com.hazelcast.transaction.impl.xa.operations.CollectRemoteTransactionsOperation) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet) MemberLeftException(com.hazelcast.core.MemberLeftException) XAException(javax.transaction.xa.XAException) Data(com.hazelcast.nio.serialization.Data) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ClusterService(com.hazelcast.internal.cluster.ClusterService) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService)

Example 37 with XAException

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

the class XAResourceImpl method prepare.

@Override
public int prepare(Xid xid) throws XAException {
    List<TransactionContext> contexts = xidContextMap.get(xid);
    if (contexts == null) {
        throw new XAException("There is no TransactionContexts for the given xid: " + xid);
    }
    for (TransactionContext context : contexts) {
        Transaction transaction = getTransaction(context);
        transaction.prepare();
    }
    return XA_OK;
}
Also used : XAException(javax.transaction.xa.XAException) Transaction(com.hazelcast.transaction.impl.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 38 with XAException

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

the class ClientXACompatibilityTest method testTransactionTimeout.

@Test
public void testTransactionTimeout() throws XAException {
    boolean timeoutSet = xaResource.setTransactionTimeout(2);
    assertTrue(timeoutSet);
    xaResource.start(xid, TMNOFLAGS);
    TransactionContext context = xaResource.getTransactionContext();
    TransactionalMap<Object, Object> map = context.getMap("map");
    map.put("key", "val");
    xaResource.end(xid, TMSUCCESS);
    sleepSeconds(3);
    try {
        xaResource.commit(xid, true);
        fail();
    } catch (XAException e) {
        assertEquals(XAException.XA_RBTIMEOUT, e.errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 39 with XAException

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

the class XAResourceProxy method prepare.

@Override
public int prepare(Xid xid) throws XAException {
    List<TransactionContext> contexts = xidContextMap.get(xid);
    if (contexts == null) {
        throw new XAException("There is no TransactionContexts for the given xid: " + xid);
    }
    for (TransactionContext context : contexts) {
        XATransactionProxy transaction = getTransaction(context);
        transaction.prepare();
    }
    return XA_OK;
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 40 with XAException

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

the class XAResourceProxy 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) {
        XATransactionProxy transaction = getTransaction(context);
        transaction.commit(onePhase);
    }
    clearRemoteTransactions(xid);
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext)

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