use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.
the class GridCachePartitionExchangeManager method createPartitionsSingleMessage.
/**
* @param targetNode Target node.
* @param exchangeId ID.
* @param clientOnlyExchange Client exchange flag.
* @param sndCounters {@code True} if need send partition update counters.
* @return Message.
*/
public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(ClusterNode targetNode, @Nullable GridDhtPartitionExchangeId exchangeId, boolean clientOnlyExchange, boolean sndCounters) {
GridDhtPartitionsSingleMessage m = new GridDhtPartitionsSingleMessage(exchangeId, clientOnlyExchange, cctx.versions().last(), true);
Map<Object, T2<Integer, Map<Integer, GridDhtPartitionState>>> dupData = new HashMap<>();
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (!cacheCtx.isLocal()) {
GridDhtPartitionMap locMap = cacheCtx.topology().localPartitionMap();
addPartitionMap(m, dupData, true, cacheCtx.cacheId(), locMap, cacheCtx.affinity().affinityCache().similarAffinityKey());
if (sndCounters)
m.partitionUpdateCounters(cacheCtx.cacheId(), cacheCtx.topology().updateCounters(true));
}
}
for (GridClientPartitionTopology top : clientTops.values()) {
if (m.partitions() != null && m.partitions().containsKey(top.cacheId()))
continue;
GridDhtPartitionMap locMap = top.localPartitionMap();
addPartitionMap(m, dupData, true, top.cacheId(), locMap, top.similarAffinityKey());
if (sndCounters)
m.partitionUpdateCounters(top.cacheId(), top.updateCounters(true));
}
return m;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.
the class IgniteClusterSnapshotRestoreSelfTest method checkNodeLeftOnExchangeFinish.
/**
* @param crdStop {@code True} to stop coordinator node.
* @param expCls Expected exception class.
* @param expMsg Expected exception message.
* @throws Exception If failed.
*/
private void checkNodeLeftOnExchangeFinish(boolean crdStop, Class<? extends Throwable> expCls, String expMsg) throws Exception {
startGridsWithSnapshot(3, CACHE_KEYS_RANGE, true);
TestRecordingCommunicationSpi node1spi = TestRecordingCommunicationSpi.spi(grid(1));
TestRecordingCommunicationSpi node2spi = TestRecordingCommunicationSpi.spi(grid(2));
node1spi.blockMessages((node, msg) -> msg instanceof GridDhtPartitionsSingleMessage);
node2spi.blockMessages((node, msg) -> msg instanceof GridDhtPartitionsSingleMessage);
IgniteFuture<Void> fut = grid(1).snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME));
node1spi.waitForBlocked();
node2spi.waitForBlocked();
stopGrid(crdStop ? 0 : 2, true);
node1spi.stopBlock();
if (crdStop)
node2spi.stopBlock();
GridTestUtils.assertThrowsAnyCause(log, () -> fut.get(TIMEOUT), expCls, expMsg);
awaitPartitionMapExchange();
ensureCacheAbsent(dfltCacheCfg);
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.
the class TxPartitionCounterStateConsistencyTest method testLateAffinityChangeDuringExchange.
/**
* Tests a scenario when stale partition state message can trigger spurious late affinity switching followed by
* possible primary mapping to moving partition.
*/
@Test
public void testLateAffinityChangeDuringExchange() throws Exception {
backups = 2;
Ignite crd = startGridsMultiThreaded(3);
crd.cluster().active(true);
awaitPartitionMapExchange();
for (int p = 0; p < PARTS_CNT; p++) crd.cache(DEFAULT_CACHE_NAME).put(p, p);
forceCheckpoint();
int key = primaryKey(grid(2).cache(DEFAULT_CACHE_NAME));
TestRecordingCommunicationSpi.spi(grid(1)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode clusterNode, Message msg) {
if (msg instanceof GridDhtPartitionsSingleMessage) {
GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
return msg0.exchangeId() == null && msg0.partitions().get(CU.cacheId(DEFAULT_CACHE_NAME)).topologyVersion().equals(new AffinityTopologyVersion(4, 0));
}
return false;
}
});
stopGrid(2);
// Fill a queue with a lot of messages.
for (int i = 0; i < 1000; i++) grid(1).context().cache().context().exchange().refreshPartitions();
TestRecordingCommunicationSpi.spi(grid(1)).waitForBlocked(1000);
// Create counter delta for triggering counter rebalance.
for (int p = 0; p < PARTS_CNT; p++) crd.cache(DEFAULT_CACHE_NAME).put(p, p + 1);
IgniteConfiguration cfg2 = getConfiguration(getTestIgniteInstanceName(2));
TestRecordingCommunicationSpi spi2 = (TestRecordingCommunicationSpi) cfg2.getCommunicationSpi();
spi2.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode clusterNode, Message msg) {
if (msg instanceof GridDhtPartitionDemandMessage)
// Prevent any rebalancing to avoid switching partitions to owning.
return true;
if (msg instanceof GridDhtPartitionsSingleMessage) {
GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
return msg0.exchangeId() != null && msg0.exchangeId().topologyVersion().equals(new AffinityTopologyVersion(5, 0));
}
return false;
}
});
GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(cfg2);
return null;
}
});
// Delay last single message. It should trigger PME for version 5,0
spi2.waitForBlocked();
// Start processing single messages.
TestRecordingCommunicationSpi.spi(grid(1)).stopBlock();
// Allow PME to finish.
spi2.stopBlock();
grid(0).context().cache().context().exchange().affinityReadyFuture(new AffinityTopologyVersion(5, 1)).get();
// Primary node for a key will be stopped by FH without a fix.
grid(0).cache(DEFAULT_CACHE_NAME).put(key, -1);
for (int i = 0; i < 1000; i++) assertEquals(-1, grid(2).cache(DEFAULT_CACHE_NAME).get(key));
assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.
the class IgniteWalHistoryReservationsTest method testNodeLeftDuringExchange.
/**
* @throws Exception If failed.
*/
@Test
public void testNodeLeftDuringExchange() throws Exception {
MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.ENTRY_LOCK);
System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0");
final int entryCnt = 10_000;
final int initGridCnt = 4;
final Ignite ig0 = startGrids(initGridCnt);
ig0.cluster().active(true);
IgniteCache<Object, Object> cache = ig0.cache("cache1");
for (int k = 0; k < entryCnt; k++) cache.put(k, k);
forceCheckpoint();
TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
spi.blockMessages((node, msg) -> {
if (msg instanceof GridDhtPartitionsSingleMessage) {
GridDhtPartitionsSingleMessage sm = (GridDhtPartitionsSingleMessage) msg;
return sm.exchangeId() != null;
}
return false;
});
GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
try {
IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(initGridCnt));
cfg.setCommunicationSpi(spi);
startGrid(optimize(cfg));
} catch (Exception e) {
fail(e.getMessage());
}
}
});
spi.waitForBlocked();
boolean reserved = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int g = 0; g < initGridCnt; g++) {
IgniteEx ig = grid(g);
if (isReserveListEmpty(ig))
return false;
}
return true;
}
}, 10_000);
assert reserved;
spi.stopBlock();
stopGrid(getTestIgniteInstanceName(initGridCnt - 1), true, false);
boolean released = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int g = 0; g < initGridCnt - 1; g++) {
IgniteEx ig = grid(g);
if (!isReserveListEmpty(ig))
return false;
}
return true;
}
}, 10_000);
assert released;
awaitPartitionMapExchange();
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.
the class CacheMvccPartitionedSqlTxQueriesWithReducerTest method testQueryUpdateOnUnstableTopologyDoesNotCauseDeadlock.
/**
* @throws Exception If failed.
*/
@Test
public void testQueryUpdateOnUnstableTopologyDoesNotCauseDeadlock() throws Exception {
ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT).setIndexedTypes(Integer.class, CacheMvccSqlTxQueriesAbstractTest.MvccTestSqlIndexValue.class);
testSpi = true;
Ignite updateNode = startGrids(3);
CountDownLatch latch = new CountDownLatch(1);
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid(1));
spi.blockMessages((node, msg) -> {
if (msg instanceof GridDhtPartitionsSingleMessage) {
latch.countDown();
return true;
}
return false;
});
CompletableFuture.runAsync(() -> stopGrid(2));
assertTrue(latch.await(TX_TIMEOUT, TimeUnit.MILLISECONDS));
CompletableFuture<Void> queryFut = CompletableFuture.runAsync(() -> updateNode.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("INSERT INTO MvccTestSqlIndexValue (_key, idxVal1) VALUES (1,1),(2,2),(3,3)")).getAll());
Thread.sleep(300);
spi.stopBlock();
try {
queryFut.get(TX_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (Exception e) {
assertTrue(X.hasCause(e, ClusterTopologyException.class));
}
}
Aggregations