Search in sources :

Example 16 with GridDhtPartitionsFullMessage

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

the class CacheExchangeMessageDuplicatedStateTest method checkFullMessages.

/**
 * @param crdIdx Coordinator node index.
 */
private void checkFullMessages(int crdIdx) {
    TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite(crdIdx).configuration().getCommunicationSpi();
    List<Object> msgs = commSpi0.recordedMessages(false);
    assertTrue(!msgs.isEmpty());
    for (Object msg : msgs) {
        assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsFullMessage);
        checkFullMessage((GridDhtPartitionsFullMessage) msg);
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)

Example 17 with GridDhtPartitionsFullMessage

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

the class NodeWithFilterRestartTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    if (getTestIgniteInstanceName(5).equals(igniteInstanceName))
        cfg.setUserAttributes(F.asMap("FILTER", "true"));
    // if (getTestIgniteInstanceName(3).equals(igniteInstanceName))
    // cfg.setUserAttributes(F.asMap("FILTER", "true"));
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
    if (getTestIgniteInstanceName(0).equals(igniteInstanceName)) {
        TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
        commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            /**
             * {@inheritDoc}
             */
            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg instanceof GridDhtPartitionsFullMessage && (node.id().getLeastSignificantBits() & 0xFFFF) == 5) {
                    GridDhtPartitionsFullMessage fullMsg = (GridDhtPartitionsFullMessage) msg;
                    if (fullMsg.exchangeId() != null && fullMsg.topologyVersion().equals(new AffinityTopologyVersion(8, 0))) {
                        info("Going to block message [node=" + node + ", msg=" + msg + ']');
                        return true;
                    }
                }
                return false;
            }
        });
        cfg.setCommunicationSpi(commSpi);
    } else
        cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 18 with GridDhtPartitionsFullMessage

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

the class CacheClientsConcurrentStartTest method doTest.

/**
 * @throws Exception If failed.
 */
private void doTest() throws Exception {
    final AtomicBoolean failed = new AtomicBoolean();
    startGrids(SRV_CNT);
    for (int i = 0; i < SRV_CNT; i++) {
        ((TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi()).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg instanceof GridDhtPartitionsFullMessage) {
                    try {
                        U.sleep(ThreadLocalRandom.current().nextLong(500) + 100);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                return false;
            }
        });
    }
    List<IgniteInternalFuture<?>> futs = new ArrayList<>();
    for (int i = 0; i < CLIENTS_CNT; i++) {
        final int idx = i;
        IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

            @Override
            public void run() {
                Random rnd = new Random();
                try {
                    Ignite ignite = startClientGrid(SRV_CNT + idx);
                    assertTrue(ignite.configuration().isClientMode());
                    for (int i = 0; i < CACHES / 2; i++) {
                        String cacheName = "cache-" + rnd.nextInt(CACHES);
                        IgniteCache<Object, Object> cache = getCache(ignite, cacheName);
                        cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
                        IgniteAtomicSequence seq = ignite.atomicSequence("seq-" + rnd.nextInt(20), 0, true);
                        seq.getAndIncrement();
                    }
                    while (!stopped) {
                        IgniteCache<Object, Object> cache = getCache(ignite, "cache-" + rnd.nextInt(CACHES));
                        int val = Math.abs(rnd.nextInt(100));
                        if (val >= 0 && val < 40)
                            cache.containsKey(ignite.cluster().localNode().id());
                        else if (val >= 40 && val < 80)
                            cache.get(ignite.cluster().localNode().id());
                        else
                            cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
                        Thread.sleep(10);
                    }
                } catch (Exception e) {
                    log.error("Unexpected error: " + e, e);
                    failed.set(true);
                }
            }
        }, 1, "client-thread");
        futs.add(fut);
    }
    Thread.sleep(10_000);
    stopped = true;
    for (IgniteInternalFuture<?> fut : futs) fut.get();
    assertFalse(failed.get());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite)

Example 19 with GridDhtPartitionsFullMessage

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

the class PartitionsExchangeCoordinatorFailoverTest method testNewCoordinatorCompletedExchange.

/**
 * Tests that new coordinator is able to finish old exchanges in case of in-complete coordinator initialization.
 */
