use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage in project ignite by apache.
the class CacheExchangeMessageDuplicatedStateTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setUserAttributes(Collections.singletonMap("name", igniteInstanceName));
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
commSpi.record(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return (msg.getClass() == GridDhtPartitionsSingleMessage.class || msg.getClass() == GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
}
});
cfg.setCommunicationSpi(commSpi);
List<CacheConfiguration> ccfgs = new ArrayList<>();
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF1_CACHE1);
ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF1_CACHE2);
ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF3_CACHE1);
ccfg.setBackups(3);
RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 64);
ccfg.setAffinity(aff);
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF4_FILTER_CACHE1);
ccfg.setNodeFilter(new TestNodeFilter());
ccfg.setAffinity(new RendezvousAffinityFunction());
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF4_FILTER_CACHE2);
ccfg.setNodeFilter(new TestNodeFilter());
ccfg.setAffinity(new RendezvousAffinityFunction());
ccfgs.add(ccfg);
}
cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
return cfg;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage in project ignite by apache.
the class IgniteClientReconnectDelayedSpiTest method testReconnectCacheDestroyedDelayedAffinityChange.
/**
* Test checks correctness of stale {@link CacheAffinityChangeMessage} processing by client node as delayed
* {@link GridDhtPartitionsSingleMessage} with exchId = null sends after client node reconnect happens.
*
* @throws Exception If failed.
*/
@Test
public void testReconnectCacheDestroyedDelayedAffinityChange() throws Exception {
Ignite ignite = ignite(1);
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite);
spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite.name());
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() == null;
}
});
final Ignite client = startClientGrid(getConfiguration());
client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
final Ignite srv = clientRouter(client);
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
srv.destroyCache(DEFAULT_CACHE_NAME);
srv.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
}
});
// Resend delayed GridDhtPartitionsSingleMessage.
spi.waitForBlocked();
spi.stopBlock();
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
final GridDiscoveryManager srvDisco = ((IgniteEx) srv).context().discovery();
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return F.eq(true, srvDisco.cacheClientNode(client.cluster().localNode(), DEFAULT_CACHE_NAME));
}
}, 5000));
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage in project ignite by apache.
the class GridExchangeFreeSwitchTest method startPmeMessagesCounting.
/**
* @param nodes Nodes.
* @param singleCnt Counter for GridDhtPartitionsSingleMessage.
* @param fullCnt Counter for GridDhtPartitionsFullMessage.
*/
private void startPmeMessagesCounting(int nodes, AtomicLong singleCnt, AtomicLong fullCnt) {
for (int i = 0; i < nodes; i++) {
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
spi.closure(new IgniteBiInClosure<ClusterNode, Message>() {
@Override
public void apply(ClusterNode node, Message msg) {
if (msg.getClass().equals(GridDhtPartitionsSingleMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null)
singleCnt.incrementAndGet();
if (msg.getClass().equals(GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null)
fullCnt.incrementAndGet();
}
});
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage 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.GridDhtPartitionsAbstractMessage in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testJoinExchangeBecomeCoordinator.
/**
* @throws Exception If failed.
*/
@Test
public void testJoinExchangeBecomeCoordinator() throws Exception {
long topVer = 0;
final int NODES = 3;
for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
checkAffinity(NODES, topVer(topVer, 1), true);
AtomicBoolean joined = new AtomicBoolean();
for (int i = 0; i < NODES; i++) {
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg.getClass().equals(GridDhtPartitionsSingleMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null)
// Join exchange started.
joined.set(true);
return msg.getClass().equals(GridDhtPartitionsSingleMessage.class) || msg.getClass().equals(GridDhtPartitionsFullMessage.class);
}
});
}
IgniteInternalFuture<?> stopFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
for (int j = 1; j < NODES; j++) {
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(j).configuration().getCommunicationSpi();
spi.waitForBlocked();
}
for (int i = 0; i < NODES; i++) stopGrid(getTestIgniteInstanceName(i), false, false);
return null;
}
}, "stop-thread");
Ignite node = startGrid(NODES);
assertEquals(NODES + 1, node.cluster().localNode().order());
stopFut.get();
for (int i = 0; i < NODES + 1; i++) calculateAffinity(++topVer);
checkAffinity(1, topVer(topVer, 0), true);
for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
checkAffinity(NODES + 1, topVer(topVer, 1), true);
}
Aggregations