Search in sources :

Example 6 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class ClientSlowDiscoveryTopologyChangeTest method testClientJoinAndCacheStop.

/**
 * Test check that client join works well if cache configured on it stopped on server nodes
 * but discovery event about cache stop is not delivered to client node immediately.
 * When client node joins to cluster it sends SingleMessage to coordinator.
 * During this time topology on server nodes can be changed,
 * because client exchange doesn't require acknowledgement for SingleMessage on coordinator.
 * Delay is simulated by blocking sending this SingleMessage and resume sending after topology is changed.
 */
@Test
public void testClientJoinAndCacheStop() throws Exception {
    IgniteEx crd = (IgniteEx) startGridsMultiThreaded(3);
    awaitPartitionMapExchange();
    for (int k = 0; k < 64; k++) crd.cache(CACHE_NAME).put(k, k);
    TestRecordingCommunicationSpi clientCommSpi = new TestRecordingCommunicationSpi();
    // Delay client join process.
    clientCommSpi.blockMessages((node, msg) -> {
        if (!(msg instanceof GridDhtPartitionsSingleMessage))
            return false;
        GridDhtPartitionsSingleMessage singleMsg = (GridDhtPartitionsSingleMessage) msg;
        return Optional.ofNullable(singleMsg.exchangeId()).map(GridDhtPartitionExchangeId::topologyVersion).filter(topVer -> topVer.equals(new AffinityTopologyVersion(4, 0))).isPresent();
    });
    communicationSpiSupplier = () -> clientCommSpi;
    CustomMessageInterceptingDiscoverySpi clientDiscoSpi = new CustomMessageInterceptingDiscoverySpi();
    CountDownLatch clientDiscoSpiBlock = new CountDownLatch(1);
    // Delay cache destroying on client node.
    clientDiscoSpi.interceptor = (msg) -> {
        if (!(msg instanceof DynamicCacheChangeBatch))
            return;
        DynamicCacheChangeBatch cacheChangeBatch = (DynamicCacheChangeBatch) msg;
        boolean hasCacheStopReq = cacheChangeBatch.requests().stream().anyMatch(req -> req.stop() && req.cacheName().equals(CACHE_NAME));
        if (hasCacheStopReq)
            U.awaitQuiet(clientDiscoSpiBlock);
    };
    discoverySpiSupplier = () -> clientDiscoSpi;
    IgniteInternalFuture<IgniteEx> clientStartFut = GridTestUtils.runAsync(() -> startClientGrid(3));
    // Wait till client node starts join process.
    clientCommSpi.waitForBlocked();
    // Destroy cache on server nodes.
    crd.destroyCache(CACHE_NAME);
    // Resume client join.
    clientCommSpi.stopBlock();
    // Client join should succeed.
    IgniteEx client = clientStartFut.get();
    IgniteCache<Object, Object> clientCache = client.cache(CACHE_NAME);
    Assert.assertNotNull("Cache should exists on client node", clientCache);
    IgniteInternalFuture<?> cacheGet = GridTestUtils.runAsync(() -> clientCache.get(0));
    try {
        // Reasonable timeout.
        cacheGet.get(5_000);
        fail("Cache get operation should throw " + CacheStoppedException.class);
    } catch (Exception e) {
        assertTrue("Got unexpected exception during cache get " + e, X.hasCause(e, CacheStoppedException.class));
    } finally {
        // Resume processing cache destroy on client node.
        clientDiscoSpiBlock.countDown();
    }
    // Wait till cache destroyed on client node.
    GridTestUtils.waitForCondition(() -> {
        AffinityTopologyVersion topVer = client.context().cache().context().exchange().lastFinishedFuture().topologyVersion();
        // Cache destroy version.
        return topVer.equals(new AffinityTopologyVersion(4, 1));
    }, // Reasonable timeout.
    5_000);
    Assert.assertNull("Cache should be destroyed on client node", client.cache(CACHE_NAME));
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) X(org.apache.ignite.internal.util.typedef.X) After(org.junit.After) Optional(java.util.Optional) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) Assert(org.junit.Assert) Before(org.junit.Before) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test)

