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

zstan 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 cd88050f46d IGNITE-29181 P2P in SHARED mode a job class is requested 
from a neighbour client that does not have it (#13718)
cd88050f46d is described below

commit cd88050f46d880f2d5b3b8d30f7be0b55812420b
Author: Evgeniy Stanilovskiy <[email protected]>
AuthorDate: Fri Oct 23 08:35:58 2026 +0300

    IGNITE-29181 P2P in SHARED mode a job class is requested from a neighbour 
client that does not have it (#13718)
---
 .../deployment/GridDeploymentClassLoader.java      |  75 ++++--
 .../deployment/GridDeploymentPerVersionStore.java  |  67 ++---
 .../p2p/GridP2PClientDeploymentSourceTest.java     | 292 +++++++++++++++++++++
 .../apache/ignite/p2p/SharedDeploymentTest.java    |  28 ++
 .../ignite/testsuites/IgniteP2PSelfTestSuite.java  |   2 +
 5 files changed, 407 insertions(+), 57 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentClassLoader.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentClassLoader.java
index ebafda4291f..4f723f26538 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentClassLoader.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentClassLoader.java
@@ -319,6 +319,19 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
      * @param ldrId Participating class loader id.
      */
     void register(UUID nodeId, IgniteUuid ldrId) {
+        register(nodeId, ldrId, true);
+    }
+
+    /**
+     * Adds new node and remote class loader id to this class loader.
+     * Class loader will ask all associated nodes for the class/resource
+     * until find it.
+     *
+     * @param nodeId Participating node ID.
+     * @param ldrId Participating class loader id.
+     * @param first {@code True} to ask the node first, {@code false} to ask 
it after the already registered nodes.
+     */
+    void register(UUID nodeId, IgniteUuid ldrId, boolean first) {
         assert nodeId != null;
         assert ldrId != null;
         assert nodeId.equals(ldrId.globalId());
@@ -328,16 +341,14 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
             if (missedRsrcs != null)
                 missedRsrcs.clear();
 
-            /*
-             * We need to put passed in node into the
-             * first position in the list.
-             */
-
             // 1. Remove passed in node if any.
             nodeList.remove(nodeId);
 
-            // 2. Add passed in node to the first position.
-            nodeList.addFirst(nodeId);
+            // 2. Add passed in node to the requested position.
+            if (first)
+                nodeList.addFirst(nodeId);
+            else
+                nodeList.addLast(nodeId);
 
             // 3. Put to map.
             nodeLdrMap.put(nodeId, ldrId);
@@ -610,6 +621,8 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
 
         List<IgniteException> clsReqExceptions = new ArrayList<>();
 
+        boolean notFound = false;
+
         for (UUID nodeId : nodeListCp) {
             if (nodeId.equals(ctx.discovery().localNode().id()))
                 // Skip local node as it is already used as parent class 
loader.
@@ -632,21 +645,18 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
                 if (res.success())
                     return res.byteSource();
                 else {
-                    // In case of shared resources/classes all nodes should 
have it.
-                    String msg = "Failed to find class on remote node [class=" 
+ name + ", nodeId=" + node.id() +
-                        ", clsLdrId=" + ldrId + ", classLoadersHierarchy=" + 
clsLdrHierarchy +
+                    // Participants of a shared deployment are not guaranteed 
to have the same class path (a node joins
+                    // the deployment as soon as it is able to load one of its 
classes), so keep asking the other nodes.
+                    String msg = "Failed to find class on remote node (will 
try other nodes, if any) [class=" + name +
+                        ", nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", 
classLoadersHierarchy=" + clsLdrHierarchy +
                         ", reason=" + res.errorMessage() + ']';
 
-                    LT.warn(log, msg);
+                    if (log.isDebugEnabled())
+                        log.debug(msg);
 
                     clsReqExceptions.add(new IgniteException(msg));
 
-                    synchronized (mux) {
-                        if (missedRsrcs != null)
-                            missedRsrcs.add(path);
-                    }
-
-                    break;
+                    notFound = true;
                 }
             }
             catch (IgniteCheckedException e) {
@@ -688,6 +698,14 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
             }
         }
 
+        // Cache the miss only after none of the nodes was able to provide the 
class.
+        if (notFound) {
+            synchronized (mux) {
+                if (missedRsrcs != null)
+                    missedRsrcs.add(path);
+            }
+        }
+
         if (!clsReqExceptions.isEmpty()) {
             IgniteException ex = clsReqExceptions.remove(0);
 
@@ -782,6 +800,8 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
             nodeLdrMapCp = singleNode ? nodeLdrMap : new HashMap<>(nodeLdrMap);
         }
 
+        boolean notFound = false;
+
         for (UUID nodeId : nodeListCp) {
             if (nodeId.equals(ctx.discovery().localNode().id()))
                 // Skip local node as it is already used as parent class 
loader.
@@ -807,16 +827,10 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
                         res.byteSource().size());
                 }
                 else {
-                    synchronized (mux) {
-                        // Cache unsuccessfully loaded resource.
-                        if (missedRsrcs != null)
-                            missedRsrcs.add(name);
-                    }
-
                     // Some frameworks like Spring often ask for the resources
                     // just in case - none will happen if there are no such
                     // resources. So we print out INFO level message.
-                    String msg = "Failed to get resource from node [" +
+                    String msg = "Failed to get resource from node (will try 
other nodes, if any) [" +
                         "nodeId=" + node.id() +
                         ", clsLdrId=" + ldrId +
                         ", resName=" + name +
@@ -825,8 +839,9 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
 
                     LT.info(log, msg);
 
-                    // Do not ask other nodes in case of shared mode all of 
them should have the resource.
-                    return null;
+                    // Participants of a shared deployment are not guaranteed 
to have the same class path,
+                    // so keep asking the other nodes.
+                    notFound = true;
                 }
             }
             catch (IgniteCheckedException | TimeoutException e) {
@@ -857,6 +872,14 @@ class GridDeploymentClassLoader extends ClassLoader 
implements GridDeploymentInf
             }
         }
 
