use of org.apache.ignite.cache.CacheRebalanceMode in project ignite by apache.
the class PartitionEvictionOrderTest method testSyncCachesEvictedAtFirst.
/**
* Tests that {@link CacheRebalanceMode#SYNC} caches are evicted at first.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_EVICTION_PERMITS, value = "1")
@WithSystemProperty(key = IGNITE_PDS_WAL_REBALANCE_THRESHOLD, value = "500_000")
public void testSyncCachesEvictedAtFirst() throws Exception {
IgniteEx node0 = startGrid(0);
node0.cluster().state(ACTIVE);
IgniteEx node1 = startGrid(1);
node0.cluster().setBaselineTopology(node1.cluster().topologyVersion());
GridCacheAdapter<Object, Object> utilCache0 = grid(0).context().cache().internalCache(CU.UTILITY_CACHE_NAME);
IgniteCache<Object, Object> cache = node0.getOrCreateCache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 1000; i++) {
utilCache0.put(i, i);
cache.put(i, i);
}
awaitPartitionMapExchange();
stopGrid(0);
GridCacheAdapter<Object, Object> utilCache1 = grid(1).context().cache().internalCache(CU.UTILITY_CACHE_NAME);
IgniteInternalCache<Object, Object> cache2 = grid(1).context().cache().cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 2000; i++) {
try {
cache2.put(i, i + 1);
utilCache1.put(i, i + 1);
} catch (IgniteCheckedException e) {
e.printStackTrace();
}
}
List<T2<Integer, Integer>> evictionOrder = Collections.synchronizedList(new ArrayList<>());
TestDependencyResolver rslvr = new TestDependencyResolver(new DependencyResolver() {
@Override
public <T> T resolve(T instance) {
if (instance instanceof GridDhtPartitionTopologyImpl) {
GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) instance;
top.partitionFactory((ctx, grp, id, recovery) -> new GridDhtLocalPartition(ctx, grp, id, recovery) {
@Override
public long clearAll(EvictionContext evictionCtx) throws NodeStoppingException {
evictionOrder.add(new T2<>(grp.groupId(), id));
return super.clearAll(evictionCtx);
}
});
}
return instance;
}
});
startGrid(0, rslvr);
awaitPartitionMapExchange(true, true, null);
assertEquals(utilCache0.affinity().partitions() + grid(0).cachex(DEFAULT_CACHE_NAME).affinity().partitions(), evictionOrder.size());
for (int i = 0; i < utilCache0.affinity().partitions(); i++) assertEquals(CU.UTILITY_CACHE_GROUP_ID, evictionOrder.get(i).get1().intValue());
}
use of org.apache.ignite.cache.CacheRebalanceMode in project ignite by apache.
the class GridCacheRebalanceOrderTest method testRebalanceOrderBasedOnCacheRebalanceMode.
/**
* Tests that caches with rebalance mode equals to SYNC are rebalanced in the first place.
*
* @throws Exception If failed.
*/
@Test
public void testRebalanceOrderBasedOnCacheRebalanceMode() throws Exception {
Ignite g = startGrid(0);
// Fix the expected order of rebalance.
List<IgniteBiTuple<Integer, CacheRebalanceMode>> order = new ArrayList<>();
order.add(new T2<>(0, SYNC));
order.add(new T2<>(0, SYNC));
order.add(new T2<>(0, ASYNC));
order.add(new T2<>(0, ASYNC));
order.add(new T2<>(1, SYNC));
order.add(new T2<>(1, SYNC));
order.add(new T2<>(1, ASYNC));
order.add(new T2<>(1, ASYNC));
// Prepare caches with different rebalance mode and order.
List<IgniteCache<Integer, Integer>> caches = new ArrayList<>();
for (int i = order.size() - 1; i >= 0; i--) {
int rebalanceOrder = order.get(i).get1();
CacheRebalanceMode rebalanceMode = order.get(i).get2();
caches.add(g.getOrCreateCache(getCacheConfiguration("cache-" + i + "-order-" + rebalanceOrder + "-mode-" + rebalanceMode, rebalanceOrder, rebalanceMode)));
}
// Fill values.
for (IgniteCache<Integer, Integer> c : caches) c.put(12, 21);
trackRebalanceEvts = true;
Ignite g1 = startGrid(1);
// Wait for all rebalance futures.
for (IgniteCache<Integer, Integer> c : caches) grid(1).context().cache().internalCache(c.getName()).preloader().syncFuture().get(REBALANCE_TIMEOUT);
// Check that all events were fired.
assertEquals("Expected rebalance events were not triggered.", order.size(), evtsList.size());
// Check rebelance order.
for (int i = 0; i < order.size(); ++i) {
int expOrder = order.get(i).get1();
CacheRebalanceMode expMode = order.get(i).get2();
CacheRebalancingEvent actualEvt = evtsList.get(i);
CacheConfiguration<Integer, Integer> actualCfg = g1.cache(actualEvt.cacheName()).getConfiguration(CacheConfiguration.class);
assertEquals("Unexpected rebalance order [cacheName=" + actualEvt.cacheName() + ']', expOrder, actualCfg.getRebalanceOrder());
assertEquals("Unexpected cache rebalance mode [cacheName=" + actualEvt.cacheName() + ']', expMode, actualCfg.getRebalanceMode());
}
}
Aggregations