Example 7 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class IgniteClientReconnectDelayedSpiTest method testReconnectCacheDestroyedDelayedAffinityChange.

/**
 * Test checks correctness of stale {@link CacheAffinityChangeMessage} processing by client node as delayed
 * {@link GridDhtPartitionsSingleMessage} with exchId = null sends after client node reconnect happens.
 *
 * @throws Exception If failed.
 */
@Test
public void testReconnectCacheDestroyedDelayedAffinityChange() throws Exception {
    Ignite ignite = ignite(1);
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite);
    spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite.name());
    spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() == null;
        }
    });
    final Ignite client = startClientGrid(getConfiguration());
    client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
    final Ignite srv = clientRouter(client);
    reconnectClientNode(client, srv, new Runnable() {

        @Override
        public void run() {
            srv.destroyCache(DEFAULT_CACHE_NAME);
            srv.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
        }
    });
    // Resend delayed GridDhtPartitionsSingleMessage.
    spi.waitForBlocked();
    spi.stopBlock();
    assertNotNull(client.cache(DEFAULT_CACHE_NAME));
    final GridDiscoveryManager srvDisco = ((IgniteEx) srv).context().discovery();
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return F.eq(true, srvDisco.cacheClientNode(client.cluster().localNode(), DEFAULT_CACHE_NAME));
        }
    }, 5000));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 8 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class TxPartitionCounterStateConsistencyTest method testLateAffinityChangeDuringExchange.

/**
 * Tests a scenario when stale partition state message can trigger spurious late affinity switching followed by
 * possible primary mapping to moving partition.
 */
@Test
public void testLateAffinityChangeDuringExchange() throws Exception {
    backups = 2;
    Ignite crd = startGridsMultiThreaded(3);
    crd.cluster().active(true);
    awaitPartitionMapExchange();
    for (int p = 0; p < PARTS_CNT; p++) crd.cache(DEFAULT_CACHE_NAME).put(p, p);
    forceCheckpoint();
    int key = primaryKey(grid(2).cache(DEFAULT_CACHE_NAME));
    TestRecordingCommunicationSpi.spi(grid(1)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionsSingleMessage) {
                GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
                return msg0.exchangeId() == null && msg0.partitions().get(CU.cacheId(DEFAULT_CACHE_NAME)).topologyVersion().equals(new AffinityTopologyVersion(4, 0));
            }
            return false;
        }
    });
    stopGrid(2);
    // Fill a queue with a lot of messages.
    for (int i = 0; i < 1000; i++) grid(1).context().cache().context().exchange().refreshPartitions();
    TestRecordingCommunicationSpi.spi(grid(1)).waitForBlocked(1000);
    // Create counter delta for triggering counter rebalance.
    for (int p = 0; p < PARTS_CNT; p++) crd.cache(DEFAULT_CACHE_NAME).put(p, p + 1);
    IgniteConfiguration cfg2 = getConfiguration(getTestIgniteInstanceName(2));
    TestRecordingCommunicationSpi spi2 = (TestRecordingCommunicationSpi) cfg2.getCommunicationSpi();
    spi2.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionDemandMessage)
                // Prevent any rebalancing to avoid switching partitions to owning.
                return true;
            if (msg instanceof GridDhtPartitionsSingleMessage) {
                GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
                return msg0.exchangeId() != null && msg0.exchangeId().topologyVersion().equals(new AffinityTopologyVersion(5, 0));
            }
            return false;
        }
    });
    GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            startGrid(cfg2);
            return null;
        }
    });
    // Delay last single message. It should trigger PME for version 5,0
    spi2.waitForBlocked();
    // Start processing single messages.
    TestRecordingCommunicationSpi.spi(grid(1)).stopBlock();
    // Allow PME to finish.
    spi2.stopBlock();
    grid(0).context().cache().context().exchange().affinityReadyFuture(new AffinityTopologyVersion(5, 1)).get();
    // Primary node for a key will be stopped by FH without a fix.
    grid(0).cache(DEFAULT_CACHE_NAME).put(key, -1);
    for (int i = 0; i < 1000; i++) assertEquals(-1, grid(2).cache(DEFAULT_CACHE_NAME).get(key));
    assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) Test(org.junit.Test)

