use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage in project ignite by apache.
the class CacheExchangeMessageDuplicatedStateTest method checkFullMessages.
/**
* @param crdIdx Coordinator node index.
*/
private void checkFullMessages(int crdIdx) {
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite(crdIdx).configuration().getCommunicationSpi();
List<Object> msgs = commSpi0.recordedMessages(false);
assertTrue(!msgs.isEmpty());
for (Object msg : msgs) {
assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsFullMessage);
checkFullMessage((GridDhtPartitionsFullMessage) msg);
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage in project ignite by apache.
the class NodeWithFilterRestartTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
if (getTestIgniteInstanceName(5).equals(igniteInstanceName))
cfg.setUserAttributes(F.asMap("FILTER", "true"));
// if (getTestIgniteInstanceName(3).equals(igniteInstanceName))
// cfg.setUserAttributes(F.asMap("FILTER", "true"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
if (getTestIgniteInstanceName(0).equals(igniteInstanceName)) {
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
/**
* {@inheritDoc}
*/
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsFullMessage && (node.id().getLeastSignificantBits() & 0xFFFF) == 5) {
GridDhtPartitionsFullMessage fullMsg = (GridDhtPartitionsFullMessage) msg;
if (fullMsg.exchangeId() != null && fullMsg.topologyVersion().equals(new AffinityTopologyVersion(8, 0))) {
info("Going to block message [node=" + node + ", msg=" + msg + ']');
return true;
}
}
return false;
}
});
cfg.setCommunicationSpi(commSpi);
} else
cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
return cfg;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage in project ignite by apache.
the class CacheClientsConcurrentStartTest method doTest.
/**
* @throws Exception If failed.
*/
private void doTest() throws Exception {
final AtomicBoolean failed = new AtomicBoolean();
startGrids(SRV_CNT);
for (int i = 0; i < SRV_CNT; i++) {
((TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi()).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsFullMessage) {
try {
U.sleep(ThreadLocalRandom.current().nextLong(500) + 100);
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
});
}
List<IgniteInternalFuture<?>> futs = new ArrayList<>();
for (int i = 0; i < CLIENTS_CNT; i++) {
final int idx = i;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
Random rnd = new Random();
try {
Ignite ignite = startClientGrid(SRV_CNT + idx);
assertTrue(ignite.configuration().isClientMode());
for (int i = 0; i < CACHES / 2; i++) {
String cacheName = "cache-" + rnd.nextInt(CACHES);
IgniteCache<Object, Object> cache = getCache(ignite, cacheName);
cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
IgniteAtomicSequence seq = ignite.atomicSequence("seq-" + rnd.nextInt(20), 0, true);
seq.getAndIncrement();
}
while (!stopped) {
IgniteCache<Object, Object> cache = getCache(ignite, "cache-" + rnd.nextInt(CACHES));
int val = Math.abs(rnd.nextInt(100));
if (val >= 0 && val < 40)
cache.containsKey(ignite.cluster().localNode().id());
else if (val >= 40 && val < 80)
cache.get(ignite.cluster().localNode().id());
else
cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
Thread.sleep(10);
}
} catch (Exception e) {
log.error("Unexpected error: " + e, e);
failed.set(true);
}
}
}, 1, "client-thread");
futs.add(fut);
}
Thread.sleep(10_000);
stopped = true;
for (IgniteInternalFuture<?> fut : futs) fut.get();
assertFalse(failed.get());
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage in project ignite by apache.
the class PartitionsExchangeCoordinatorFailoverTest method testNewCoordinatorCompletedExchange.
/**
* Tests that new coordinator is able to finish old exchanges in case of in-complete coordinator initialization.
*/
@Test
public void testNewCoordinatorCompletedExchange() throws Exception {
spiFactory = TestRecordingCommunicationSpi::new;
IgniteEx crd = startGrid(CRD_NONE);
IgniteEx newCrd = startGrid(1);
crd.cluster().active(true);
// 3 node join topology version.
AffinityTopologyVersion joinThirdNodeVer = new AffinityTopologyVersion(3, 0);
// 4 node join topology version.
AffinityTopologyVersion joinFourNodeVer = new AffinityTopologyVersion(4, 0);
// Block FullMessage for newly joined nodes.
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(crd);
final CountDownLatch sndFullMsgLatch = new CountDownLatch(1);
// Delay sending full message to newly joined nodes.
spi.blockMessages((node, msg) -> {
if (msg instanceof GridDhtPartitionsFullMessage && node.order() > 2) {
try {
sndFullMsgLatch.await();
} catch (Throwable ignored) {
}
return true;
}
return false;
});
IgniteInternalFuture joinTwoNodesFut = GridTestUtils.runAsync(() -> startGridsMultiThreaded(2, 2));
GridCachePartitionExchangeManager exchangeMgr = newCrd.context().cache().context().exchange();
// Wait till new coordinator finishes third node join exchange.
GridTestUtils.waitForCondition(() -> exchangeMgr.readyAffinityVersion().compareTo(joinThirdNodeVer) >= 0, getTestTimeout());
IgniteInternalFuture startLastNodeFut = GridTestUtils.runAsync(() -> startGrid(5));
// Wait till new coordinator starts third node join exchange.
GridTestUtils.waitForCondition(() -> exchangeMgr.lastTopologyFuture().initialVersion().compareTo(joinFourNodeVer) >= 0, getTestTimeout());
IgniteInternalFuture stopCrdFut = GridTestUtils.runAsync(() -> stopGrid(CRD_NONE, true, false));
// Magic sleep to make sure that coordinator stop process has started.
U.sleep(1000);
// Resume full messages sending to unblock coordinator stopping process.
sndFullMsgLatch.countDown();
// Coordinator stop should succeed.
stopCrdFut.get();
// Nodes join should succeed.
joinTwoNodesFut.get();
startLastNodeFut.get();
awaitPartitionMapExchange();
// Check that all caches are operable.
for (Ignite grid : G.allGrids()) {
IgniteCache cache = grid.cache(CACHE_NAME);
Assert.assertNotNull(cache);
cache.put(0, 0);
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage in project ignite by apache.
the class TxPartitionCounterStateConsistencyTest method testPartitionConsistencyDuringRebalanceAndConcurrentUpdates_TxDuringPME.
/**
* Tests tx load concurrently with PME not changing tx topology.
* In such scenario a race is possible with tx updates and PME counters set.
* Outdated counters on PME should be ignored.
*/
@Test
public void testPartitionConsistencyDuringRebalanceAndConcurrentUpdates_TxDuringPME() throws Exception {
backups = 2;
Ignite crd = startGrid(0);
startGrid(1);
startGrid(2);
crd.cluster().active(true);
Ignite client = startClientGrid(CLIENT_GRID_NAME);
IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
// Put one key per partition.
try (IgniteDataStreamer<Object, Object> streamer = client.dataStreamer(DEFAULT_CACHE_NAME)) {
for (int k = 0; k < partitions(); k++) streamer.addData(k, 0);
}
Integer key0 = primaryKey(grid(1).cache(DEFAULT_CACHE_NAME));
Integer key = primaryKey(grid(0).cache(DEFAULT_CACHE_NAME));
TestRecordingCommunicationSpi crdSpi = TestRecordingCommunicationSpi.spi(crd);
crdSpi.blockMessages((node, message) -> {
if (message instanceof GridDhtPartitionsFullMessage) {
GridDhtPartitionsFullMessage tmp = (GridDhtPartitionsFullMessage) message;
return tmp.exchangeId() != null;
}
return false;
});
// Locks mapped wait.
CountDownLatch l = new CountDownLatch(1);
IgniteInternalFuture startNodeFut = GridTestUtils.runAsync(() -> {
U.awaitQuiet(l);
try {
// Start node out of BLT.
startGrid(SERVER_NODES);
} catch (Exception e) {
fail(X.getFullStackTrace(e));
}
});
TestRecordingCommunicationSpi cliSpi = TestRecordingCommunicationSpi.spi(client);
cliSpi.blockMessages((node, message) -> {
// Block second lock map req.
return message instanceof GridNearLockRequest && node.order() == crd.cluster().localNode().order();
});
IgniteInternalFuture txFut = GridTestUtils.runAsync(() -> {
try (Transaction tx = client.transactions().txStart()) {
Map<Integer, Integer> map = new LinkedHashMap<>();
// clientFirst=true in lockAll.
map.put(key, key);
// clientFirst=false in lockAll.
map.put(key0, key0);
cache.putAll(map);
// Will start preparing in the middle of PME.
tx.commit();
}
});
IgniteInternalFuture lockFut = GridTestUtils.runAsync(() -> {
try {
// Delay first before PME.
cliSpi.waitForBlocked();
l.countDown();
// Block PME after finish on crd and wait on others.
crdSpi.waitForBlocked();
// Start remote lock mapping.
cliSpi.stopBlock();
} catch (InterruptedException e) {
fail();
}
});
lockFut.get();
crdSpi.stopBlock();
txFut.get();
startNodeFut.get();
awaitPartitionMapExchange();
assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
// Expect correct reservation counters.
PartitionUpdateCounter cntr = counter(key, grid(0).name());
assertNotNull(cntr);
assertEquals(cntr.toString(), 2, cntr.reserved());
}
Aggregations