You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2020/06/25 13:03:07 UTC

[ignite] branch master updated: IGNITE-13010 Fixed NPE during handle of EVT_CACHE_STOPPED event (#7921)

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

nizhikov 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 6ed72a5  IGNITE-13010 Fixed NPE during handle of EVT_CACHE_STOPPED event (#7921)
6ed72a5 is described below

commit 6ed72a509a3d9a2a6e8d7784ddc4dfaad0411731
Author: Denis Garus <ga...@gmail.com>
AuthorDate: Thu Jun 25 16:02:41 2020 +0300

    IGNITE-13010 Fixed NPE during handle of EVT_CACHE_STOPPED event (#7921)
---
 .../ignite/internal/GridEventConsumeHandler.java   | 12 +++---
 .../cache/IgniteDynamicCacheStartSelfTest.java     | 45 ++++++++++++++++++++--
 2 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java
index 786eb18..5cfafad 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java
@@ -38,7 +38,6 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
 import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheDeployable;
 import org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager;
 import org.apache.ignite.internal.processors.continuous.GridContinuousBatch;
@@ -233,17 +232,16 @@ class GridEventConsumeHandler implements GridContinuousHandler {
                                                     if (node == null)
                                                         continue;
 
-                                                    if (ctx.config().isPeerClassLoadingEnabled()) {
-                                                        GridCacheContext cctx =
-                                                            ctx.cache().internalCache(cacheName).context();
+                                                    if (ctx.config().isPeerClassLoadingEnabled() &&
+                                                        ctx.discovery().cacheNode(node, cacheName)) {
+                                                        GridCacheAdapter cache = ctx.cache().internalCache(cacheName);
 
-                                                        if (cctx.deploymentEnabled() &&
-                                                            ctx.discovery().cacheNode(node, cacheName)) {
+                                                        if (cache != null && cache.context().deploymentEnabled()) {
                                                             wrapper.p2pMarshal(ctx.config().getMarshaller());
 
                                                             wrapper.cacheName = cacheName;
 
-                                                            cctx.deploy().prepare(wrapper);
+                                                            cache.context().deploy().prepare(wrapper);
                                                         }
                                                     }
                                                 }
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
index dcb6d2b..7648ec6 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.UUID;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.CountDownLatch;
@@ -58,6 +59,9 @@ import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.junit.Test;
 
+import static org.apache.ignite.events.EventType.EVT_CACHE_STARTED;
+import static org.apache.ignite.events.EventType.EVT_CACHE_STOPPED;
+
 /**
  * Test for dynamic cache start.
  */
@@ -114,7 +118,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
 
         cfg.setCacheConfiguration(cacheCfg);
 
-        cfg.setIncludeEventTypes(EventType.EVT_CACHE_STARTED, EventType.EVT_CACHE_STOPPED, EventType.EVT_CACHE_NODES_LEFT);
+        cfg.setIncludeEventTypes(EVT_CACHE_STARTED, EVT_CACHE_STOPPED, EventType.EVT_CACHE_NODES_LEFT);
 
         if (daemon)
             cfg.setDaemon(true);
@@ -779,12 +783,12 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
             lsnrs[i] = new IgnitePredicate<CacheEvent>() {
                 @Override public boolean apply(CacheEvent e) {
                     switch (e.type()) {
-                        case EventType.EVT_CACHE_STARTED:
+                        case EVT_CACHE_STARTED:
                             starts[idx].countDown();
 
                             break;
 
-                        case EventType.EVT_CACHE_STOPPED:
+                        case EVT_CACHE_STOPPED:
                             stops[idx].countDown();
 
                             break;
@@ -821,6 +825,41 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
             ignite(i).events().stopLocalListen(lsnrs[i]);
     }
 
+    /** */
+    @Test
+    public void testRemoteListenShouldGetCacheEventFromEveryNode() throws Exception {
+        CountDownLatch[] evts = new CountDownLatch[] {new CountDownLatch(nodeCount())};
+        int[] evtType = new int[] {EVT_CACHE_STARTED};
+
+        UUID lsnrId = ignite(0).events().remoteListen((uuid, evt) -> {
+            assertEquals(DYNAMIC_CACHE_NAME, ((CacheEvent)evt).cacheName());
+            assertEquals(evt.type(), evtType[0]);
+
+            evts[0].countDown();
+
+            return true;
+        }, evt -> true, EventType.EVTS_CACHE_LIFECYCLE);
+
+        try {
+            IgniteCache<Object, Object> cache = ignite(0).createCache(DYNAMIC_CACHE_NAME);
+
+            evts[0].await(10, TimeUnit.SECONDS);
+
+            evts[0] = new CountDownLatch(nodeCount());
+            evtType[0] = EVT_CACHE_STOPPED;
+
+            cache.destroy();
+
+            evts[0].await(10, TimeUnit.SECONDS);
+        }
+        finally {
+            ignite(0).events().stopRemoteListen(lsnrId);
+
+            if (ignite(0).cache(DYNAMIC_CACHE_NAME) != null)
+                ignite(0).cache(DYNAMIC_CACHE_NAME).destroy();
+        }
+    }
+
     /**
      * @throws Exception If failed.
      */