+        // Cache the miss only after none of the nodes was able to provide the 
resource.
+        if (notFound) {
+            synchronized (mux) {
+                if (missedRsrcs != null)
+                    missedRsrcs.add(name);
+            }
+        }
+
         return null;
     }
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
index 20ac3f01bae..0638a7c7dcc 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
@@ -329,26 +329,6 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
                 if (isDeadClassLoader(meta))
                     return null;
 
-                boolean skipSearchDeployment = false;
-
-                // Check already exist deployment.
-                if (meta.deploymentMode() == SHARED) {
-                    Collection<GridDeployment> created = getDeployments();
-
-                    for (GridDeployment dep0 : created) {
-                        // hot redeploy from same node
-                        if 
(dep0.participants().containsKey(meta.senderNodeId()) || dep0.undeployed())
-                            continue;
-
-                        IgniteBiTuple<Class<?>, Throwable> cls = 
dep0.deployedClass(meta.className(), meta.alias());
-
-                        if (cls.getKey() != null && cls.getValue() == null) {
-                            
((SharedDeployment)dep0).addParticipant(meta.senderNodeId(), 
meta.classLoaderId());
-                            skipSearchDeployment = true;
-                        }
-                    }
-                }
-
                 if (!F.isEmpty(meta.participants())) {
                     Map<UUID, IgniteUuid> participants = new LinkedHashMap<>();
 
@@ -396,8 +376,7 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
                     return null;
                 }
 
