You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2021/04/02 15:40:47 UTC

[ignite] branch master updated: IGNITE-14439 Re-fixed NPE when accessing clustername before first exchange finished - Fixes #8944.

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

ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 92b3f1a  IGNITE-14439 Re-fixed NPE when accessing clustername before first exchange finished - Fixes #8944.
92b3f1a is described below

commit 92b3f1a999d29c5e95847097e150db977e475acc
Author: pvinokurov <vi...@gmail.com>
AuthorDate: Fri Apr 2 18:39:55 2021 +0300

    IGNITE-14439 Re-fixed NPE when accessing clustername before first exchange finished - Fixes #8944.
    
    Signed-off-by: Ilya Kasnacheev <il...@gmail.com>
---
 .../processors/cache/GridCacheProcessor.java       |  7 ----
 .../processors/cluster/ClusterProcessor.java       |  7 ++++
 .../ClusterNameBeforeActivation.java}              | 38 +++++++++++-----------
 .../ignite/testsuites/IgniteCacheTestSuite9.java   |  4 +--
 4 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 7c1d13d..6b5e493 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -4432,13 +4432,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @return Cache.
      */
     private <K, V> IgniteInternalCache<K, V> internalCacheEx(String name) {
-        try {
-            awaitStarted();
-        }
-        catch (IgniteCheckedException e) {
-            throw U.convertException(e);
-        }
-
         if (ctx.discovery().localNode().isClient()) {
             IgniteCacheProxy<K, V> proxy = (IgniteCacheProxy<K, V>)jcacheProxy(name, true);
 
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java
index 7625368..f81c162 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java
@@ -855,6 +855,13 @@ public class ClusterProcessor extends GridProcessorAdapter implements Distribute
      * @return Cluster name.
      * */
     public String clusterName() {
+        try {
+            ctx.cache().awaitStarted();
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+
         return IgniteSystemProperties.getString(
             IGNITE_CLUSTER_NAME,
             ctx.cache().utilityCache().context().dynamicDeploymentId().toString()
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadBeforeActivationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterNameBeforeActivation.java
similarity index 72%
rename from modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadBeforeActivationTest.java
rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterNameBeforeActivation.java
index 0059940..c15a65e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadBeforeActivationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterNameBeforeActivation.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.internal.processors.cache;
+package org.apache.ignite.internal.processors.cluster;
 
 import java.io.Serializable;
 import java.util.concurrent.CountDownLatch;
@@ -26,7 +26,6 @@ import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteCallable;
 import org.apache.ignite.plugin.AbstractTestPluginProvider;
@@ -34,10 +33,10 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.junit.Test;
 
 /**
- * Tests that caches could not be accessed before activation.
+ * Tests that cluster name could not be accessed before system cache initialized.
  */
-public class CacheReadBeforeActivationTest extends GridCommonAbstractTest {
-    /** Activation latch.*/
+public class ClusterNameBeforeActivation extends GridCommonAbstractTest {
+    /** Activation latch. */
     private CountDownLatch latch;
 
     /** {@inheritDoc} */
@@ -50,18 +49,17 @@ public class CacheReadBeforeActivationTest extends GridCommonAbstractTest {
     }
 
     /**
-     * Tests that reading from the utility system cache waits until activation finished.
-     * Scenario:
-     *  <ul>
-     *      <li>Start a server node.</li>
-     *      <li>Start a client node with the plugin provider delaying activation.</li>
-     *      <li>Run a job on the client node that reads from the utility cache.</li>
-     *  </ul>
+     * Tests that getting the cluster name cache waits until system cache started. Scenario:
+     * <ul>
+     *     <li>Start a server node.</li>
+     *     <li>Start a client node with the plugin provider delaying activation and system cache initalization.</li>
+     *     <li>Run a job on the client node that gets the cluster name.</li>
+     * </ul>
      *
      * @throws Exception If failed.
      */
     @Test
-    public void readUtilityCacheBeforeActivationFinished() throws Exception {
+    public void testGetClusterNameBeforeSystemCacheStarted() throws Exception {
         IgniteEx ignite = startGrid(0);
 
         latch = new CountDownLatch(1);
@@ -70,12 +68,13 @@ public class CacheReadBeforeActivationTest extends GridCommonAbstractTest {
 
         latch.await(1, TimeUnit.MINUTES);
 
-        // try to access the utility cache before activation finished and starting exchange on the client node.
-        ignite.compute(ignite.cluster().forClients()).call(new IgniteCallable<Object>() {
-            @Override public Object call() throws Exception {
-                return ((IgniteEx)Ignition.localIgnite()).context().cache().utilityCache().get("1");
+        String clusterName = ignite.compute(ignite.cluster().forClients()).call(new IgniteCallable<String>() {
+            @Override public String call() throws Exception {
+                return ((IgniteEx)Ignition.localIgnite()).context().cluster().clusterName();
             }
         });
+
+        assertNotNull(clusterName);
     }
 
     /**
@@ -93,10 +92,11 @@ public class CacheReadBeforeActivationTest extends GridCommonAbstractTest {
 
         /** {@inheritDoc} */
         @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException {
-            if (latch != null)
+            if (latch != null) {
                 latch.countDown();
 
-            U.sleep(2_000);
+                U.sleep(2_000);
+            }
         }
 
         /** {@inheritDoc} */
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java
index 1cd4977..b3999b3 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java
@@ -33,7 +33,6 @@ import org.apache.ignite.internal.metric.ReadMetricsOnNodeStartupTest;
 import org.apache.ignite.internal.metric.SystemViewComputeJobTest;
 import org.apache.ignite.internal.metric.SystemViewSelfTest;
 import org.apache.ignite.internal.processors.cache.CachePutIfAbsentTest;
-import org.apache.ignite.internal.processors.cache.CacheReadBeforeActivationTest;
 import org.apache.ignite.internal.processors.cache.GridCacheDataTypesCoverageTest;
 import org.apache.ignite.internal.processors.cache.GridCacheLongRunningTransactionDiagnosticsTest;
 import org.apache.ignite.internal.processors.cache.GridCacheVersionGenerationWithCacheStorageTest;
@@ -63,6 +62,7 @@ import org.apache.ignite.internal.processors.cache.transactions.TxPartitionCount
 import org.apache.ignite.internal.processors.cache.transactions.TxPartitionCounterStateTwoPrimaryTwoBackupsTest;
 import org.apache.ignite.internal.processors.cache.transactions.TxPartitionCounterStateWithFilterTest;
 import org.apache.ignite.internal.processors.cache.transactions.TxRecoveryOnCoordniatorFailTest;
+import org.apache.ignite.internal.processors.cluster.ClusterNameBeforeActivation;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.DynamicSuite;
 import org.junit.runner.RunWith;
@@ -144,7 +144,7 @@ public class IgniteCacheTestSuite9 {
         GridTestUtils.addTestIfNeeded(suite, RebalanceStatisticsTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, TxRecoveryOnCoordniatorFailTest.class, ignoredTests);
 
-        GridTestUtils.addTestIfNeeded(suite, CacheReadBeforeActivationTest.class, ignoredTests);
+        GridTestUtils.addTestIfNeeded(suite, ClusterNameBeforeActivation.class, ignoredTests);
 
         return suite;
     }