use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class CachePartitionLostAfterSupplierHasLeftTest method doTestPartitionLostWhileClearing.
/**
* Test scenario: last supplier has left while a partition on demander is cleared before sending first demand request.
*
* @param cnt Nodes count.
* @param mode Test mode: 0 - reset while clearing, 1 - restart while clearing and activate all, 2 - restart while
* clearing and activate in wrong order.
* @throws Exception If failed.
*/
private void doTestPartitionLostWhileClearing(int cnt, int mode) throws Exception {
IgniteEx crd = startGrids(cnt);
crd.cluster().baselineAutoAdjustEnabled(false);
crd.cluster().active(true);
int partId = -1;
int idx0 = 0;
int idx1 = 1;
for (int p = 0; p < PARTS_CNT; p++) {
List<ClusterNode> nodes = new ArrayList<>(crd.affinity(DEFAULT_CACHE_NAME).mapPartitionToPrimaryAndBackups(p));
if (grid(nodes.get(0)) == grid(idx0) && grid(nodes.get(1)) == grid(idx1)) {
partId = p;
break;
}
}
assertTrue(partId >= 0);
final int keysCnt = 10_010;
List<Integer> keys = partitionKeys(grid(idx0).cache(DEFAULT_CACHE_NAME), partId, keysCnt, 0);
load(grid(idx0), DEFAULT_CACHE_NAME, keys.subList(0, keysCnt - 10));
stopGrid(idx1);
load(grid(idx0), DEFAULT_CACHE_NAME, keys.subList(keysCnt - 10, keysCnt));
TestRecordingCommunicationSpi.spi(grid(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode clusterNode, Message msg) {
if (msg instanceof GridDhtPartitionSupplyMessage) {
GridDhtPartitionSupplyMessage msg0 = (GridDhtPartitionSupplyMessage) msg;
return msg0.groupId() == CU.cacheId(DEFAULT_CACHE_NAME);
}
return false;
}
});
IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(idx1));
((TestRecordingCommunicationSpi) cfg.getCommunicationSpi()).blockMessages((node, msg) -> {
if (msg instanceof GridDhtPartitionDemandMessage) {
GridDhtPartitionDemandMessage demandMsg = (GridDhtPartitionDemandMessage) msg;
return CU.cacheId(DEFAULT_CACHE_NAME) == demandMsg.groupId();
}
return false;
});
IgniteEx g1 = startGrid(optimize(cfg));
// Stop supplier in the middle of rebalancing.
stopGrid(idx0);
TestRecordingCommunicationSpi.spi(g1).stopBlock();
final GridDhtLocalPartition part = g1.cachex(DEFAULT_CACHE_NAME).context().topology().localPartition(partId);
assertTrue("Unexpected partition state [p=" + partId + ", expected=" + GridDhtPartitionState.LOST + ", actual=" + part.state() + ']', GridTestUtils.waitForCondition(() -> part.state() == GridDhtPartitionState.LOST, 30_000));
assertTrue(g1.cachex(DEFAULT_CACHE_NAME).lostPartitions().contains(partId));
if (mode != 0) {
stopAllGrids();
if (mode == 1) {
crd = startGrids(cnt);
crd.cluster().active(true);
} else if (mode == 2) {
crd = startGrid(idx1);
crd.cluster().active(true);
startGrid(idx0);
} else
fail("Mode: " + mode);
awaitPartitionMapExchange();
assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
} else {
// Will own a clearing partition.
g1.resetLostPartitions(Collections.singletonList(DEFAULT_CACHE_NAME));
awaitPartitionMapExchange();
// Expecting partition in OWNING state.
final PartitionUpdateCounter cntr = counter(partId, DEFAULT_CACHE_NAME, g1.name());
assertNotNull(cntr);
// Counter must be reset.
assertEquals(0, cntr.get());
// Puts done concurrently with clearing after reset should not be lost.
g1.cache(DEFAULT_CACHE_NAME).putAll(keys.stream().collect(Collectors.toMap(k -> k, v -> -1)));
GridTestUtils.waitForCondition(() -> g1.context().cache().context().evict().total() == 0, 30_000);
for (Integer key : keys) assertEquals("key=" + key.toString(), -1, g1.cache(DEFAULT_CACHE_NAME).get(key));
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class GridCacheRebalancingSyncSelfTest method checkPartitionMapExchangeFinished.
/**
*/
public static void checkPartitionMapExchangeFinished() {
for (Ignite g : G.allGrids()) {
IgniteKernal g0 = (IgniteKernal) g;
for (IgniteCacheProxy<?, ?> c : g0.context().cache().jcaches()) {
CacheConfiguration cfg = c.context().config();
if (cfg.getCacheMode() != LOCAL && cfg.getRebalanceMode() != NONE) {
GridDhtCacheAdapter<?, ?> dht = dht(c);
GridDhtPartitionTopology top = dht.topology();
List<GridDhtLocalPartition> locs = top.localPartitions();
for (GridDhtLocalPartition loc : locs) {
GridDhtPartitionState actl = loc.state();
boolean res = GridDhtPartitionState.OWNING.equals(actl);
if (!res)
printPartitionState(c);
assertTrue("Wrong local partition state part=" + loc.id() + ", should be OWNING [state=" + actl + "], node=" + g0.name() + " cache=" + c.getName(), res);
Collection<ClusterNode> affNodes = g0.affinity(cfg.getName()).mapPartitionToPrimaryAndBackups(loc.id());
assertTrue(affNodes.contains(g0.localNode()));
}
for (Ignite remote : G.allGrids()) {
IgniteKernal remote0 = (IgniteKernal) remote;
IgniteCacheProxy<?, ?> remoteC = remote0.context().cache().jcache(cfg.getName());
GridDhtCacheAdapter<?, ?> remoteDht = dht(remoteC);
GridDhtPartitionTopology remoteTop = remoteDht.topology();
GridDhtPartitionMap pMap = remoteTop.partitionMap(true).get(((IgniteKernal) g).localNodeId());
assertEquals(pMap.size(), locs.size());
for (Map.Entry entry : pMap.entrySet()) {
assertTrue("Wrong remote partition state part=" + entry.getKey() + ", should be OWNING [state=" + entry.getValue() + "], node=" + remote.name() + " cache=" + c.getName(), entry.getValue() == GridDhtPartitionState.OWNING);
}
for (GridDhtLocalPartition loc : locs) assertTrue(pMap.containsKey(loc.id()));
}
}
}
}
log.info("checkPartitionMapExchangeFinished finished");
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class IgniteWalHistoryReservationsTest method testRemovesArePreloadedIfHistoryIsAvailable.
/**
* @throws Exception If failed.
*/
@Test
public void testRemovesArePreloadedIfHistoryIsAvailable() throws Exception {
Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10551", MvccFeatureChecker.forcedMvcc());
int entryCnt = 10_000;
IgniteEx ig0 = (IgniteEx) startGrids(2);
ig0.cluster().active(true);
IgniteCache<Integer, Integer> cache = ig0.cache("cache1");
for (int k = 0; k < entryCnt; k++) cache.put(k, k);
stopGrid(1);
for (int k = 0; k < entryCnt; k += 2) cache.remove(k);
IgniteEx ig1 = startGrid(1);
awaitPartitionMapExchange();
IgniteCache<Integer, Integer> cache1 = ig1.cache("cache1");
assertEquals(entryCnt / 2, cache.size());
assertEquals(entryCnt / 2, cache1.size());
for (Integer k = 0; k < entryCnt; k++) {
if (k % 2 == 0) {
assertTrue("k=" + k, !cache.containsKey(k));
assertTrue("k=" + k, !cache1.containsKey(k));
} else {
assertEquals("k=" + k, k, cache.get(k));
assertEquals("k=" + k, k, cache1.get(k));
}
}
for (int p = 0; p < ig1.affinity("cache1").partitions(); p++) {
GridDhtLocalPartition p0 = ig0.context().cache().cache("cache1").context().topology().localPartition(p);
GridDhtLocalPartition p1 = ig1.context().cache().cache("cache1").context().topology().localPartition(p);
assertTrue(p0.updateCounter() > 0);
assertEquals(p0.updateCounter(), p1.updateCounter());
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class IgniteWalHistoryReservationsTest method testNodeIsClearedIfHistoryIsUnavailable.
/**
* @throws Exception If failed.
*/
@Test
public void testNodeIsClearedIfHistoryIsUnavailable() throws Exception {
Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10551", MvccFeatureChecker.forcedMvcc());
int entryCnt = 10_000;
IgniteEx ig0 = (IgniteEx) startGrids(2);
ig0.cluster().active(true);
IgniteCache<Integer, Integer> cache = ig0.cache("cache1");
for (int k = 0; k < entryCnt; k++) cache.put(k, k);
forceCheckpoint();
stopGrid(1);
for (int k = 0; k < entryCnt; k += 2) cache.remove(k);
forceCheckpoint();
for (Integer k = 0; k < entryCnt; k++) {
if (k % 2 == 0)
assertTrue("k=" + k, !cache.containsKey(k));
else
assertEquals("k=" + k, k, cache.get(k));
}
IgniteEx ig1 = startGrid(1);
awaitPartitionMapExchange();
IgniteCache<Integer, Integer> cache1 = ig1.cache("cache1");
assertEquals(entryCnt / 2, cache.size());
assertEquals(entryCnt / 2, cache1.size());
for (Integer k = 0; k < entryCnt; k++) {
if (k % 2 == 0) {
assertTrue("k=" + k, !cache.containsKey(k));
assertTrue("k=" + k, !cache1.containsKey(k));
} else {
assertEquals("k=" + k, k, cache.get(k));
assertEquals("k=" + k, k, cache1.get(k));
}
}
for (int p = 0; p < ig1.affinity("cache1").partitions(); p++) {
GridDhtLocalPartition p0 = ig0.context().cache().cache("cache1").context().topology().localPartition(p);
GridDhtLocalPartition p1 = ig1.context().cache().cache("cache1").context().topology().localPartition(p);
assertTrue(p0.updateCounter() > 0);
assertEquals(p0.updateCounter(), p1.updateCounter());
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class IgnitePdsWithTtlTest method waitAndCheckExpired.
/**
*/
protected void waitAndCheckExpired(IgniteEx srv, final IgniteCache<Integer, byte[]> cache) throws IgniteCheckedException {
boolean awaited = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cache.size() == 0;
}
}, TimeUnit.SECONDS.toMillis(EXPIRATION_TIMEOUT + EXPIRATION_TIMEOUT / 2));
assertTrue("Cache is not empty. size=" + cache.size(), awaited);
printStatistics((IgniteCacheProxy) cache, "After timeout");
GridCacheSharedContext ctx = srv.context().cache().context();
GridCacheContext cctx = ctx.cacheContext(CU.cacheId(CACHE_NAME_ATOMIC));
// Check partitions through internal API.
for (int partId = 0; partId < PART_SIZE; ++partId) {
GridDhtLocalPartition locPart = cctx.dht().topology().localPartition(partId);
if (locPart == null)
continue;
GridCursor cur = locPart.dataStore().cursor();
assertFalse(cur.next());
assertEquals(0, locPart.fullSize());
}
for (int i = 0; i < ENTRIES; i++) assertNull(cache.get(i));
}
Aggregations