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 + ']');
}
}
}
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;
});
}
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;
}
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]");
}
}
}
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;
}
Aggregations