tillrohrmann commented on a change in pull request #13722:
URL: https://github.com/apache/flink/pull/13722#discussion_r517444715



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/AutoRequirementDecrementingSlotPoolWrapper.java
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.jobmaster.slotpool;
+
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway;
+import org.apache.flink.runtime.jobmaster.SlotInfo;
+import org.apache.flink.runtime.slots.ResourceRequirement;
+import org.apache.flink.runtime.taskexecutor.slot.SlotOffer;
+import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
+
+import javax.annotation.Nullable;
+
+import java.util.Collection;
+import java.util.Optional;
+
+/**
+ * A wrapper around a {@link DeclarativeSlotPool} that automatically 
decrements requirements if a slot is freed or
+ * released.
+ */
+class AutoRequirementDecrementingSlotPoolWrapper implements 
DeclarativeSlotPool {
+
+       private final DeclarativeSlotPool backingSlotPool;
+
+       AutoRequirementDecrementingSlotPoolWrapper(DeclarativeSlotPool 
backingSlotPool) {
+               this.backingSlotPool = backingSlotPool;
+       }
+
+       @Override
+       public void increaseResourceRequirementsBy(ResourceCounter increment) {
+               backingSlotPool.increaseResourceRequirementsBy(increment);
+       }
+
+       @Override
+       public void decreaseResourceRequirementsBy(ResourceCounter decrement) {
+               backingSlotPool.decreaseResourceRequirementsBy(decrement);
+       }
+
+       @Override
+       public Collection<ResourceRequirement> getResourceRequirements() {
+               return backingSlotPool.getResourceRequirements();
+       }
+
+       @Override
+       public Collection<SlotOffer> offerSlots(Collection<? extends SlotOffer> 
offers, TaskManagerLocation taskManagerLocation, TaskManagerGateway 
taskManagerGateway, long currentTime) {
+               return backingSlotPool.offerSlots(offers, taskManagerLocation, 
taskManagerGateway, currentTime);
+       }
+
+       @Override
+       public Collection<SlotInfoWithUtilization> getFreeSlotsInformation() {
+               return backingSlotPool.getFreeSlotsInformation();
+       }
+
+       @Override
+       public Collection<? extends SlotInfo> getAllSlotsInformation() {
+               return backingSlotPool.getAllSlotsInformation();
+       }
+
+       @Override
+       public PhysicalSlot reserveFreeSlot(AllocationID allocationId, 
ResourceProfile requiredSlotProfile) {
+               return backingSlotPool.reserveFreeSlot(allocationId, 
requiredSlotProfile);
+       }
+
+       @Override
+       public Optional<ResourceCounter> freeReservedSlot(AllocationID 
allocationId, @Nullable Throwable cause, long currentTime) {
+               Optional<ResourceCounter> previouslyFulfilledRequirement = 
backingSlotPool.freeReservedSlot(allocationId, cause, currentTime);
+               previouslyFulfilledRequirement
+                       
.ifPresent(backingSlotPool::decreaseResourceRequirementsBy);
+               return previouslyFulfilledRequirement;
+       }
+
+       @Override
+       public ResourceCounter releaseSlots(ResourceID owner, Exception cause) {
+               ResourceCounter previouslyFulfilledRequirement = 
backingSlotPool.releaseSlots(owner, cause);
+
+               
backingSlotPool.decreaseResourceRequirementsBy(previouslyFulfilledRequirement);
+               return previouslyFulfilledRequirement;
+       }

Review comment:
       Ah I see. This is definitely a recurring theme that the matching of the 
slots to required resources and the slots to `Executions` need to be aligned.
   
   In the case of the `releaseSlots` method, I guess that the return value will 
tell us which requirements are no longer fulfilled.
   
   Maybe it is not such a bad idea to return in some form the matched resource 
profile of a slot. This would allow the user to adjust the resource 
requirements if it decides to use this slot for a different `Execution`.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to