You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2023/01/11 15:23:51 UTC

[ignite] branch ignite-18494 created (now 43280272bf2)

This is an automated email from the ASF dual-hosted git repository.

ivandasch pushed a change to branch ignite-18494
in repository https://gitbox.apache.org/repos/asf/ignite.git


      at 43280272bf2 IGNITE-18494 Fix ignoring near cache configuration while starting cache not from affinity node.

This branch includes the following new commits:

     new 43280272bf2 IGNITE-18494 Fix ignoring near cache configuration while starting cache not from affinity node.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[ignite] 01/01: IGNITE-18494 Fix ignoring near cache configuration while starting cache not from affinity node.

Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ivandasch pushed a commit to branch ignite-18494
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 43280272bf20a6af0402066eae75a63e455d22e9
Author: Ivan Daschinsky <iv...@apache.org>
AuthorDate: Wed Jan 11 18:23:12 2023 +0300

    IGNITE-18494 Fix ignoring near cache configuration while starting cache not from affinity node.
---
 .../cache/DynamicCacheChangeRequest.java           |   3 +
 .../near/GridCacheNearDynamicStartTest.java        | 157 +++++++++++++++++++++
 .../ignite/testsuites/IgniteCacheTestSuite2.java   |   2 +
 3 files changed, 162 insertions(+)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
index 399c2cd1c77..e0e6037a856 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
@@ -371,6 +371,9 @@ public class DynamicCacheChangeRequest implements Serializable {
      */
     public void startCacheConfiguration(CacheConfiguration startCfg) {
         this.startCfg = startCfg;
+
+        if (startCfg.getNearConfiguration() != null)
+            nearCacheCfg = startCfg.getNearConfiguration();
     }
 
     /**
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearDynamicStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearDynamicStartTest.java
new file mode 100644
index 00000000000..3f43e5710f9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearDynamicStartTest.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.near;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ * Tests that dynamically started caches with near configurations actually start with near caches on all nodes:
+ * affinity, non-affinity and clients.
+ */
+@RunWith(Parameterized.class)
+public class GridCacheNearDynamicStartTest extends GridCommonAbstractTest {
+    /** */
+    private static final int SRV_CNT = 3;
+
+    /** */
+    private static final String CLIENT_ID = "client";
+
+    /** */
+    @Parameterized.Parameters(name = "nodeCacheStart = {0}, nodeNearCheck = {1}")
+    public static Iterable<Object[]> useBinaryArrays() {
+        List<Object[]> params = new ArrayList<>();
+
+        for (NODE_TYPE nodeStart: NODE_TYPE.values()) {
+            for (NODE_TYPE nodeNearCheck: NODE_TYPE.values())
+                params.add(new Object[]{ nodeStart, nodeNearCheck});
+        }
+
+        return params;
+    }
+
+    /** */
+    @Parameterized.Parameter(0)
+    public NODE_TYPE nodeStart;
+
+    /** */
+    @Parameterized.Parameter(1)
+    public NODE_TYPE nodeCheck;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(SRV_CNT);
+        startClientGrid(CLIENT_ID);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        IgniteEx ign = grid(0);
+
+        ign.cacheNames().forEach(ign::destroyCache);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName).setConsistentId(igniteInstanceName);
+    }
+
+    /** */
+    @Test
+    public void test() throws Exception {
+        startCache();
+
+        IgniteEx ign = testNode(nodeCheck);
+
+        IntStream.range(0, 1000).boxed().forEach(i -> {
+            IgniteCache<Integer, Integer> cache = ign.cache(DEFAULT_CACHE_NAME);
+
+            assertEquals(i, cache.get(i));
+
+            if (ign.affinity(DEFAULT_CACHE_NAME).isPrimary(ign.localNode(), i))
+                return;
+
+            assertEquals(i, cache.localPeek(i, CachePeekMode.NEAR));
+        });
+    }
+
+    /** */
+    private void startCache() {
+        Ignite ign = testNode(nodeStart);
+
+        IgniteCache<Integer, Integer> cache = ign.createCache(
+            new CacheConfiguration<Integer, Integer>(DEFAULT_CACHE_NAME)
+                .setNodeFilter(n -> {
+                    if (n.consistentId() == null)
+                        return false;
+
+                    // Start cache on nodes with indices [0, 1].
+                    return !n.consistentId().toString().contains(String.valueOf(SRV_CNT - 1));
+                })
+                .setNearConfiguration(new NearCacheConfiguration<>())
+        );
+
+        cache.putAll(
+            IntStream.range(0, 1000).boxed().collect(
+                Collectors.toMap(Function.identity(), Function.identity(), (i, j) -> i, TreeMap::new)
+            )
+        );
+
+        assertEquals(ign.cache(DEFAULT_CACHE_NAME).size(CachePeekMode.PRIMARY), 1000);
+    }
+
+    /** */
+    private IgniteEx testNode(NODE_TYPE type) {
+        switch (type) {
+            case AFFINITY:
+                return grid(SRV_CNT - 2);
+            case NON_AFFINITY:
+                return grid(SRV_CNT - 1);
+            case CLIENT:
+            default:
+                return grid(CLIENT_ID);
+        }
+    }
+
+    /** */
+    private enum NODE_TYPE {
+        /** Affinity node. */
+        AFFINITY,
+
+        /** Non affinity node. */
+        NON_AFFINITY,
+
+        /** Client node. */
+        CLIENT,
+    }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
index b3ca245f7ba..0c44992d8e4 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
@@ -114,6 +114,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAto
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearMultiNodeSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearReadersSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearClientHitTest;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearDynamicStartTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearEvictionEventSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearJobExecutionSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheNearMultiGetSelfTest;
@@ -266,6 +267,7 @@ public class IgniteCacheTestSuite2 {
 
         GridTestUtils.addTestIfNeeded(suite, GridCacheOffheapUpdateSelfTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, GridCacheNearClientHitTest.class, ignoredTests);
+        GridTestUtils.addTestIfNeeded(suite, GridCacheNearDynamicStartTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, GridCacheNearPrimarySyncSelfTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, GridCacheColocatedPrimarySyncSelfTest.class, ignoredTests);