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;
}
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);
}
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());
}
}
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;
}
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);
}
Aggregations