You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2020/08/24 14:28:32 UTC

[ignite] branch master updated: IGNITE-13072 Synchronization problems when different classloaders are used for deployment of same class. - Fixes #7847.

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

sergeychugunov 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 d8f01c5  IGNITE-13072 Synchronization problems when different classloaders are used for deployment of same class. - Fixes #7847.
d8f01c5 is described below

commit d8f01c58fc83ea83856034afc400c4118ff550c8
Author: Vladislav Pyatkov <vl...@gmail.com>
AuthorDate: Mon Aug 24 16:50:40 2020 +0300

    IGNITE-13072 Synchronization problems when different classloaders are used for deployment of same class. - Fixes #7847.
    
    Signed-off-by: Sergey Chugunov <se...@gmail.com>
---
 .../deployment/GridDeploymentLocalStore.java       |  67 +++++-----
 .../RaceOnDeployClassesWithSameAliases.java        | 147 +++++++++++++++++++++
 .../ignite/testsuites/IgniteP2PSelfTestSuite.java  |   2 +
 3 files changed, 186 insertions(+), 30 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
index c308f85..89d7bcf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
@@ -184,40 +184,43 @@ class GridDeploymentLocalStore extends GridDeploymentStoreAdapter {
                 return null;
             }
 
-            try {
-                // Check that class can be loaded.
-                String clsName = meta.className();
+            while (true) {
+                try {
+                    // Check that class can be loaded.
+                    String clsName = meta.className();
 
-                Class<?> cls = U.forName(clsName != null ? clsName : alias, ldr);
+                    Class<?> cls = U.forName(clsName != null ? clsName : alias, ldr);
 
-                spi.register(ldr, cls);
+                    spi.register(ldr, cls);
 
-                rsrc = spi.findResource(cls.getName());
+                    rsrc = spi.findResource(cls.getName());
 
-                if (rsrc != null && rsrc.getResourceClass().equals(cls)) {
-                    if (log.isDebugEnabled())
-                        log.debug("Retrieved auto-loaded resource from spi: " + rsrc);
+                    if (rsrc != null && rsrc.getResourceClass().equals(cls)) {
+                        if (log.isDebugEnabled())
+                            log.debug("Retrieved auto-loaded resource from spi: " + rsrc);
 
-                    dep = deploy(ctx.config().getDeploymentMode(), ldr, cls, meta.alias(), meta.record());
+                        dep = deploy(ctx.config().getDeploymentMode(), ldr, cls, meta.alias(), meta.record());
 
-                    assert dep != null;
+                        if (dep != null)
+                            return dep;
+                    }
+                    else {
+                        U.warn(log, "Failed to find resource from deployment SPI even after registering: " + meta);
+
+                        return null;
+                    }
                 }
-                else {
-                    U.warn(log, "Failed to find resource from deployment SPI even after registering: " + meta);
+                catch (ClassNotFoundException ignored) {
+                    if (log.isDebugEnabled())
+                        log.debug("Failed to load class for local auto-deployment [ldr=" + ldr + ", meta=" + meta + ']');
 
                     return null;
                 }
-            }
-            catch (ClassNotFoundException ignored) {
-                if (log.isDebugEnabled())
-                    log.debug("Failed to load class for local auto-deployment [ldr=" + ldr + ", meta=" + meta + ']');
+                catch (IgniteSpiException e) {
+                    U.error(log, "Failed to deploy local class with meta: " + meta, e);
 
-                return null;
-            }
-            catch (IgniteSpiException e) {
-                U.error(log, "Failed to deploy local class with meta: " + meta, e);
-
-                return null;
+                    return null;
+                }
             }
         }
 
@@ -353,16 +356,20 @@ class GridDeploymentLocalStore extends GridDeploymentStoreAdapter {
             if (clsLdr.getClass().equals(GridDeploymentClassLoader.class))
                 clsLdr = clsLdr.getParent();
 
-            spi.register(clsLdr, cls);
+            GridDeployment dep = null;
 
-            GridDeployment dep = deployment(cls.getName());
+            while (dep == null) {
+                spi.register(clsLdr, cls);
 
-            if (dep == null) {
-                DeploymentResource rsrc = spi.findResource(cls.getName());
+                dep = deployment(cls.getName());
 
-                if (rsrc != null && rsrc.getClassLoader() == clsLdr)
-                    dep = deploy(ctx.config().getDeploymentMode(), rsrc.getClassLoader(),
-                        rsrc.getResourceClass(), rsrc.getName(), true);
+                if (dep == null) {
+                    DeploymentResource rsrc = spi.findResource(cls.getName());
+
+                    if (rsrc != null && rsrc.getClassLoader() == clsLdr)
+                        dep = deploy(ctx.config().getDeploymentMode(), rsrc.getClassLoader(),
+                            rsrc.getResourceClass(), rsrc.getName(), true);
+                }
             }
 
             return dep;
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/RaceOnDeployClassesWithSameAliases.java b/modules/core/src/test/java/org/apache/ignite/internal/RaceOnDeployClassesWithSameAliases.java
new file mode 100644
index 0000000..3f9b923
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/RaceOnDeployClassesWithSameAliases.java
@@ -0,0 +1,147 @@
+/*
+ * 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;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeTaskAdapter;
+import org.apache.ignite.compute.ComputeTaskName;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+import org.junit.Test;
+
+/**
+ * Tets reproduces issue which can happens deploing classes to local store from difference class loaders.
+ */
+@GridCommonTest(group = "P2P")
+public class RaceOnDeployClassesWithSameAliases extends GridCommonAbstractTest {
+    /** Listening logger. */
+    private final ListeningTestLogger listeningLog = new ListeningTestLogger(true, log);
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        listeningLog.clearListeners();
+
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setGridLogger(listeningLog)
+            .setPeerClassLoadingEnabled(true)
+            .setFailureHandler(new StopNodeFailureHandler())
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
+    }
+
+    /**
+     * Test loads class with same alias in time another class deploying.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void test() throws Exception {
+        setRootLoggerDebugLevel();
+
+        IgniteEx crd = startGrids(1);
+
+        Ignite client = startClientGrid("client");
+
+        awaitPartitionMapExchange();
+
+        AtomicBoolean deployed = new AtomicBoolean();
+
+        LogListener logLsnr = LogListener.matches(logStr -> {
+            if (logStr.startsWith("Retrieved auto-loaded resource from spi:") &&
+                logStr.contains(TestCacheEntryProcessor.class.getSimpleName())) {
+
+                if (deployed.compareAndSet(false, true)) {
+                    System.out.println("dirty getting a breakdown location " + logStr);
+
+                    crd.compute().localDeployTask(TestTask.class, new TestClassLoader());
+                }
+                return true;
+            }
+
+            return false;
+        }).build();
+
+        listeningLog.registerListener(logLsnr);
+
+        client.cache(DEFAULT_CACHE_NAME).invoke(1, new TestCacheEntryProcessor());
+
+        assertTrue(logLsnr.check());
+    }
+
+    /**
+     * Test entry processor.
+     */
+    private static class TestCacheEntryProcessor implements CacheEntryProcessor<Object, Object, Object> {
+        /** {@inheritDoc} */
+        @Override public Object process(
+            MutableEntry<Object, Object> entry,
+            Object... objects
+        ) throws EntryProcessorException {
+            return 2;
+        }
+    }
+
+    /**
+     * That is a compute task with same aliase as entry processor {@link TestCacheEntryProcessor}.
+     */
+    @ComputeTaskName("org.apache.ignite.internal.RaceOnDeployClassesWithSameAliases$TestCacheEntryProcessor")
+    private static class TestTask extends ComputeTaskAdapter<Object, Object> {
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Object arg) {
+            assert false;
+
+            return Collections.emptyMap();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            return new Object();
+        }
+    }
+
+    /**
+     * Test {@link ClassLoader}.
+     */
+    private static class TestClassLoader extends ClassLoader {
+        /** {@inheritDoc} */
+        @Override protected Class<?> findClass(String name) throws ClassNotFoundException {
+            return Thread.currentThread().getContextClassLoader().loadClass(name);
+        }
+    }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteP2PSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteP2PSelfTestSuite.java
index a054104..0813094 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteP2PSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteP2PSelfTestSuite.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.testsuites;
 
+import org.apache.ignite.internal.RaceOnDeployClassesWithSameAliases;
 import org.apache.ignite.internal.managers.deployment.GridDeploymentMessageCountSelfTest;
 import org.apache.ignite.p2p.DeploymentClassLoaderCallableTest;
 import org.apache.ignite.p2p.GridP2PClassLoadingSelfTest;
@@ -69,6 +70,7 @@ import org.junit.runners.Suite;
     GridDeploymentMessageCountSelfTest.class,
     GridP2PComputeWithNestedEntryProcessorTest.class,
     GridP2PCountTiesLoadClassDirectlyFromClassLoaderTest.class,
+    RaceOnDeployClassesWithSameAliases.class,
     GridP2PScanQueryWithTransformerTest.class
 })
 public class IgniteP2PSelfTestSuite {