Search in sources :

Example 21 with GridDhtPartitionsSingleMessage

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

the class GridDhtPartitionsStateValidator method validatePartitionsUpdateCounters.

/**
 * Validate partitions update counters for given {@code top}.
 *
 * @param top Topology to validate.
 * @param messages Single messages received from all nodes.
 * @param ignoringNodes Nodes for what we ignore validation.
 * @return Invalid partitions map with following structure:
 * (partId, (nodeId, updateCounter)).
 * If map is empty validation is successful.
 */
public Map<Integer, Map<UUID, Long>> validatePartitionsUpdateCounters(GridDhtPartitionTopology top, Map<UUID, GridDhtPartitionsSingleMessage> messages, Set<UUID> ignoringNodes) {
    Map<Integer, Map<UUID, Long>> invalidPartitions = new HashMap<>();
    Map<Integer, AbstractMap.Entry<UUID, Long>> updateCountersAndNodesByPartitions = new HashMap<>();
    // Populate counters statistics from local node partitions.
    for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
        if (part.state() != GridDhtPartitionState.OWNING)
            continue;
        if (part.updateCounter() == 0 && part.fullSize() == 0)
            continue;
        updateCountersAndNodesByPartitions.put(part.id(), new AbstractMap.SimpleEntry<>(cctx.localNodeId(), part.updateCounter()));
    }
    int partitions = top.partitions();
    // Then process and validate counters from other nodes.
    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : messages.entrySet()) {
        UUID nodeId = e.getKey();
        if (ignoringNodes.contains(nodeId))
            continue;
        final GridDhtPartitionsSingleMessage message = e.getValue();
        CachePartitionPartialCountersMap countersMap = message.partitionUpdateCounters(top.groupId(), partitions);
        Map<Integer, Long> sizesMap = message.partitionSizes(top.groupId());
        Set<Integer> ignorePartitions = shouldIgnore(top, nodeId, countersMap, sizesMap);
        for (int i = 0; i < countersMap.size(); i++) {
            int p = countersMap.partitionAt(i);
            if (ignorePartitions != null && ignorePartitions.contains(p))
                continue;
            long currentCounter = countersMap.updateCounterAt(i);
            process(invalidPartitions, updateCountersAndNodesByPartitions, p, nodeId, currentCounter);
        }
    }
    return invalidPartitions;
}
Also used : HashMap(java.util.HashMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) AbstractMap(java.util.AbstractMap) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) UUID(java.util.UUID) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) HashMap(java.util.HashMap) NavigableMap(java.util.NavigableMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 22 with GridDhtPartitionsSingleMessage

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

the class GridCachePartitionsStateValidatorSelfTest method testPartitionCountersValidation.

/**
 * Test partition update counters validation.
 */
@Test
public void testPartitionCountersValidation() {
    UUID remoteNode = UUID.randomUUID();
    UUID ignoreNode = UUID.randomUUID();
    // For partitions 0 and 2 we have inconsistent update counters.
    Map<Integer, T2<Long, Long>> updateCountersMap = new HashMap<>();
    updateCountersMap.put(0, new T2<>(2L, 2L));
    updateCountersMap.put(1, new T2<>(2L, 2L));
    updateCountersMap.put(2, new T2<>(5L, 5L));
    // For partitions 0 and 2 we have inconsistent cache sizes.
    Map<Integer, Long> cacheSizesMap = new HashMap<>();
    cacheSizesMap.put(0, 2L);
    cacheSizesMap.put(1, 2L);
    cacheSizesMap.put(2, 2L);
    // Form single messages map.
    Map<UUID, GridDhtPartitionsSingleMessage> messages = new HashMap<>();
    messages.put(remoteNode, from(updateCountersMap, cacheSizesMap));
    messages.put(ignoreNode, from(updateCountersMap, cacheSizesMap));
    GridDhtPartitionsStateValidator validator = new GridDhtPartitionsStateValidator(cctxMock);
    // (partId, (nodeId, updateCounter))
    Map<Integer, Map<UUID, Long>> result = validator.validatePartitionsUpdateCounters(topologyMock, messages, Sets.newHashSet(ignoreNode));
    // Check that validation result contains all necessary information.
    Assert.assertEquals(2, result.size());
    Assert.assertTrue(result.containsKey(0));
    Assert.assertTrue(result.containsKey(2));
    Assert.assertTrue(result.get(0).get(localNodeId) == 1L);
    Assert.assertTrue(result.get(0).get(remoteNode) == 2L);
    Assert.assertTrue(result.get(2).get(localNodeId) == 3L);
    Assert.assertTrue(result.get(2).get(remoteNode) == 5L);
}
Also used : HashMap(java.util.HashMap) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsStateValidator(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) T2(org.apache.ignite.internal.util.typedef.T2) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with GridDhtPartitionsSingleMessage

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

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

the class ClientFastReplyCoordinatorFailureTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setFailureHandler(new StopNodeOrHaltFailureHandler());
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    // Block messages to old coordinator right before killing it.
    if (igniteInstanceName.contains("client")) {
        commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg instanceof GridDhtPartitionsSingleMessage && (node.id().getLeastSignificantBits() & OLD_CRD_BITS) == 0) {
                    info("Going to block message [node=" + node + ", msg=" + msg + ']');
                    clientSingleMesssageLatch.countDown();
                    return true;
                }
                return false;
            }
        });
        if (delayNodeFailedMsg) {
            TcpDiscoverySpi spi = new TestDiscoverySpi();
            spi.setIpFinder(IP_FINDER);
            cfg.setDiscoverySpi(spi);
        }
    } else if (getTestIgniteInstanceName(3).equals(igniteInstanceName)) {
        commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg instanceof GridDhtPartitionsSingleMessage && (node.id().getLeastSignificantBits() & OLD_CRD_BITS) == 0L) {
                    info("Going to block message [node=" + node + ", msg=" + msg + ']');
                    newSrvSingleMesssageLatch.countDown();
                    return true;
                }
                return false;
            }
        });
    } else if (delayNodeFailedMsg) {
        commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg instanceof GridDhtPartitionsSingleRequest && node.isClient()) {
                    GridTestUtils.runAsync(() -> {
                        try {
                            Thread.sleep(1_000);
                        } catch (InterruptedException ignore) {
                        // No-op.
                        }
                        PART_SINGLE_REQ_MSG_LATCH.countDown();
                    });
                }
                return false;
            }
        });
    }
    cfg.setCommunicationSpi(commSpi);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TcpDiscoveryNodeFailedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) TcpDiscoveryNodeLeftMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionsSingleRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleRequest) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 25 with GridDhtPartitionsSingleMessage

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

the class RebalanceCompleteDuringExchangeTest method startNodeAndBlockRebalance.

/**
 * Starts node and blocks rebalance.
 *
 * @param nodeNum Number of node.
 * @throws Exception If failed.
 */
public IgniteEx startNodeAndBlockRebalance(int nodeNum) throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(nodeNum)));
    TestRecordingCommunicationSpi commSpi = (TestRecordingCommunicationSpi) cfg.getCommunicationSpi();
    commSpi.record((ClusterNode node, Message msg) -> {
        if (msg instanceof GridDhtPartitionsSingleMessage) {
            GridDhtPartitionsSingleMessage singleMessage = (GridDhtPartitionsSingleMessage) msg;
            if (singleMessage.exchangeId() == null)
                return false;
            return singleMessage.exchangeId().topologyVersion().equals(new AffinityTopologyVersion(3, 0));
        }
        return false;
    });
    commSpi.blockMessages((ClusterNode node, Message msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage demandMessage = (GridDhtPartitionDemandMessage) msg;
            return CU.cacheId(DEFAULT_CACHE_NAME) == demandMessage.groupId();
        }
        return false;
    });
    return startGrid(cfg);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)

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