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

[GitHub] [ignite-3] Pochatkin commented on a diff in pull request #2219: IGNITE-19708 Check refcounter of unit before undeploy

Pochatkin commented on code in PR #2219:
URL: https://github.com/apache/ignite-3/pull/2219#discussion_r1243585152


##########
modules/code-deployment/src/test/java/org/apache/ignite/internal/deployunit/DeploymentUnitUndeployerTest.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.function.Predicate.isEqual;
+import static org.awaitility.Awaitility.await;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.junit.jupiter.api.AfterEach;
+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 DeploymentUnitUndeployerTest {
+    private static final int DELAY_IN_MILLIS = 500;
+
+    private final Set<DeploymentUnit> removingUnits = new CopyOnWriteArraySet<>();
+
+    @Mock
+    private DeploymentUnitAccessor deploymentUnitAccessor;
+
+

Review Comment:
   Remove empty line



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitProcessor.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.Queue;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+
+/**
+ * Executes action on the deployment unit if it is not acquired. Otherwise, puts it to the queue.
+ */
+class DeploymentUnitProcessor {
+    private static final IgniteLogger LOG = Loggers.forClass(DeploymentUnitProcessor.class);
+
+    /** Deployment units to undeploy. */
+    private final Queue<DeploymentUnit> unitsToProcess = new ConcurrentLinkedDeque<>();
+
+    /** Deployment unit accessor. */
+    private final DeploymentUnitAccessor deploymentUnitAccessor;
+
+    /** Executor. */
+    private final ScheduledExecutorService executor;
+
+    /** Action. */
+    private final Consumer<DeploymentUnit> action;
+
+    /**
+     * Creates processor.
+     *
+     * @param nodeName node name.
+     * @param deploymentUnitAccessor deployment unit accessor.
+     * @param action action.
+     */
+    DeploymentUnitProcessor(

Review Comment:
   Processor is so abstract. Lets rename it to DeploymentUnitAcquiredWaiter/Checker ?



##########
modules/code-deployment/src/test/java/org/apache/ignite/internal/deployunit/DeploymentUnitProcessorTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.function.Predicate.isEqual;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.emptyIterable;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.after;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.verify;
+
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class DeploymentUnitProcessorTest {
+    private static final int DELAY_IN_MILLIS = 500;
+
+    private final Set<DeploymentUnit> removingUnits = new CopyOnWriteArraySet<>();
+
+    @Mock
+    private FileDeployerService deployerService;
+
+    @Spy
+    @InjectMocks
+    private DeploymentUnitAccessorImpl deploymentUnitAccessor;
+
+

Review Comment:
   Remove empty line



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentUnitProcessor.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.Queue;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+
+/**
+ * Executes action on the deployment unit if it is not acquired. Otherwise, puts it to the queue.
+ */
+class DeploymentUnitProcessor {
+    private static final IgniteLogger LOG = Loggers.forClass(DeploymentUnitProcessor.class);
+
+    /** Deployment units to undeploy. */
+    private final Queue<DeploymentUnit> unitsToProcess = new ConcurrentLinkedDeque<>();
+
+    /** Deployment unit accessor. */
+    private final DeploymentUnitAccessor deploymentUnitAccessor;
+
+    /** Executor. */
+    private final ScheduledExecutorService executor;
+
+    /** Action. */
+    private final Consumer<DeploymentUnit> action;
+
+    /**
+     * Creates processor.
+     *
+     * @param nodeName node name.
+     * @param deploymentUnitAccessor deployment unit accessor.
+     * @param action action.
+     */
+    DeploymentUnitProcessor(
+            String nodeName,
+            DeploymentUnitAccessor deploymentUnitAccessor,
+            Consumer<DeploymentUnit> action) {
+        this.deploymentUnitAccessor = deploymentUnitAccessor;
+        this.executor = Executors.newScheduledThreadPool(
+                1, NamedThreadFactory.create(nodeName, "deployment-unit-undeployer", LOG));
+        this.action = action;
+    }
+
+    /**
+     * Starts the processor.
+     *
+     * @param delay delay between undeploy attempts.
+     * @param unit time unit of the delay.
+     */
+    public void start(long delay, TimeUnit unit) {
+        executor.scheduleWithFixedDelay(this::processUnits, 0, delay, unit);
+    }
+
+    /**
+     * Stops the processor.
+     */
+    public void stop() {
+        executor.shutdown();
+    }
+
+    /**
+     * Processes all deployment units in the queue.
+     */
+    private void processUnits() {
+        int size = unitsToProcess.size();
+        for (int i = 0; i < size; i++) {
+            process(unitsToProcess.remove());
+        }
+    }
+
+    /**
+     * Executes action on the deployment unit if it is not acquired. Otherwise, puts it to the queue.
+     *
+     * @param unit deployment unit to undeploy.
+     */
+    public void process(DeploymentUnit unit) {

Review Comment:
   Name process also so abstract



-- 
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