-                if (!skipSearchDeployment)
-                    dep = (SharedDeployment)searchDeploymentCache(meta);
+                dep = (SharedDeployment)searchDeploymentCache(meta);
 
                 if (dep == null) {
                     List<SharedDeployment> deps = 
cache.get(meta.userVersion());
@@ -407,9 +386,15 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
 
                         checkRedeploy(meta);
 
-                        // Find existing deployments that need to be checked
-                        // whether they should be reused for this request.
-                        if (ctx.config().getDeploymentMode() == CONTINUOUS) {
+                        // Find existing deployments that need to be checked 
whether they should be reused for this
+                        // request. In both SHARED and CONTINUOUS modes a 
deployment whose participants are able to
+                        // provide the requested class is reused, so that the 
same class coming from different nodes
+                        // is represented by a single class on this node.
+                        // Classes of a sandboxed subject are never shared 
with other subjects: the JVM checks the
+                        // package access permissions of the subject that 
resolves a class first and caches the result
+                        // per class loader, so a shared loader would extend 
that subject's permissions to all other
+                        // participants. Hence in SHARED mode under the 
sandbox every sender gets its own deployment.
+                        if (meta.deploymentMode() != SHARED || 
!ctx.security().sandbox().enabled()) {
                             for (SharedDeployment d : deps) {
                                 if (!d.pendingUndeploy() && !d.undeployed()) {
                                     Map<UUID, IgniteUuid> parties = 
d.participants();
@@ -491,7 +476,9 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
                 if (cls != null) {
                     synchronized (mux) {
                         if (!d.undeployed() && !d.pendingUndeploy()) {
-                            if (!addParticipant(d, meta))
+                            // The class was provided by the existing 
participants, while the sender is only known
+                            // to have this very class, so the sender is asked 
for further classes after them.
+                            if (!addParticipant(d, meta, false))
                                 return null;
 
                             if (log.isDebugEnabled())
@@ -511,6 +498,11 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
             // We are here either because all participant nodes failed
             // or the class indeed should have a separate deployment.
             for (SharedDeployment d : depsToCheck) {
+                // In SHARED mode a class unknown to the existing deployments 
gets a separate deployment, so that
+                // a deployment is never extended with classes its 
participants do not have.
+                if (meta.deploymentMode() != CONTINUOUS)
+                    break;
+
                 // We check if any random class from existing deployment can be
                 // loaded from sender node. If it can, then we reuse existing
                 // deployment.
@@ -521,7 +513,7 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
 
                         // Add new node prior to loading the class, so we 
attempt
                         // to load the class from the latest node.
-                        if (!addParticipant(d, meta)) {
+                        if (!addParticipant(d, meta, true)) {
                             if (log.isDebugEnabled())
                                 log.debug("Failed to add participant to 
deployment " +
                                     "[meta=" + meta + ", dep=" + dep + ']');
@@ -823,9 +815,11 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
      *
      * @param dep Shared deployment.
      * @param meta Request metadata.
+     * @param first {@code True} to ask the added nodes for classes first, 
{@code false} to ask them after
+     *      the existing participants.
      * @return {@code True} if participant was added.
      */
-    private boolean addParticipant(SharedDeployment dep, 
GridDeploymentMetadata meta) {
+    private boolean addParticipant(SharedDeployment dep, 
GridDeploymentMetadata meta, boolean first) {
         assert dep != null;
         assert meta != null;
 
@@ -837,7 +831,7 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
         if (meta.participants() != null) {
             for (Map.Entry<UUID, IgniteUuid> e : 
meta.participants().entrySet()) {
                 if (ctx.discovery().node(e.getKey()) != null) {
-                    dep.addParticipant(e.getKey(), e.getValue());
+                    dep.addParticipant(e.getKey(), e.getValue(), first);
 
                     if (log.isDebugEnabled())
                         log.debug("Added new participant [nodeId=" + 
e.getKey() + ", clsLdrId=" + e.getValue() +
@@ -850,7 +844,7 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
         }
 
         if (dep.deployMode() == CONTINUOUS || meta.participants() == null) {
-            if (!dep.addParticipant(meta.senderNodeId(), 
meta.classLoaderId())) {
+            if (!dep.addParticipant(meta.senderNodeId(), meta.classLoaderId(), 
first)) {
                 U.warn(log, "Failed to create shared mode deployment " +
                     "(requested class loader was already undeployed, did 
sender node leave grid?) " +
                     "[clsLdrId=" + meta.classLoaderId() + ", senderNodeId=" + 
meta.senderNodeId() + ']');
@@ -1141,13 +1135,24 @@ public class GridDeploymentPerVersionStore extends 
GridDeploymentStoreAdapter {
          * @return Whether actually added or not.
          */
         boolean addParticipant(UUID nodeId, IgniteUuid ldrId) {
+            return addParticipant(nodeId, ldrId, true);
+        }
+
+        /**
+         * @param nodeId Node ID to add.
+         * @param ldrId Class loader ID to add.
+         * @param first {@code True} to ask the node for classes first, {@code 
false} to ask it after
+         *      the existing participants.
+         * @return {@code True} if participant was added.
+         */
+        boolean addParticipant(UUID nodeId, IgniteUuid ldrId, boolean first) {
             assert nodeId != null;
             assert ldrId != null;
 
             assert Thread.holdsLock(mux);
 
             if (!deadClsLdrs.contains(ldrId)) {
-                classLoader().register(nodeId, ldrId);
+                classLoader().register(nodeId, ldrId, first);
 
                 return true;
             }
diff --git 
a/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClientDeploymentSourceTest.java
 
b/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClientDeploymentSourceTest.java
new file mode 100644
index 00000000000..87943417d5f
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClientDeploymentSourceTest.java
@@ -0,0 +1,292 @@
+/*
+ * 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.p2p;
+
+import java.net.URL;
+import java.util.UUID;
+import org.apache.ignite.configuration.DeploymentMode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import 
org.apache.ignite.internal.managers.deployment.GridDeploymentPerVersionStore;
+import org.apache.ignite.testframework.GridTestExternalClassLoader;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.config.GridTestProperties;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.junit.Test;
+
+import static org.apache.ignite.configuration.DeploymentMode.CONTINUOUS;
+import static org.apache.ignite.configuration.DeploymentMode.ISOLATED;
+import static org.apache.ignite.configuration.DeploymentMode.PRIVATE;
+import static org.apache.ignite.configuration.DeploymentMode.SHARED;
+
+/**
+ * Tests that a server peer-loads classes only from the client nodes that 
really have them, when thick clients with
+ * partially overlapping class paths submit tasks in SHARED (and other) 
deployment modes.
+ */
+@GridCommonTest(group = "P2P")
+public class GridP2PClientDeploymentSourceTest extends GridCommonAbstractTest {
+    /** Task available only on the first client. */
+    private static final String TASK1_CLS_NAME = 
"org.apache.ignite.tests.p2p.P2PTestTaskExternalPath1";
+
+    /** Job of {@link #TASK1_CLS_NAME}, available only on the first client. */
+    private static final String JOB1_CLS_NAME = TASK1_CLS_NAME + "$TestJob1";
+
+    /** Task available on both clients. */
+    private static final String TASK2_CLS_NAME = 
"org.apache.ignite.tests.p2p.P2PTestTaskExternalPath2";
+
+    /** Message logged by {@code GridDeploymentClassLoader} when a node 
reports a class as missing. */
+    private static final String CLS_NOT_FOUND_MSG = "Failed to find class on 
remote node";
+
+    /** Log category the peer class loaders of a node log under. The miss on a 
participant is reported at DEBUG level. */
+    private static final String DEP_LOG_NAME = 
GridDeploymentPerVersionStore.class.getName();
+
+    /** Server node. */
+    private static final int SRV = 0;
+
+    /** Client with full class path. */
+    private static final int FULL_CLI = 1;
+
+    /** Client without {@link #TASK1_CLS_NAME} and {@link #JOB1_CLS_NAME}. */
+    private static final int PARTIAL_CLI = 2;
+
+    /** Class loader having all test classes. */
+    private ClassLoader fullLdr;
+
+    /** Class loader lacking task 1 and its job. */
+    private ClassLoader partialLdr;
+
+    /** Current deployment mode. */
+    private DeploymentMode depMode;
+
+    /** Server log. */
+    private ListeningTestLogger srvLog;
+
+    /** Level of {@link #DEP_LOG_NAME} before the test. */
+    private Level initDepLogLevel;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setDeploymentMode(depMode);
+        cfg.setPeerClassLoadingEnabled(true);
+        cfg.setCacheConfiguration();
+
+        if (getTestIgniteInstanceName(SRV).equals(igniteInstanceName))
+            cfg.setGridLogger(srvLog);
+        else if 
(getTestIgniteInstanceName(FULL_CLI).equals(igniteInstanceName))
+            cfg.setClassLoader(fullLdr);
+        else if 
(getTestIgniteInstanceName(PARTIAL_CLI).equals(igniteInstanceName))
+            cfg.setClassLoader(partialLdr);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        URL[] urls = {new URL(GridTestProperties.getProperty("p2p.uri.cls"))};
+
+        fullLdr = new GridTestExternalClassLoader(urls);
+        partialLdr = new GridTestExternalClassLoader(urls, TASK1_CLS_NAME, 
JOB1_CLS_NAME);
+
+        srvLog = new ListeningTestLogger(log);
+
+        initDepLogLevel = 
LoggerContext.getContext(false).getConfiguration().getLoggerConfig(DEP_LOG_NAME).getLevel();
+        Configurator.setLevel(DEP_LOG_NAME, Level.DEBUG);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        Configurator.setLevel(DEP_LOG_NAME, initDepLogLevel);
+
+        super.afterTest();
+    }
+
+    /**
+     * Scenario (SHARED mode):
+     * <ol>
+     *     <li>Client 1 (has task 1, job 1 and task 2) executes task 2 on the 
server.</li>
+     *     <li>Client 2 (has task 2 only) executes task 2 on the server and 
joins the shared deployment created by
+     *     the first client, since the deployment is already able to load task 
2.</li>
+     *     <li>Client 1 executes task 1. The server must load job 1 from 
client 1, not fail because client 2
+     *     (a participant of the same shared deployment) does not have it.</li>
+     * </ol>
+     */
+    @Test
+    public void testNeighbourClientWithoutJobClass() throws Exception {
+        depMode = SHARED;
+
+        LogListener clsNotFoundLsnr = 
LogListener.matches(CLS_NOT_FOUND_MSG).build();
+
+        srvLog.registerListener(clsNotFoundLsnr);
+
+        IgniteEx srv = startGrid(SRV);
+        IgniteEx fullCli = startClientGrid(FULL_CLI);
+        IgniteEx partialCli = startClientGrid(PARTIAL_CLI);
+
+        UUID srvId = srv.localNode().id();
+
+        Class task2Full = fullLdr.loadClass(TASK2_CLS_NAME);
+        Class task2Partial = partialLdr.loadClass(TASK2_CLS_NAME);
+        Class task1Full = fullLdr.loadClass(TASK1_CLS_NAME);
+
+        Integer ldr2Full = (Integer)fullCli.compute().execute(task2Full, 
srvId);
+        Integer ldr2Partial = 
(Integer)partialCli.compute().execute(task2Partial, srvId);
+
+        // Both clients share the same deployment (and thus class loader) on 
the server in SHARED mode.
+        assertEquals(ldr2Full, ldr2Partial);
+
+        // Job class must be loaded from the client that has it, no matter 
which participants joined the deployment.
+        Integer ldr1Full = (Integer)fullCli.compute().execute(task1Full, 
srvId);
+
+        assertEquals(ldr2Full, ldr1Full);
+
+        assertFalse("Class was requested from a node that does not have it", 
clsNotFoundLsnr.check());
+    }
+
+    /**
+     * Same as {@link #testNeighbourClientWithoutJobClass()} but the clients 
deploy in the opposite order, so the client
+     * lacking the job class is the first participant of the shared deployment 
and is asked first:
+     * <ol>
+     *     <li>Client 2 (has task 2 only) executes task 2 on the server and 
creates the shared deployment.</li>
+     *     <li>Client 1 (has task 1, job 1 and task 2) executes task 2 and 
joins that deployment after client 2.</li>
+     *     <li>Client 1 executes task 1. The server asks client 2 for job 1 
first, gets "not found" and must go on
+     *     to client 1 instead of giving up on the first miss.</li>
+     * </ol>
+     */
+    @Test
+    public void testNeighbourClientWithoutJobClassAskedFirst() throws 
Exception {
+        depMode = SHARED;
+
+        IgniteEx srv = startGrid(SRV);
+        IgniteEx fullCli = startClientGrid(FULL_CLI);
+        IgniteEx partialCli = startClientGrid(PARTIAL_CLI);
+
+        UUID srvId = srv.localNode().id();
+        String partialCliId = partialCli.localNode().id().toString();
+
+        // The log abbreviates packages, so match on the simple names. The 
trailing comma keeps the task name from
+        // matching its job.
+        String task1SimpleName = 
TASK1_CLS_NAME.substring(TASK1_CLS_NAME.lastIndexOf('.') + 1);
+        String job1SimpleName = 
JOB1_CLS_NAME.substring(JOB1_CLS_NAME.lastIndexOf('.') + 1);
+
+        // Client 2 has neither task 1 nor job 1. The server reports each miss 
on client 2 exactly once and then
+        // goes on to the next node.
+        LogListener taskMissedOnPartialLsnr = LogListener.matches(s -> 
s.contains(CLS_NOT_FOUND_MSG)
+            && s.contains(task1SimpleName + ',')
+            && s.contains(partialCliId)).times(1).build();
+
+        LogListener jobMissedOnPartialLsnr = LogListener.matches(s -> 
s.contains(CLS_NOT_FOUND_MSG)
+            && s.contains(job1SimpleName + ',')
+            && s.contains(partialCliId)).times(1).build();
+
+        // No other class is ever reported missing: task 2 is served by client 
2, task 1 and job 1 by client 1.
+        LogListener otherMissLsnr = LogListener.matches(s -> 
s.contains(CLS_NOT_FOUND_MSG)
+            && !s.contains(task1SimpleName)).build();
+
+        srvLog.registerListener(taskMissedOnPartialLsnr);
+        srvLog.registerListener(jobMissedOnPartialLsnr);
+        srvLog.registerListener(otherMissLsnr);
+
+        Class task2Partial = partialLdr.loadClass(TASK2_CLS_NAME);
+        Class task2Full = fullLdr.loadClass(TASK2_CLS_NAME);
+        Class task1Full = fullLdr.loadClass(TASK1_CLS_NAME);
+
+        Integer ldr2Partial = 
(Integer)partialCli.compute().execute(task2Partial, srvId);
+        Integer ldr2Full = (Integer)fullCli.compute().execute(task2Full, 
srvId);
+
+        // Client 1 joined the deployment created by client 2.
+        assertEquals(ldr2Partial, ldr2Full);
+
+        // Job 1 exists on client 1 only. The server asks client 2 first and 
must fall through to client 1.
+        Integer ldr1Full = (Integer)fullCli.compute().execute(task1Full, 
srvId);
+
+        assertEquals(ldr2Partial, ldr1Full);
+
+        assertTrue("Task class was not requested from the first participant 
before the owner",
+            taskMissedOnPartialLsnr.check());
+
+        assertTrue("Job class was not requested from the first participant 
before the owner",
+            jobMissedOnPartialLsnr.check());
+
+        assertFalse("A class other than the job class was requested from a 
node that does not have it",
+            otherMissLsnr.check());
+    }
+
+    /** */
+    @Test
+    public void testSharedMode() throws Exception {
+        checkOwnerLeft(SHARED);
+    }
+
+    /** */
+    @Test
+    public void testContinuousMode() throws Exception {
+        checkOwnerLeft(CONTINUOUS);
+    }
+
+    /** */
+    @Test
+    public void testPrivateMode() throws Exception {
+        checkOwnerLeft(PRIVATE);
+    }
+
+    /** */
+    @Test
+    public void testIsolatedMode() throws Exception {
+        checkOwnerLeft(ISOLATED);
+    }
+
+    /**
+     * Checks that after the client which originally deployed a task leaves, 
the task is still executable by another
+     * client having the same class: the class requests are targeted at the 
remaining client.
+     *
+     * @param mode Deployment mode.
+     */
+    private void checkOwnerLeft(DeploymentMode mode) throws Exception {
+        depMode = mode;
+
+        IgniteEx srv = startGrid(SRV);
+        IgniteEx fullCli = startClientGrid(FULL_CLI);
+        IgniteEx partialCli = startClientGrid(PARTIAL_CLI);
+
+        UUID srvId = srv.localNode().id();
+
+        Class task2Full = fullLdr.loadClass(TASK2_CLS_NAME);
+        Class task2Partial = partialLdr.loadClass(TASK2_CLS_NAME);
+
+        fullCli.compute().execute(task2Full, srvId);
+        partialCli.compute().execute(task2Partial, srvId);
+
+        stopGrid(FULL_CLI);
+
+        awaitPartitionMapExchange();
+
+        // Class loader of the remaining client must be used now.
+        partialCli.compute().execute(task2Partial, srvId);
+    }
+}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/p2p/SharedDeploymentTest.java 
b/modules/core/src/test/java/org/apache/ignite/p2p/SharedDeploymentTest.java
index 51966fa93a9..4e06e1ec60c 100644
--- a/modules/core/src/test/java/org/apache/ignite/p2p/SharedDeploymentTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/p2p/SharedDeploymentTest.java
@@ -53,6 +53,25 @@ public class SharedDeploymentTest extends 
GridCommonAbstractTest {
     }
 
     /**
+     * Start a cluster of 3 server nodes.
+     * Run callables deployed on nodes 2 and 3 from the first classpath. Check 
return values.
+     * Stop nodes 2 and 3 (all master nodes of the deployment), restart node 3 
and run a callable deployed on it
+     * from the second classpath (another version of the same class). Check 
the return value of the new version.
+     * <br><br>
+     * According to SHARED mode contract: <br>
+     * 1. Classes from different master nodes with the same user version share
+     * the same class loader on worker nodes <br>
+     *
+     * 2. Classes are un-deployed when all master nodes leave the cluster or 
the
+     * user version changes <br><br>
+     *
+     * The documented contract is: "classes from different master nodes with 
the
+     * same user version share the same class
+     * loader on worker nodes. Classes are un-deployed when all master nodes
+     * leave the cluster or the user version changes."
+     * Also from the user-version section: redeploying changed code on a subset
+     * of nodes requires changing the user version.
+     *
      * @throws Exception if failed.
      */
     @Test
@@ -66,12 +85,15 @@ public class SharedDeploymentTest extends 
GridCommonAbstractTest {
             Collection<Object> res = runJob0(new 
GridTestExternalClassLoader(new URL[] {
                 new URL(GridTestProperties.getProperty("p2p.uri.cls"))}, 
RUN_CLS1/*, RUN_CLS2*/), ignite2, 10_000, 1);
 
+            // Node 3 and node 2 are different nodes with the same user
+            // version, they share the loader, node 3 gets v1 = 42.
             for (Object o: res)
                 assertEquals(o, 42);
 
             res = runJob1(new GridTestExternalClassLoader(new URL[] {
                 new URL(GridTestProperties.getProperty("p2p.uri.cls"))}, 
RUN_CLS, RUN_CLS2), ignite3, 10_000, 2);
 
+            // Nothing is undeployed: user version unchanged.
             for (Object o: res)
                 assertEquals(o, 42);
 
@@ -81,6 +103,11 @@ public class SharedDeploymentTest extends 
GridCommonAbstractTest {
             for (Object o: res)
                 assertEquals(o, 42);
 
+            // In SHARED mode classes are undeployed only when all master 
nodes leave: node 2 participates in the
+            // deployment serving the first version of the classes, so it has 
to leave before node 3 is restarted
+            // with the second version. Otherwise node 3 would legitimately 
share the already deployed classes.
+            stopGrid(2);
+
             ignite3.close();
 
             ignite3 = startGrid(3);
@@ -88,6 +115,7 @@ public class SharedDeploymentTest extends 
GridCommonAbstractTest {
             res = runJob2(new GridTestExternalClassLoader(new URL[] {
                 new 
URL(GridTestProperties.getProperty("p2p.uri.cls.second"))}, RUN_CLS, RUN_CLS1), 
ignite3, 10_000, 4);
 
+            // User-version bump: redeploying changed code on a subset of 
nodes.
             for (Object o: res)
                 assertEquals(o, 43);
         }
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 c167e16de97..248ee08309a 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
@@ -25,6 +25,7 @@ import 
org.apache.ignite.internal.managers.deployment.P2PCacheOperationIntoCompu
 import 
org.apache.ignite.internal.managers.deployment.P2PClassLoadingIssuesTest;
 import org.apache.ignite.p2p.DeploymentClassLoaderCallableTest;
 import org.apache.ignite.p2p.GridP2PClassLoadingSelfTest;
+import org.apache.ignite.p2p.GridP2PClientDeploymentSourceTest;
 import org.apache.ignite.p2p.GridP2PComputeExceptionTest;
 import org.apache.ignite.p2p.GridP2PComputeWithNestedEntryProcessorTest;
 import org.apache.ignite.p2p.GridP2PContinuousDeploymentClientDisconnectTest;
@@ -87,6 +88,7 @@ import org.junit.runners.Suite;
     P2PClassLoadingIssuesTest.class,
     GridP2PComputeExceptionTest.class,
     GridDeploymentLocalStoreReuseTest.class,
+    GridP2PClientDeploymentSourceTest.class,
 })
 public class IgniteP2PSelfTestSuite {
 }

Reply via email to