@Test
public void testNewCoordinatorCompletedExchange() throws Exception {
    spiFactory = TestRecordingCommunicationSpi::new;
    IgniteEx crd = startGrid(CRD_NONE);
    IgniteEx newCrd = startGrid(1);
    crd.cluster().active(true);
    // 3 node join topology version.
    AffinityTopologyVersion joinThirdNodeVer = new AffinityTopologyVersion(3, 0);
    // 4 node join topology version.
    AffinityTopologyVersion joinFourNodeVer = new AffinityTopologyVersion(4, 0);
    // Block FullMessage for newly joined nodes.
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(crd);
    final CountDownLatch sndFullMsgLatch = new CountDownLatch(1);
    // Delay sending full message to newly joined nodes.
    spi.blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionsFullMessage && node.order() > 2) {
            try {
                sndFullMsgLatch.await();
            } catch (Throwable ignored) {
            }
            return true;
        }
        return false;
    });
    IgniteInternalFuture joinTwoNodesFut = GridTestUtils.runAsync(() -> startGridsMultiThreaded(2, 2));
    GridCachePartitionExchangeManager exchangeMgr = newCrd.context().cache().context().exchange();
    // Wait till new coordinator finishes third node join exchange.
    GridTestUtils.waitForCondition(() -> exchangeMgr.readyAffinityVersion().compareTo(joinThirdNodeVer) >= 0, getTestTimeout());
    IgniteInternalFuture startLastNodeFut = GridTestUtils.runAsync(() -> startGrid(5));
    // Wait till new coordinator starts third node join exchange.
    GridTestUtils.waitForCondition(() -> exchangeMgr.lastTopologyFuture().initialVersion().compareTo(joinFourNodeVer) >= 0, getTestTimeout());
    IgniteInternalFuture stopCrdFut = GridTestUtils.runAsync(() -> stopGrid(CRD_NONE, true, false));
    // Magic sleep to make sure that coordinator stop process has started.
    U.sleep(1000);
    // Resume full messages sending to unblock coordinator stopping process.
    sndFullMsgLatch.countDown();
    // Coordinator stop should succeed.
    stopCrdFut.get();
    // Nodes join should succeed.
    joinTwoNodesFut.get();
    startLastNodeFut.get();
    awaitPartitionMapExchange();
    // Check that all caches are operable.
    for (Ignite grid : G.allGrids()) {
        IgniteCache cache = grid.cache(CACHE_NAME);
        Assert.assertNotNull(cache);
        cache.put(0, 0);
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 20 with GridDhtPartitionsFullMessage

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

the class TxPartitionCounterStateConsistencyTest method testPartitionConsistencyDuringRebalanceAndConcurrentUpdates_TxDuringPME.

/**
 * Tests tx load concurrently with PME not changing tx topology.
 * In such scenario a race is possible with tx updates and PME counters set.
 * Outdated counters on PME should be ignored.
 */
@Test
public void testPartitionConsistencyDuringRebalanceAndConcurrentUpdates_TxDuringPME() throws Exception {
    backups = 2;
    Ignite crd = startGrid(0);
    startGrid(1);
    startGrid(2);
    crd.cluster().active(true);
    Ignite client = startClientGrid(CLIENT_GRID_NAME);
    IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
    // Put one key per partition.
    try (IgniteDataStreamer<Object, Object> streamer = client.dataStreamer(DEFAULT_CACHE_NAME)) {
        for (int k = 0; k < partitions(); k++) streamer.addData(k, 0);
    }
    Integer key0 = primaryKey(grid(1).cache(DEFAULT_CACHE_NAME));
    Integer key = primaryKey(grid(0).cache(DEFAULT_CACHE_NAME));
    TestRecordingCommunicationSpi crdSpi = TestRecordingCommunicationSpi.spi(crd);
    crdSpi.blockMessages((node, message) -> {
        if (message instanceof GridDhtPartitionsFullMessage) {
            GridDhtPartitionsFullMessage tmp = (GridDhtPartitionsFullMessage) message;
            return tmp.exchangeId() != null;
        }
        return false;
    });
    // Locks mapped wait.
    CountDownLatch l = new CountDownLatch(1);
    IgniteInternalFuture startNodeFut = GridTestUtils.runAsync(() -> {
        U.awaitQuiet(l);
        try {
            // Start node out of BLT.
            startGrid(SERVER_NODES);
        } catch (Exception e) {
            fail(X.getFullStackTrace(e));
        }
    });
    TestRecordingCommunicationSpi cliSpi = TestRecordingCommunicationSpi.spi(client);
    cliSpi.blockMessages((node, message) -> {
        // Block second lock map req.
        return message instanceof GridNearLockRequest && node.order() == crd.cluster().localNode().order();
    });
    IgniteInternalFuture txFut = GridTestUtils.runAsync(() -> {
        try (Transaction tx = client.transactions().txStart()) {
            Map<Integer, Integer> map = new LinkedHashMap<>();
            // clientFirst=true in lockAll.
            map.put(key, key);
            // clientFirst=false in lockAll.
            map.put(key0, key0);
            cache.putAll(map);
            // Will start preparing in the middle of PME.
            tx.commit();
        }
    });
    IgniteInternalFuture lockFut = GridTestUtils.runAsync(() -> {
        try {
            // Delay first before PME.
            cliSpi.waitForBlocked();
            l.countDown();
            // Block PME after finish on crd and wait on others.
            crdSpi.waitForBlocked();
            // Start remote lock mapping.
            cliSpi.stopBlock();
        } catch (InterruptedException e) {
            fail();
        }
    });
    lockFut.get();
    crdSpi.stopBlock();
    txFut.get();
    startNodeFut.get();
    awaitPartitionMapExchange();
    assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
    // Expect correct reservation counters.
    PartitionUpdateCounter cntr = counter(key, grid(0).name());
    assertNotNull(cntr);
    assertEquals(cntr.toString(), 2, cntr.reserved());
}
Also used : GridNearLockRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) 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) LinkedHashMap(java.util.LinkedHashMap) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Aggregations

GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)22 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 Message (org.apache.ignite.plugin.extensions.communication.Message)8 Ignite (org.apache.ignite.Ignite)7 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 GridDhtPartitionsAbstractMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage)4 Transaction (org.apache.ignite.transactions.Transaction)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 GridAffinityAssignmentCache (org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3