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



##########
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:
       hmm...it's not difficult to move the requirement adjustments into the 
wrapper, but the lack of updates to the slotpool-internal mappings could be 
problematic.
   
   so let's see; we require one large and one small slot, get one each and do a 
perfect match.
   
   ```
   requirements: S:1 L:1
   fulfilledRequirements: S:1 L:1
   slotToRequirementProfileMappings: S->S L->L
   ```
   
   Now the scheduler makes things difficult, and uses L for S. We just adjust 
the requirements from the outside, and get:
   
   ```
   requirements: S:2 L:0
   fulfilledRequirements: S:1 L:1
   mapping: S->S L->L
   ```
   
   soo...we would now correctly determine that we need one more small slot, 
because we subtract the fulfilledRequirements from requirements, so that's fine.
   But, if we release the large slot, then the wrapper needs to know what 
profile the slot was used for, to properly reduce the requirements. Currently 
this is based on what the slot pool returns, which would still based on the 
original mapping and as such would be incorrect.
   I suppose if the scheduler were to use it then it would know for what 
requirement it was used for, so maybe the additional mapping would exist in the 
wrapper temporarily?...




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