Search in sources :

Example 1 with READ_ONLY_SAFE

use of org.apache.ignite.cache.PartitionLossPolicy.READ_ONLY_SAFE in project ignite by apache.

the class CacheBaselineTopologyTest method testBaselineTopologyChanges.

/**
 * @throws Exception If failed.
 */
private void testBaselineTopologyChanges(boolean fromClient) throws Exception {
    startGrids(NODE_COUNT);
    IgniteEx ignite;
    if (fromClient)
        ignite = startClientGrid(NODE_COUNT + 10);
    else
        ignite = grid(0);
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().active(true);
    awaitPartitionMapExchange();
    Map<ClusterNode, Ignite> nodes = new HashMap<>();
    for (int i = 0; i < NODE_COUNT; i++) {
        Ignite ig = grid(i);
        nodes.put(ig.cluster().localNode(), ig);
    }
    ignite.createCache(new CacheConfiguration<Integer, Integer>().setName(CACHE_NAME).setCacheMode(PARTITIONED).setBackups(1).setPartitionLossPolicy(READ_ONLY_SAFE));
    manualCacheRebalancing(ignite, CACHE_NAME);
    int key = -1;
    for (int k = 0; k < 100_000; k++) {
        if (!ignite.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(k).contains(ignite.localNode())) {
            key = k;
            break;
        }
    }
    assert key >= 0;
    Collection<ClusterNode> initialMapping = ignite.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(key);
    assert initialMapping.size() == 2 : initialMapping;
    ignite.cluster().setBaselineTopology(baselineNodes(nodes.keySet()));
    Set<String> stoppedNodeNames = new HashSet<>();
    ClusterNode node = initialMapping.iterator().next();
    stoppedNodeNames.add(nodes.get(node).name());
    nodes.get(node).close();
    nodes.remove(node);
    awaitPartitionMapExchange();
    Collection<ClusterNode> mapping = ignite.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(key);
    assert mapping.size() == 1 : mapping;
    assert initialMapping.containsAll(mapping);
    Set<ClusterNode> blt2 = new HashSet<>(ignite.cluster().nodes());
    ignite.cluster().setBaselineTopology(baselineNodes(blt2.stream().filter(n -> !n.isClient()).collect(Collectors.toSet())));
    awaitPartitionMapExchange();
    Collection<ClusterNode> initialMapping2 = ignite.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(key);
    assert initialMapping2.size() == 2 : initialMapping2;
    Ignite newIgnite = startGrid(NODE_COUNT);
    awaitPartitionMapExchange();
    mapping = ignite.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(key);
    assert mapping.size() == initialMapping2.size() : mapping;
    assert mapping.containsAll(initialMapping2);
    assert ignite.affinity(CACHE_NAME).primaryPartitions(newIgnite.cluster().localNode()).length == 0;
    Set<ClusterNode> blt3 = new HashSet<>(ignite.cluster().nodes());
    ignite.cluster().setBaselineTopology(baselineNodes(blt3.stream().filter(n -> !n.isClient()).collect(Collectors.toSet())));
    awaitPartitionMapExchange();
    Collection<ClusterNode> initialMapping3 = ignite.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(key);
    assert initialMapping3.size() == 2;
    assert ignite.affinity(CACHE_NAME).primaryPartitions(newIgnite.cluster().localNode()).length > 0;
    newIgnite = startGrid(NODE_COUNT + 1);
    awaitPartitionMapExchange();
    mapping = ignite.affinity(CACHE_NAME).mapKeyToPrimaryAndBackups(key);
    assert mapping.size() == initialMapping3.size() : mapping;
    assert mapping.containsAll(initialMapping3);
    assert ignite.affinity(CACHE_NAME).primaryPartitions(newIgnite.cluster().localNode()).length == 0;
    ignite.cluster().setBaselineTopology(null);
    awaitPartitionMapExchange();
    assert ignite.affinity(CACHE_NAME).primaryPartitions(newIgnite.cluster().localNode()).length > 0;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DetachedClusterNode(org.apache.ignite.internal.cluster.DetachedClusterNode) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Random(java.util.Random) Callable(java.util.concurrent.Callable) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Map(java.util.Map) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) CachePeekMode(org.apache.ignite.cache.CachePeekMode) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) BaselineNode(org.apache.ignite.cluster.BaselineNode) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) DetachedClusterNode(org.apache.ignite.internal.cluster.DetachedClusterNode) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) READ_ONLY_SAFE(org.apache.ignite.cache.PartitionLossPolicy.READ_ONLY_SAFE) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteException (org.apache.ignite.IgniteException)1 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)1 CacheMode (org.apache.ignite.cache.CacheMode)1 PARTITIONED (org.apache.ignite.cache.CacheMode.PARTITIONED)1 CachePeekMode (org.apache.ignite.cache.CachePeekMode)1 FULL_SYNC (org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC)1