GJL commented on a change in pull request #8486: [FLINK-12372] [runtime] 
implement ExecutionSlotAllocator
URL: https://github.com/apache/flink/pull/8486#discussion_r291317737
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/DefaultExecutionSlotAllocator.java
 ##########
 @@ -0,0 +1,250 @@
+/*
+ * 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.scheduler;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.SlotProfile;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.executiongraph.ExecutionVertex;
+import org.apache.flink.runtime.instance.SlotSharingGroupId;
+import org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.SlotProvider;
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+import static 
org.apache.flink.runtime.executiongraph.ExecutionVertex.MAX_DISTINCT_LOCATIONS_TO_CONSIDER;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Default {@link ExecutionSlotAllocator} which will use {@link SlotProvider} 
to allocate slots and
+ * keep the unfulfilled requests for further cancellation.
+ */
+public class DefaultExecutionSlotAllocator implements ExecutionSlotAllocator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(DefaultExecutionSlotAllocator.class);
+
+       /**
+        * Store the uncompleted slot assignments.
+        */
+       private final Map<ExecutionVertexID, SlotExecutionVertexAssignment> 
pendingSlotAssignments;
+
+       private final SlotProvider slotProvider;
+
+       private final InputsLocationsRetriever inputsLocationsRetriever;
+
+       private final Time allocationTimeout;
+
+       public DefaultExecutionSlotAllocator(
+                       SlotProvider slotProvider,
+                       InputsLocationsRetriever inputsLocationsRetriever,
+                       Time allocationTimeout) {
+               this.slotProvider = checkNotNull(slotProvider);
+               this.inputsLocationsRetriever = 
checkNotNull(inputsLocationsRetriever);
+               this.allocationTimeout = checkNotNull(allocationTimeout);
+
+               pendingSlotAssignments = new HashMap<>();
+       }
+
+       @Override
+       public Collection<SlotExecutionVertexAssignment> allocateSlotsFor(
+                       Collection<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements) {
+
+               List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                               new 
ArrayList<>(executionVertexSchedulingRequirements.size());
+
+               Set<AllocationID> allPreviousAllocationIds = 
computeAllPriorAllocationIds(executionVertexSchedulingRequirements);
+
+               for (ExecutionVertexSchedulingRequirements 
schedulingRequirements : executionVertexSchedulingRequirements) {
+                       final ExecutionVertexID executionVertexId = 
schedulingRequirements.getExecutionVertexId();
+                       final SlotRequestId slotRequestId = new SlotRequestId();
+                       final SlotSharingGroupId slotSharingGroupId = 
schedulingRequirements.getSlotSharingGroupId();
+
+                       LOG.debug("Allocate slot with id {} for execution {}", 
slotRequestId, executionVertexId);
+
+                       CompletableFuture<LogicalSlot> slotFuture = 
calculatePreferredLocations(
+                                       executionVertexId,
+                                       
schedulingRequirements.getPreferredLocations(),
+                                       inputsLocationsRetriever).thenCompose(
+                                                       
(Collection<TaskManagerLocation> preferredLocations) ->
+                                                                       
slotProvider.allocateSlot(
+                                                                               
        slotRequestId,
+                                                                               
        new ScheduledUnit(
 
 Review comment:
   What would be the best way to test that we are creating the `ScheduledUnit` 
correctly? We can introduce a mapper (`ExecutionVertexSchedulingRequirements` 
-> `ScheduledUnit`) that we test separately, or intercept the objects in 
`TestingSlotProvider`. Same problem holds for `SlotProfile`.

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


With regards,
Apache Git Services

Reply via email to