Search in sources :

Example 1 with GridDhtPartitionsFullMessage

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

the class GridCachePartitionExchangeManager method sendAllPartitions.

/**
 * @param nodes Nodes.
 * @param msgTopVer Topology version. Will be added to full message.
 */
private void sendAllPartitions(Collection<ClusterNode> nodes, AffinityTopologyVersion msgTopVer) {
    GridDhtPartitionsFullMessage m = createPartitionsFullMessage(true, false, null, null, null, null);
    m.topologyVersion(msgTopVer);
    if (log.isDebugEnabled())
        log.debug("Sending all partitions [nodeIds=" + U.nodeIds(nodes) + ", msg=" + m + ']');
    for (ClusterNode node : nodes) {
        try {
            assert !node.equals(cctx.localNode());
            cctx.io().sendNoRetry(node, m, SYSTEM_POOL);
        } catch (ClusterTopologyCheckedException ignore) {
            if (log.isDebugEnabled())
                log.debug("Failed to send partition update to node because it left grid (will ignore) [node=" + node.id() + ", msg=" + m + ']');
        } catch (IgniteCheckedException e) {
            U.warn(log, "Failed to send partitions full message [node=" + node + ", err=" + e + ']');
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 2 with GridDhtPartitionsFullMessage

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

the class PartitionsExchangeCoordinatorFailoverTest method blockSendingFullMessage.

/**
 * Blocks sending full message from coordinator to non-coordinator node.
 *
 * @param from Coordinator node.
 * @param pred Non-coordinator node predicate.
 *                  If predicate returns {@code true} a full message will not be send to that node.
 */
private void blockSendingFullMessage(IgniteEx from, Predicate<ClusterNode> pred) {
    // Block FullMessage for newly joined nodes.
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(from);
    // Delay sending full messages (without exchange id).
    spi.blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionsFullMessage) {
            GridDhtPartitionsFullMessage fullMsg = (GridDhtPartitionsFullMessage) msg;
            if (fullMsg.exchangeId() != null && pred.test(node)) {
                log.warning("Blocked sending " + msg + " to " + node);
                return true;
            }
        }
        return false;
    });
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)

Example 3 with GridDhtPartitionsFullMessage

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

the class GridCachePartitionExchangeManager method createPartitionsFullMessage.

/**
 * Creates partitions full message for selected cache groups.
 *
 * @param compress {@code True} if possible to compress message (properly work only if prepareMarshall/
 *     finishUnmarshall methods are called).
 * @param newCntrMap {@code True} if possible to use {@link CachePartitionFullCountersMap}.
 * @param exchId Non-null exchange ID if message is created for exchange.
 * @param lastVer Last version.
 * @param partHistSuppliers Partition history suppliers map.
 * @param partsToReload Partitions to reload map.
 * @param grps Selected cache groups.
 * @return Message.
 */
public GridDhtPartitionsFullMessage createPartitionsFullMessage(boolean compress, boolean newCntrMap, @Nullable final GridDhtPartitionExchangeId exchId, @Nullable GridCacheVersion lastVer, @Nullable IgniteDhtPartitionHistorySuppliersMap partHistSuppliers, @Nullable IgniteDhtPartitionsToReloadMap partsToReload, Collection<CacheGroupContext> grps) {
    AffinityTopologyVersion ver = exchId != null ? exchId.topologyVersion() : AffinityTopologyVersion.NONE;
    final GridDhtPartitionsFullMessage m = new GridDhtPartitionsFullMessage(exchId, lastVer, ver, partHistSuppliers, partsToReload);
    m.compressed(compress);
    final Map<Object, T2<Integer, GridDhtPartitionFullMap>> dupData = new HashMap<>();
    Map<Integer, Map<Integer, Long>> partsSizes = new HashMap<>();
    for (CacheGroupContext grp : grps) {
        if (!grp.isLocal()) {
            if (exchId != null) {
                AffinityTopologyVersion startTopVer = grp.localStartVersion();
                if (startTopVer.compareTo(exchId.topologyVersion()) > 0)
                    continue;
            }
            GridAffinityAssignmentCache affCache = grp.affinity();
            GridDhtPartitionFullMap locMap = grp.topology().partitionMap(true);
            if (locMap != null)
                addFullPartitionsMap(m, dupData, compress, grp.groupId(), locMap, affCache.similarAffinityKey());
            Map<Integer, Long> partSizesMap = grp.topology().globalPartSizes();
            if (!partSizesMap.isEmpty())
                partsSizes.put(grp.groupId(), partSizesMap);
            if (exchId != null) {
                CachePartitionFullCountersMap cntrsMap = grp.topology().fullUpdateCounters();
                if (newCntrMap)
                    m.addPartitionUpdateCounters(grp.groupId(), cntrsMap);
                else {
                    m.addPartitionUpdateCounters(grp.groupId(), CachePartitionFullCountersMap.toCountersMap(cntrsMap));
                }
                // Lost partitions can be skipped on node left or activation.
                m.addLostPartitions(grp.groupId(), grp.topology().lostPartitions());
            }
        }
    }
    // It is important that client topologies be added after contexts.
    for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) {
        GridDhtPartitionFullMap map = top.partitionMap(true);
        if (map != null)
            addFullPartitionsMap(m, dupData, compress, top.groupId(), map, top.similarAffinityKey());
        if (exchId != null) {
            CachePartitionFullCountersMap cntrsMap = top.fullUpdateCounters();
            if (newCntrMap)
                m.addPartitionUpdateCounters(top.groupId(), cntrsMap);
            else
                m.addPartitionUpdateCounters(top.groupId(), CachePartitionFullCountersMap.toCountersMap(cntrsMap));
            Map<Integer, Long> partSizesMap = top.globalPartSizes();
            if (!partSizesMap.isEmpty())
                partsSizes.put(top.groupId(), partSizesMap);
            m.addLostPartitions(top.groupId(), top.lostPartitions());
        }
    }
    if (!partsSizes.isEmpty())
        m.partitionSizes(cctx, partsSizes);
    return m;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteSystemProperties.getLong(org.apache.ignite.IgniteSystemProperties.getLong) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) IgniteDhtPartitionsToReloadMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionsToReloadMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) IgniteDhtPartitionHistorySuppliersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionHistorySuppliersMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) T2(org.apache.ignite.internal.util.typedef.T2) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridClientPartitionTopology)

