Search in sources :

Example 6 with GridNearTxFinishRequest

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest in project ignite by apache.

the class TxRollbackOnTimeoutTest method testRollbackOnNearNodeLeft.

/**
 * Tests that transactions from near node that has left are rolled back on server nodes.
 *
 * @throws Exception If failed.
 */
@Test
public void testRollbackOnNearNodeLeft() throws Exception {
    Ignite client = startClient();
    Integer pk0 = primaryKey(grid(0).cache(CACHE_NAME));
    Integer pk1 = primaryKey(grid(1).cache(CACHE_NAME));
    CountDownLatch locked = new CountDownLatch(1);
    CountDownLatch blocked = new CountDownLatch(1);
    IgniteInternalFuture<Void> fut = runAsync(new Callable<Void>() {

        @Override
        public Void call() {
            try (Transaction tx0 = client.transactions().txStart()) {
                client.cache(CACHE_NAME).put(pk0, 0);
                locked.countDown();
                awaitQuiet(blocked);
                tx0.commit();
            } catch (Exception ignored) {
            // No-op.
            }
            return null;
        }
    });
    IgniteInternalFuture fut2 = runAsync(new Runnable() {

        @Override
        public void run() {
            try (Transaction tx1 = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 1000, 0)) {
                awaitQuiet(locked);
                client.cache(CACHE_NAME).put(pk1, 1);
                spi(client).blockMessages((node, msg) -> msg instanceof GridNearTxFinishRequest);
                spi(grid(0)).blockMessages((node, msg) -> msg instanceof GridNearLockResponse);
                client.cache(CACHE_NAME).put(pk0, 1);
                fail();
            } catch (Exception e) {
                assertTrue(X.hasCause(e, TransactionTimeoutException.class));
            }
        }
    });
    spi(client).waitForBlocked();
    spi(grid(0)).waitForBlocked();
    fut2.get();
    client.close();
    spi(grid(0)).stopBlock();
    blocked.countDown();
    fut.get();
    for (int i = 0; i < GRID_CNT; i++) assertTrue(grid(i).context().cache().context().tm().activeTransactions().isEmpty());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TestRecordingCommunicationSpi.spi(org.apache.ignite.internal.TestRecordingCommunicationSpi.spi) IgniteUtils.awaitQuiet(org.apache.ignite.internal.util.IgniteUtils.awaitQuiet) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest) Transaction(org.apache.ignite.transactions.Transaction) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) Thread.sleep(java.lang.Thread.sleep) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MvccFeatureChecker(org.apache.ignite.testframework.MvccFeatureChecker) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridNearLockRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) LongAdder(java.util.concurrent.atomic.LongAdder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) Callable(java.util.concurrent.Callable) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareResponse) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) CacheException(javax.cache.CacheException) Assume(org.junit.Assume) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) GridNearLockResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse) SF(org.apache.ignite.testframework.GridTestUtils.SF) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) GridNearLockResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) CacheException(javax.cache.CacheException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) Ignite(org.apache.ignite.Ignite) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

Ignite (org.apache.ignite.Ignite)6 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)6 GridNearTxFinishRequest (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest)6 Transaction (org.apache.ignite.transactions.Transaction)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Message (org.apache.ignite.plugin.extensions.communication.Message)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Test (org.junit.Test)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 List (java.util.List)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 CacheException (javax.cache.CacheException)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteException (org.apache.ignite.IgniteException)2 TRANSACTIONAL (org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL)2 FULL_SYNC (org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC)2