Search in sources :

Example 6 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class RecoveryWithDefaultCacheDistTest method testNodeCrashesAfterPrepare.

public void testNodeCrashesAfterPrepare() throws Exception {
    EmbeddedTransaction t1_1 = beginAndSuspendTx(cache(1));
    prepareTransaction(t1_1);
    EmbeddedTransaction t1_2 = beginAndSuspendTx(cache(1));
    prepareTransaction(t1_2);
    EmbeddedTransaction t1_3 = beginAndSuspendTx(cache(1));
    prepareTransaction(t1_3);
    manager(1).stop();
    super.cacheManagers.remove(1);
    TestingUtil.blockUntilViewReceived(cache(0), 1, 60000, false);
    eventually(() -> {
        int size = rm(cache(0)).getInDoubtTransactionInfo().size();
        return size == 3;
    });
    List<XidImpl> inDoubtTransactions = rm(cache(0)).getInDoubtTransactions();
    assertEquals(3, inDoubtTransactions.size());
    assert inDoubtTransactions.contains(t1_1.getXid());
    assert inDoubtTransactions.contains(t1_2.getXid());
    assert inDoubtTransactions.contains(t1_3.getXid());
    configuration.transaction().transactionMode(TransactionMode.TRANSACTIONAL);
    startCacheManager();
    TestingUtil.blockUntilViewsReceived(60000, cache(0), cache(1));
    EmbeddedTransaction t1_4 = beginAndSuspendTx(cache(1));
    prepareTransaction(t1_4);
    log.trace("Before main recovery call.");
    assertPrepared(4, t1_4);
    // now second call would only return 1 prepared tx as we only go over the network once
    assertPrepared(1, t1_4);
    commitTransaction(t1_4);
    assertPrepared(0, t1_4);
    inDoubtTransactions = rm(cache(0)).getInDoubtTransactions();
    assertEquals(3, inDoubtTransactions.size());
    assert inDoubtTransactions.contains(t1_1.getXid());
    assert inDoubtTransactions.contains(t1_2.getXid());
    assert inDoubtTransactions.contains(t1_3.getXid());
    // now let's start to forget transactions
    t1_4.firstEnlistedResource().forget(t1_1.getXid());
    log.info("returned");
    eventually(() -> rm(cache(0)).getInDoubtTransactionInfo().size() == 2);
    inDoubtTransactions = rm(cache(0)).getInDoubtTransactions();
    assertEquals(2, inDoubtTransactions.size());
    assert inDoubtTransactions.contains(t1_2.getXid());
    assert inDoubtTransactions.contains(t1_3.getXid());
    t1_4.firstEnlistedResource().forget(t1_2.getXid());
    t1_4.firstEnlistedResource().forget(t1_3.getXid());
    eventually(() -> rm(cache(0)).getInDoubtTransactionInfo().size() == 0);
    assertEquals(0, rm(cache(0)).getInDoubtTransactionInfo().size());
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) XidImpl(org.infinispan.commons.tx.XidImpl)

Example 7 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class TransactionXaAdapterTmIntegrationTest method test1PcAndNonExistentXid.

public void test1PcAndNonExistentXid() {
    Configuration configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.INVALIDATION_ASYNC).build();
    TestingUtil.inject(txCoordinator, configuration);
    try {
        XidImpl doesNotExists = EmbeddedTransaction.createXid(uuid);
        xaAdapter.commit(doesNotExists, false);
        assert false;
    } catch (XAException e) {
        assertEquals(XAException.XAER_NOTA, e.errorCode);
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) XAException(javax.transaction.xa.XAException) Configuration(org.infinispan.configuration.cache.Configuration) XidImpl(org.infinispan.commons.tx.XidImpl)

Example 8 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class TransactionXaAdapterTmIntegrationTest method test1PcAndNonExistentXid2.

public void test1PcAndNonExistentXid2() {
    Configuration configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_SYNC).build();
    TestingUtil.inject(txCoordinator, configuration);
    try {
        XidImpl doesNotExists = EmbeddedTransaction.createXid(uuid);
        xaAdapter.commit(doesNotExists, true);
        assert false;
    } catch (XAException e) {
        assertEquals(XAException.XAER_NOTA, e.errorCode);
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) XAException(javax.transaction.xa.XAException) Configuration(org.infinispan.configuration.cache.Configuration) XidImpl(org.infinispan.commons.tx.XidImpl)

Example 9 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class GlobalTxTable method getPreparedTransactions.

public Collection<XidImpl> getPreparedTransactions() {
    long currentTimestamp = timeService.time();
    // remove duplicates!
    Collection<XidImpl> preparedTx = new HashSet<>();
    for (Map.Entry<CacheXid, TxState> entry : storage.entrySet()) {
        XidImpl xid = entry.getKey().getXid();
        TxState state = entry.getValue();
        if (log.isTraceEnabled()) {
            log.tracef("Checking transaction xid=%s for recovery. TimedOut?=%s, Recoverable?=%s, Status=%s", xid, state.hasTimedOut(currentTimestamp), state.isRecoverable(), state.getStatus());
        }
        if (state.hasTimedOut(currentTimestamp) && state.isRecoverable() && state.getStatus() == Status.PREPARED) {
            preparedTx.add(xid);
        }
    }
    return preparedTx;
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl) Map(java.util.Map) FunctionalMap(org.infinispan.functional.FunctionalMap) HashSet(java.util.HashSet)

Example 10 with XidImpl

use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.

the class Encoder2x method recoveryResponse.

@Override
public ByteBuf recoveryResponse(HotRodHeader header, HotRodServer server, Channel channel, Collection<XidImpl> xids) {
    ByteBuf buf = writeHeader(header, server, channel, OperationStatus.Success);
    writeUnsignedInt(xids.size(), buf);
    for (XidImpl xid : xids) {
        writeXid(xid, buf);
    }
    return buf;
}
Also used : XidImpl(org.infinispan.commons.tx.XidImpl) ExtendedByteBuf(org.infinispan.server.hotrod.transport.ExtendedByteBuf) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

XidImpl (org.infinispan.commons.tx.XidImpl)25 HashSet (java.util.HashSet)5 Map (java.util.Map)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 XAException (javax.transaction.xa.XAException)3 EmbeddedTransaction (org.infinispan.transaction.tm.EmbeddedTransaction)3 HashMap (java.util.HashMap)2 CacheException (org.infinispan.commons.CacheException)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 Response (org.infinispan.remoting.responses.Response)2 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)2 Address (org.infinispan.remoting.transport.Address)2 HotRodClient (org.infinispan.server.hotrod.test.HotRodClient)2 TxResponse (org.infinispan.server.hotrod.test.TxResponse)2 GlobalTxTable (org.infinispan.server.hotrod.tx.table.GlobalTxTable)2 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)2 RecoveryManager (org.infinispan.transaction.xa.recovery.RecoveryManager)2 ByteBuf (io.netty.buffer.ByteBuf)1 CompletionException (java.util.concurrent.CompletionException)1