Search in sources :

Example 1 with CacheRebalanceMode

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());
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) ArrayList(java.util.ArrayList) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) Test(org.junit.Test) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) IgniteCache(org.apache.ignite.IgniteCache) T2(org.apache.ignite.internal.util.typedef.T2) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) T2(org.apache.ignite.internal.util.typedef.T2) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 2 with CacheRebalanceMode

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());
    }
}
Also used : CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CacheRebalancingEvent(org.apache.ignite.events.CacheRebalancingEvent) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 IgniteCache (org.apache.ignite.IgniteCache)2 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 Collections (java.util.Collections)1 List (java.util.List)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteSystemProperties (org.apache.ignite.IgniteSystemProperties)1 IGNITE_PDS_WAL_REBALANCE_THRESHOLD (org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD)1 ATOMIC (org.apache.ignite.cache.CacheAtomicityMode.ATOMIC)1 REPLICATED (org.apache.ignite.cache.CacheMode.REPLICATED)1 ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 CacheRebalancingEvent (org.apache.ignite.events.CacheRebalancingEvent)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1