Example 9 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class CacheMvccPartitionedSqlTxQueriesWithReducerTest method testQueryUpdateOnUnstableTopologyDoesNotCauseDeadlock.

/**
 * @throws Exception If failed.
 */
@Test
public void testQueryUpdateOnUnstableTopologyDoesNotCauseDeadlock() throws Exception {
    ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT).setIndexedTypes(Integer.class, CacheMvccSqlTxQueriesAbstractTest.MvccTestSqlIndexValue.class);
    testSpi = true;
    Ignite updateNode = startGrids(3);
    CountDownLatch latch = new CountDownLatch(1);
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid(1));
    spi.blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionsSingleMessage) {
            latch.countDown();
            return true;
        }
        return false;
    });
    CompletableFuture.runAsync(() -> stopGrid(2));
    assertTrue(latch.await(TX_TIMEOUT, TimeUnit.MILLISECONDS));
    CompletableFuture<Void> queryFut = CompletableFuture.runAsync(() -> updateNode.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("INSERT INTO MvccTestSqlIndexValue (_key, idxVal1) VALUES (1,1),(2,2),(3,3)")).getAll());
    Thread.sleep(300);
    spi.stopBlock();
    try {
        queryFut.get(TX_TIMEOUT, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        assertTrue(X.hasCause(e, ClusterTopologyException.class));
    }
}
Also used : GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) Test(org.junit.Test)

Example 10 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class IgniteClusterSnapshotRestoreSelfTest method checkNodeLeftOnExchangeFinish.

/**
 * @param crdStop {@code True} to stop coordinator node.
 * @param expCls Expected exception class.
 * @param expMsg Expected exception message.
 * @throws Exception If failed.
 */
private void checkNodeLeftOnExchangeFinish(boolean crdStop, Class<? extends Throwable> expCls, String expMsg) throws Exception {
    startGridsWithSnapshot(3, CACHE_KEYS_RANGE, true);
    TestRecordingCommunicationSpi node1spi = TestRecordingCommunicationSpi.spi(grid(1));
    TestRecordingCommunicationSpi node2spi = TestRecordingCommunicationSpi.spi(grid(2));
    node1spi.blockMessages((node, msg) -> msg instanceof GridDhtPartitionsSingleMessage);
    node2spi.blockMessages((node, msg) -> msg instanceof GridDhtPartitionsSingleMessage);
    IgniteFuture<Void> fut = grid(1).snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME));
    node1spi.waitForBlocked();
    node2spi.waitForBlocked();
    stopGrid(crdStop ? 0 : 2, true);
    node1spi.stopBlock();
    if (crdStop)
        node2spi.stopBlock();
    GridTestUtils.assertThrowsAnyCause(log, () -> fut.get(TIMEOUT), expCls, expMsg);
    awaitPartitionMapExchange();
    ensureCacheAbsent(dfltCacheCfg);
}
Also used : GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi)

Aggregations

GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)29 Test (org.junit.Test)16 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)11 Ignite (org.apache.ignite.Ignite)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 HashMap (java.util.HashMap)8 Message (org.apache.ignite.plugin.extensions.communication.Message)8 UUID (java.util.UUID)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 GridDhtPartitionDemandMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)5 GridDhtPartitionsExchangeFuture (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture)5 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)5 T2 (org.apache.ignite.internal.util.typedef.T2)5 Map (java.util.Map)4