Example 4 with GridDhtPartitionsFullMessage

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

the class GridCachePartitionExchangeManager method sendAllPartitions.

/**
 * @param nodes Target Nodes.
 * @param msgTopVer Topology version. Will be added to full message.
 * @param grps Selected cache groups.
 */
private void sendAllPartitions(Collection<ClusterNode> nodes, AffinityTopologyVersion msgTopVer, Collection<CacheGroupContext> grps) {
    long time = System.currentTimeMillis();
    GridDhtPartitionsFullMessage m = createPartitionsFullMessage(true, false, null, null, null, null, grps);
    m.topologyVersion(msgTopVer);
    if (log.isInfoEnabled()) {
        long latency = System.currentTimeMillis() - time;
        if (latency > 50 || log.isDebugEnabled()) {
            log.info("Finished full message creation [msgTopVer=" + msgTopVer + ", groups=" + grps + ", latency=" + latency + "ms]");
        }
    }
    if (log.isTraceEnabled())
        log.trace("Sending all partitions [nodeIds=" + U.nodeIds(nodes) + ", cacheGroups=" + grps + ", msg=" + m + ']');
    time = System.currentTimeMillis();
    Collection<ClusterNode> failedNodes = U.newHashSet(nodes.size());
    for (ClusterNode node : nodes) {
        try {
            assert !node.equals(cctx.localNode());
            cctx.io().sendNoRetry(node, m, SYSTEM_POOL);
        } catch (ClusterTopologyCheckedException ignore) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to send partition update to node because it left grid (will ignore) " + "[node=" + node.id() + ", msg=" + m + ']');
            }
        } catch (IgniteCheckedException e) {
            failedNodes.add(node);
            U.warn(log, "Failed to send partitions full message [node=" + node + ", err=" + e + ']', e);
        }
    }
    if (log.isInfoEnabled()) {
        long latency = System.currentTimeMillis() - time;
        if (latency > 50 || log.isDebugEnabled()) {
            log.info("Finished sending full message [msgTopVer=" + msgTopVer + ", groups=" + grps + (failedNodes.isEmpty() ? "" : (", skipped=" + U.nodeIds(failedNodes))) + ", latency=" + latency + "ms]");
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 5 with GridDhtPartitionsFullMessage

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

the class CacheExchangeMergeTest method blockExchangeFinish.

/**
 * @param crd Exchange coordinator.
 * @param topVer Exchange topology version.
 * @param blockNodes Nodes which do not receive messages.
 * @param waitMsgNodes Nodes which should receive messages.
 * @return Awaited state latch.
 */
private CountDownLatch blockExchangeFinish(Ignite crd, long topVer, final List<Integer> blockNodes, final List<Integer> waitMsgNodes) {
    log.info("blockExchangeFinish [crd=" + crd.cluster().localNode().id() + ", block=" + blockNodes + ", wait=" + waitMsgNodes + ']');
    final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer);
    final CountDownLatch latch = new CountDownLatch(waitMsgNodes.size());
    TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtPartitionsFullMessage) {
                GridDhtPartitionsFullMessage msg0 = (GridDhtPartitionsFullMessage) msg;
                if (msg0.exchangeId() == null || msg0.exchangeId().topologyVersion().compareTo(topVer0) < 0)
                    return false;
                String name = node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME);
                assert name != null : node;
                for (Integer idx : blockNodes) {
                    if (name.equals(getTestIgniteInstanceName(idx)))
                        return true;
                }
                for (Integer idx : waitMsgNodes) {
                    if (name.equals(getTestIgniteInstanceName(idx))) {
                        log.info("Coordinators sends awaited message [node=" + node.id() + ']');
                        latch.countDown();
                    }
                }
            }
            return false;
        }
    });
    return latch;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CountDownLatch(java.util.concurrent.CountDownLatch)

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