You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/11/17 10:52:25 UTC

[GitHub] [flink] xintongsong commented on a diff in pull request #21233: [FLINK-29870] [ResourceManager]Split ResourceNotEnoughNotifier from ResourceActions

xintongsong commented on code in PR #21233:
URL: https://github.com/apache/flink/pull/21233#discussion_r1024913334


##########
flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/ResourceNotEnoughNotifier.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.flink.runtime.resourcemanager.slotmanager;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.runtime.slots.ResourceRequirement;
+
+import java.util.Collection;
+
+/**
+ * Notifies that not enough resources are available to fulfill the resource requirements of a job.
+ */
+@FunctionalInterface
+public interface ResourceNotEnoughNotifier {

Review Comment:
   I'd suggest to name this `ResourceEventListener`. And maybe also change the method name to `notEnoughResourceAvailable`.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/ResourceActions.java:
##########
@@ -44,23 +39,4 @@ public interface ResourceActions {
      * @return whether the resource can be allocated
      */
     boolean allocateResource(WorkerResourceSpec workerResourceSpec);
-
-    /**
-     * Notifies that an allocation failure has occurred.
-     *
-     * @param jobId to which the allocation belonged
-     * @param allocationId identifying the failed allocation
-     * @param cause of the allocation failure
-     */
-    void notifyAllocationFailure(JobID jobId, AllocationID allocationId, Exception cause);

Review Comment:
   It would be nice to remove the unused `notifyAllocationFailure`, and also `JobMasterGateway#notifyAllocationFailure`, in a separate commit.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java:
##########
@@ -86,7 +88,7 @@ public interface SlotManager extends AutoCloseable {
     void start(
             ResourceManagerId newResourceManagerId,
             Executor newMainThreadExecutor,
-            ResourceActions newResourceActions,
+            @Nullable ResourceActions newResourceActions,

Review Comment:
   I would not make this argument `@Nullable`.
   
   I'm aware that many fields, including `resourceActions`, are `@Nullable` in the slot manager implementations. However, that is because these fields can only be decided when the slot manager is started, not when constructed. The null values can be ambiguous. E.g., in this case, `resourceActions` being `null` can mean either the slot manager is not yet started, or the resource allocation is not supported.
   
   As an alternative, I'd suggest to introduce another implementation of `ResourceActions`, something like a `NonSupportedResourceActions`. And we can add a new method `ResourceActions#isSupported`, and use it for deciding whether the resource can be allocated. For the `NonSupportedResourceActions`, `allocateResource` and `releaseResource` should throw `UnsupportedOperationException`, meaning that the slot manager is responsible for calling these two methods only on when `ResourceActions#isSupported` returns `true`.
   



##########
flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/active/ActiveResourceManager.java:
##########
@@ -499,6 +506,21 @@ public void execute(Runnable command) {
         }
     }
 
+    private class ResourceActionsImpl implements ResourceActions {
+        @Override
+        public void releaseResource(InstanceID instanceId, Exception cause) {
+            validateRunsInMainThread();
+
+            ActiveResourceManager.this.releaseResource(instanceId, cause);
+        }
+
+        @Override
+        public boolean allocateResource(WorkerResourceSpec workerResourceSpec) {
+            validateRunsInMainThread();
+            return startNewWorker(workerResourceSpec);

Review Comment:
   We probably have the same problem for `stopWorker`. There are some logics in `ResourceManager#releaseResource` that are not only for the active resource manager, however, the method `releaseResource` itself is never called except in the active resource manager. 



##########
flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/active/ActiveResourceManager.java:
##########
@@ -499,6 +506,21 @@ public void execute(Runnable command) {
         }
     }
 
+    private class ResourceActionsImpl implements ResourceActions {
+        @Override
+        public void releaseResource(InstanceID instanceId, Exception cause) {
+            validateRunsInMainThread();
+
+            ActiveResourceManager.this.releaseResource(instanceId, cause);
+        }
+
+        @Override
+        public boolean allocateResource(WorkerResourceSpec workerResourceSpec) {
+            validateRunsInMainThread();
+            return startNewWorker(workerResourceSpec);

Review Comment:
   `startNewWorker` is no longer needed for `ResourceManager` and `StandaloneResourceManager`.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/ResourceActions.java:
##########
@@ -18,13 +18,8 @@
 
 package org.apache.flink.runtime.resourcemanager.slotmanager;
 
-import org.apache.flink.api.common.JobID;
-import org.apache.flink.runtime.clusterframework.types.AllocationID;
 import org.apache.flink.runtime.instance.InstanceID;
 import org.apache.flink.runtime.resourcemanager.WorkerResourceSpec;
-import org.apache.flink.runtime.slots.ResourceRequirement;
-
-import java.util.Collection;
 
 /** Resource related actions which the {@link SlotManager} can perform. */
 public interface ResourceActions {

Review Comment:
   I'd suggest to rename this interface to `ResourceAllocator`.



-- 
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: issues-unsubscribe@flink.apache.org

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