You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "Flaugh24 (via GitHub)" <gi...@apache.org> on 2023/06/05 19:07:19 UTC

[GitHub] [ignite-3] Flaugh24 opened a new pull request, #2146: IGNITE-19517 Cache JobClassLoaders

Flaugh24 opened a new pull request, #2146:
URL: https://github.com/apache/ignite-3/pull/2146

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #2146: IGNITE-19517 Cache JobClassLoaders

Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #2146:
URL: https://github.com/apache/ignite-3/pull/2146#discussion_r1227119099


##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentManagerImpl.java:
##########
@@ -296,6 +319,41 @@ public CompletableFuture<Boolean> onDemandDeploy(String id, Version version) {
                     }
                     return messaging.downloadUnitContent(id, version, nodes)
                             .thenCompose(unitContent -> deployToLocalNode(id, version, unitContent));
+                })
+                .thenCompose(result -> {
+                    if (result) {
+                        return completedFuture(null);
+                    } else {
+                        LOG.error("Failed to deploy on demand deployment unit {}:{}", id, version);
+                        return clusterStatusAsync(id, version)
+                                .thenCombine(nodeStatusAsync(id, version), (clusterStatus, nodeStatus) -> {
+                                    if (clusterStatus == null) {
+                                        return CompletableFuture.<Void>failedFuture(
+                                                new DeploymentUnitNotFoundException(id, version));
+                                    } else {
+                                        return CompletableFuture.<Void>failedFuture(
+                                                new DeploymentUnitUnavailableException(
+                                                        id,
+                                                        version,
+                                                        clusterStatus,
+                                                        nodeStatus
+                                                )
+                                        );
+                                    }
+                                }).thenCompose(it -> it);
+                    }
+                });
+    }
+
+    @Override
+    public CompletableFuture<Version> detectLatestDeployedVersion(String id) {

Review Comment:
   the method contains only "Deployed" word but the filter function includes DEPLOYED or UPLOADING status. That is confusing.



##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/ClassLoaderExceptionsMapper.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.compute;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import org.apache.ignite.internal.compute.loader.JobContext;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+
+class ClassLoaderExceptionsMapper {
+    // <class_fqdn>. Deployment unit <deployment_unit_id_and ver> doesn’t exist.
+    private static final String DEPLOYMENT_UNIT_DOES_NOT_EXIST_MSG = "%s. Deployment unit %s:%s doesn’t exist";
+
+
+    // <class_fqdn>. Deployment unit <deployment_unit_id> can’t be used:
+    // [clusterStatus = <clusterDURecord.status>, nodeStatus = <nodeDURecord.status>].
+    private static final String DEPLOYMENT_UNIT_NOT_AVAILABLE_MSG = "%s. Deployment unit %s:%s can’t be used: "
+            + "[clusterStatus = %s, nodeStatus = %s]";
+
+    static CompletableFuture<JobContext> mapClassLoaderExceptions(
+            CompletableFuture<JobContext> future,
+            String jobClassName
+    ) {
+        return future.handle((v, e) -> {
+            if (e instanceof Exception) {
+                throw new CompletionException(mapException(unwrapCompletionException((Exception) e), jobClassName));
+            } else {
+                return v;

Review Comment:
   Are you sure you do not want to log the exception at least? What if it is an important error? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] Pochatkin commented on a diff in pull request #2146: IGNITE-19517 Cache JobClassLoaders

Posted by "Pochatkin (via GitHub)" <gi...@apache.org>.
Pochatkin commented on code in PR #2146:
URL: https://github.com/apache/ignite-3/pull/2146#discussion_r1226496748


##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/FileDeployerService.java:
##########
@@ -145,7 +146,22 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
      * @param version Deployment unit version.
      * @return Path to unit folder.
      */
-    public Path unitPath(String id, Version version) {
+    Path unitPath(String id, Version version, boolean checkExistence) {

Review Comment:
   Javadoc for checkExistance



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentManagerImpl.java:
##########
@@ -101,6 +101,8 @@ public class DeploymentManagerImpl implements IgniteDeployment {
      */
     private final DeployTracker tracker;
 
+    private final DeploymentUnitAccessor deploymentUnitAccessor;

Review Comment:
   Javadoc



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] Pochatkin commented on a diff in pull request #2146: IGNITE-19517 Cache JobClassLoaders

Posted by "Pochatkin (via GitHub)" <gi...@apache.org>.
Pochatkin commented on code in PR #2146:
URL: https://github.com/apache/ignite-3/pull/2146#discussion_r1222885650


##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/exception/DeploymentUnitUnavailableException.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.deployunit.exception;
+
+import org.apache.ignite.compute.version.Version;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+import org.apache.ignite.lang.ErrorGroups.CodeDeployment;
+import org.apache.ignite.lang.IgniteException;
+
+/**
+ * Throws when trying to use unavailable unit for computing. Unit can be unavailable if it has one of the following statuses:
+ * {@link DeploymentStatus#OBSOLETE} or {@link DeploymentStatus#REMOVING} or {@link DeploymentStatus#UPLOADING}.
+ */
+public class DeploymentUnitUnavailableException extends IgniteException {
+

Review Comment:
   Remove empty line



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DisposableDeploymentUnit.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.deployunit;
+
+import java.nio.file.Path;
+import java.util.Objects;
+import org.apache.ignite.compute.DeploymentUnit;
+
+/**
+ * Disposable deployment unit.
+ */
+public class DisposableDeploymentUnit {
+

Review Comment:
   Remove empty line



##########
modules/core/src/main/java/org/apache/ignite/internal/util/RefCountedObjectPool.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.util;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Supplier;
+
+/**
+ * A pool of objects that are reference counted. Objects are created on demand and destroyed when the reference count
+ * reaches zero.
+ *
+ * @param <K> The type of the key used to identify the object.
+ * @param <V> The type of the object.
+ */
+public class RefCountedObjectPool<K, V> {
+

Review Comment:
   Empty line



##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/ClassLoaderExceptionsMapper.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.compute;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import org.apache.ignite.internal.compute.loader.JobContext;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+
+class ClassLoaderExceptionsMapper {
+

Review Comment:
   Remove empty line



##########
modules/code-deployment/src/test/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessorImplTest.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.deployunit;
+
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+
+import java.nio.file.Path;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+import org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher;
+import org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class DeploymentUnitAccessorImplTest {
+

Review Comment:
   Remove empty line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] Pochatkin commented on a diff in pull request #2146: IGNITE-19517 Cache JobClassLoaders

Posted by "Pochatkin (via GitHub)" <gi...@apache.org>.
Pochatkin commented on code in PR #2146:
URL: https://github.com/apache/ignite-3/pull/2146#discussion_r1226244893


##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessor.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.deployunit;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+
+/**
+ * Interface for accessing deployment units.
+ */
+public interface DeploymentUnitAccessor {
+    /**
+     * Detects the latest version of the deployment unit.
+     */
+    CompletableFuture<Version> detectLatestDeployedVersion(String id);
+
+    /**
+     * Acquires the deployment unit. Each call to this method must be matched with a call to {@link DisposableDeploymentUnit#release()}.
+     */
+    DisposableDeploymentUnit acquire(DeploymentUnit unit);
+
+    boolean isAcquired(DeploymentUnit unit);

Review Comment:
   Javadocs



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessorImpl.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.deployunit;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.DEPLOYED;
+import static org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.UPLOADING;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.util.RefCountedObjectPool;
+
+/**
+ * Implementation of {@link DeploymentUnitAccessor}.
+ */
+public class DeploymentUnitAccessorImpl implements DeploymentUnitAccessor {
+

Review Comment:
   Remove empty line



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessor.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.deployunit;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+
+/**
+ * Interface for accessing deployment units.
+ */
+public interface DeploymentUnitAccessor {
+    /**
+     * Detects the latest version of the deployment unit.
+     */
+    CompletableFuture<Version> detectLatestDeployedVersion(String id);
+
+    /**
+     * Acquires the deployment unit. Each call to this method must be matched with a call to {@link DisposableDeploymentUnit#release()}.
+     */
+    DisposableDeploymentUnit acquire(DeploymentUnit unit);
+
+    boolean isAcquired(DeploymentUnit unit);
+
+    CompletableFuture<Void> onDemandDeploy(DeploymentUnit unit);

Review Comment:
   On demand deploy shouldn't be here



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitAccessorImpl.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.deployunit;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.DEPLOYED;
+import static org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.UPLOADING;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.util.RefCountedObjectPool;
+
+/**
+ * Implementation of {@link DeploymentUnitAccessor}.
+ */
+public class DeploymentUnitAccessorImpl implements DeploymentUnitAccessor {
+
+    private static final IgniteLogger LOG = Loggers.forClass(DeploymentUnitAccessorImpl.class);
+    private final RefCountedObjectPool<DeploymentUnit, DisposableDeploymentUnit> pool = new RefCountedObjectPool<>();

Review Comment:
   Add extra line space



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/exception/DeploymentUnitNotFoundException.java:
##########
@@ -17,19 +17,63 @@
 
 package org.apache.ignite.internal.deployunit.exception;
 
+import org.apache.ignite.compute.version.Version;
 import org.apache.ignite.lang.ErrorGroups.CodeDeployment;
 import org.apache.ignite.lang.IgniteException;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Throws when trying to access information about unit which doesn't exist.
  */
 public class DeploymentUnitNotFoundException extends IgniteException {
+
+    /**
+     * Unit id.
+     */
+    private final String id;
+
+    /**
+     * Unit version.
+     */
+    private final Version version;
+
+    /**
+     * Constructor.
+     *
+     * @param id Unit id.
+     */
+    public DeploymentUnitNotFoundException(String id) {
+        super(CodeDeployment.UNIT_NOT_FOUND_ERR, message(id, null));

Review Comment:
   Please use this(id, null)



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DisposableDeploymentUnit.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.deployunit;
+
+import java.nio.file.Path;
+import java.util.Objects;
+import org.apache.ignite.compute.DeploymentUnit;
+
+/**
+ * Disposable deployment unit.
+ */
+public class DisposableDeploymentUnit {
+    private final DeploymentUnit unit;
+
+    private final Path path;
+
+    private final Runnable release;
+
+    /**
+     * Constructor.
+     *
+     * @param unit Deployment unit.
+     * @param path Path to the deployment unit.
+     * @param release Release.
+     */
+    public DisposableDeploymentUnit(DeploymentUnit unit, Path path, Runnable release) {
+        this.unit = unit;
+        this.path = path;
+        this.release = release;
+    }
+
+    /**
+     * Returns deployment unit.
+     *
+     * @return Deployment unit.
+     */
+    public DeploymentUnit unit() {
+        return unit;
+    }
+
+    /**
+     * Returns path to the deployment unit.
+     *
+     * @return Path to the deployment unit.
+     */
+    public Path path() {
+        return path;
+    }
+
+    /**
+     * Releases resources of the unit. This method should be called when the unit is not needed any more.
+     */
+    public void release() {
+        release.run();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        DisposableDeploymentUnit that = (DisposableDeploymentUnit) o;
+        return Objects.equals(unit, that.unit);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(unit);
+    }
+
+    @Override
+    public String toString() {
+        return "DisposableDeploymentUnit{"
+                + "unit=" + unit
+                + ", release=" + release + '}';

Review Comment:
   What the reason to add Runnable to string?



##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/loader/JobContextManager.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.compute.loader;
+
+import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.version.Version;
+import org.apache.ignite.internal.deployunit.DeploymentUnitAccessor;
+import org.apache.ignite.internal.deployunit.DisposableDeploymentUnit;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.util.RefCountedObjectPool;
+
+/**
+ * Manages job context.
+ */
+public class JobContextManager {
+    private static final IgniteLogger LOG = Loggers.forClass(JobContextManager.class);
+
+    private final RefCountedObjectPool<List<DeploymentUnit>, JobClassLoader> classLoaderPool = new RefCountedObjectPool<>();
+
+    /**
+     * The deployer service.
+     */
+    private final DeploymentUnitAccessor deploymentUnitAccessor;
+
+    /**
+     * The class loader factory.
+     */
+    private final JobClassLoaderFactory classLoaderFactory;
+
+    /**
+     * Constructor.
+     *
+     * @param deploymentUnitAccessor The deployer service.
+     * @param classLoaderFactory The class loader factory.
+     */
+    public JobContextManager(DeploymentUnitAccessor deploymentUnitAccessor, JobClassLoaderFactory classLoaderFactory) {
+        this.deploymentUnitAccessor = deploymentUnitAccessor;
+        this.classLoaderFactory = classLoaderFactory;
+    }
+
+    /**
+     * Acquires a class loader for the given deployment units.
+     *
+     * @param units The deployment units.
+     * @return The class loader.
+     */
+    public CompletableFuture<JobContext> acquireClassLoader(List<DeploymentUnit> units) {
+        return normalizeVersions(units)
+                .thenCompose(normalizedUnits -> onDemandDeploy(normalizedUnits).thenApply(v -> normalizedUnits))
+                .thenApply(normalizedUnits -> classLoaderPool.acquire(normalizedUnits, this::createClassLoader))
+                .whenComplete((ctx, err) -> {
+                    if (err != null) {
+                        LOG.error("Failed to acquire class loader for units: " + units, err);
+                    } else {
+                        LOG.debug("Acquired class loader for units: " + units);
+                    }
+                })

Review Comment:
   May you please move these logs to place where it throws and remove this whenComplete handler



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] Flaugh24 commented on a diff in pull request #2146: IGNITE-19517 Cache JobClassLoaders

Posted by "Flaugh24 (via GitHub)" <gi...@apache.org>.
Flaugh24 commented on code in PR #2146:
URL: https://github.com/apache/ignite-3/pull/2146#discussion_r1228238924


##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/ClassLoaderExceptionsMapper.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.compute;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import org.apache.ignite.internal.compute.loader.JobContext;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitNotFoundException;
+import org.apache.ignite.internal.deployunit.exception.DeploymentUnitUnavailableException;
+
+class ClassLoaderExceptionsMapper {
+    // <class_fqdn>. Deployment unit <deployment_unit_id_and ver> doesn’t exist.
+    private static final String DEPLOYMENT_UNIT_DOES_NOT_EXIST_MSG = "%s. Deployment unit %s:%s doesn’t exist";
+
+
+    // <class_fqdn>. Deployment unit <deployment_unit_id> can’t be used:
+    // [clusterStatus = <clusterDURecord.status>, nodeStatus = <nodeDURecord.status>].
+    private static final String DEPLOYMENT_UNIT_NOT_AVAILABLE_MSG = "%s. Deployment unit %s:%s can’t be used: "
+            + "[clusterStatus = %s, nodeStatus = %s]";
+
+    static CompletableFuture<JobContext> mapClassLoaderExceptions(
+            CompletableFuture<JobContext> future,
+            String jobClassName
+    ) {
+        return future.handle((v, e) -> {
+            if (e instanceof Exception) {
+                throw new CompletionException(mapException(unwrapCompletionException((Exception) e), jobClassName));
+            } else {
+                return v;

Review Comment:
   I don't think the mapper should be responsible for that. We have logging at other levels. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] PakhomovAlexander merged pull request #2146: IGNITE-19517 Cache JobClassLoaders

Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander merged PR #2146:
URL: https://github.com/apache/ignite-3/pull/2146


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org