Search in sources :

Example 1 with GridDhtPartitionsAbstractMessage

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

the class CacheExchangeMessageDuplicatedStateTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setUserAttributes(Collections.singletonMap("name", igniteInstanceName));
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    commSpi.record(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg.getClass() == GridDhtPartitionsSingleMessage.class || msg.getClass() == GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
        }
    });
    cfg.setCommunicationSpi(commSpi);
    List<CacheConfiguration> ccfgs = new ArrayList<>();
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE1);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE2);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF3_CACHE1);
        ccfg.setBackups(3);
        RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 64);
        ccfg.setAffinity(aff);
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE1);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE2);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ArrayList(java.util.ArrayList) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with GridDhtPartitionsAbstractMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage 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 3 with GridDhtPartitionsAbstractMessage

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

the class GridExchangeFreeSwitchTest method startPmeMessagesCounting.

/**
 * @param nodes Nodes.
 * @param singleCnt Counter for GridDhtPartitionsSingleMessage.
 * @param fullCnt Counter for GridDhtPartitionsFullMessage.
 */
private void startPmeMessagesCounting(int nodes, AtomicLong singleCnt, AtomicLong fullCnt) {
    for (int i = 0; i < nodes; i++) {
        TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
        spi.closure(new IgniteBiInClosure<ClusterNode, Message>() {

            @Override
            public void apply(ClusterNode node, Message msg) {
                if (msg.getClass().equals(GridDhtPartitionsSingleMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null)
                    singleCnt.incrementAndGet();
                if (msg.getClass().equals(GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null)
                    fullCnt.incrementAndGet();
            }
        });
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message)

Example 4 with GridDhtPartitionsAbstractMessage

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

the class IgniteClusterSnapshotSelfTest method testClusterSnapshotCoordinatorStopped.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotCoordinatorStopped() throws Exception {
    CountDownLatch block = new CountDownLatch(1);
    startGridsWithCache(3, dfltCacheCfg, CACHE_KEYS_RANGE);
    startClientGrid(3);
    awaitPartitionMapExchange();
    for (IgniteEx grid : Arrays.asList(grid(1), grid(2))) {
        grid.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
                try {
                    block.await(TIMEOUT, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    fail("Must not catch exception here: " + e.getMessage());
                }
            }
        });
    }
    for (Ignite grid : G.allGrids()) {
        TestRecordingCommunicationSpi.spi(grid).blockMessages((node, msg) -> {
            if (msg instanceof GridDhtPartitionsSingleMessage)
                return ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
            return false;
        });
    }
    IgniteFuture<Void> fut = grid(1).snapshot().createSnapshot(SNAPSHOT_NAME);
    stopGrid(0);
    block.countDown();
    // There are two exchanges happen: snapshot, node left (with pme-free).
    // Both of them are not require for sending messages.
    assertFalse("Pme-free switch doesn't expect messaging exchanging between nodes", GridTestUtils.waitForCondition(() -> {
        boolean hasMsgs = false;
        for (Ignite g : G.allGrids()) hasMsgs |= TestRecordingCommunicationSpi.spi(g).hasBlockedMessages();
        return hasMsgs;
    }, 5_000));
    assertThrowsWithCause((Callable<Object>) fut::get, IgniteException.class);
    List<GridDhtPartitionsExchangeFuture> exchFuts = grid(1).context().cache().context().exchange().exchangeFutures();
    assertFalse("Exchanges cannot be empty due to snapshot and node left happened", exchFuts.isEmpty());
    for (GridDhtPartitionsExchangeFuture exch : exchFuts) {
        assertTrue("Snapshot and node left events must keep `rebalanced` state" + exch, exch.rebalanced());
    }
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 5 with GridDhtPartitionsAbstractMessage

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

the class CacheLateAffinityAssignmentTest method testJoinExchangeBecomeCoordinator.

/**
 * @throws Exception If failed.
 */
@Test
public void testJoinExchangeBecomeCoordinator() throws Exception {
    long topVer = 0;
    final int NODES = 3;
    for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
    checkAffinity(NODES, topVer(topVer, 1), true);
    AtomicBoolean joined = new AtomicBoolean();
    for (int i = 0; i < NODES; i++) {
        TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
        spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg.getClass().equals(GridDhtPartitionsSingleMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null)
                    // Join exchange started.
                    joined.set(true);
                return msg.getClass().equals(GridDhtPartitionsSingleMessage.class) || msg.getClass().equals(GridDhtPartitionsFullMessage.class);
            }
        });
    }
    IgniteInternalFuture<?> stopFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            for (int j = 1; j < NODES; j++) {
                TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(j).configuration().getCommunicationSpi();
                spi.waitForBlocked();
            }
            for (int i = 0; i < NODES; i++) stopGrid(getTestIgniteInstanceName(i), false, false);
            return null;
        }
    }, "stop-thread");
    Ignite node = startGrid(NODES);
    assertEquals(NODES + 1, node.cluster().localNode().order());
    stopFut.get();
    for (int i = 0; i < NODES + 1; i++) calculateAffinity(++topVer);
    checkAffinity(1, topVer(topVer, 0), true);
    for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
    checkAffinity(NODES + 1, topVer(topVer, 1), true);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) 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) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridDhtPartitionsAbstractMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage)5 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Message (org.apache.ignite.plugin.extensions.communication.Message)4 Ignite (org.apache.ignite.Ignite)3 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)3 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)3 Test (org.junit.Test)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 CacheAffinityChangeMessage (org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IgniteException (org.apache.ignite.IgniteException)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)1 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)1