GJL commented on a change in pull request #8486: [FLINK-12372] [runtime] implement ExecutionSlotAllocator URL: https://github.com/apache/flink/pull/8486#discussion_r290166547
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/DefaultExecutionSlotAllocator.java ########## @@ -0,0 +1,294 @@ +/* + * 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.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.Scheduler; +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 { + + 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; + + private final Boolean isQueuedSchedulingAllowed; + + public DefaultExecutionSlotAllocator( + SlotProvider slotProvider, + InputsLocationsRetriever inputsLocationsRetriever, + Time allocationTimeout, + boolean isQueuedSchedulingAllowed) { + this.slotProvider = checkNotNull(slotProvider); + this.inputsLocationsRetriever = checkNotNull(inputsLocationsRetriever); + this.allocationTimeout = checkNotNull(allocationTimeout); + this.isQueuedSchedulingAllowed = isQueuedSchedulingAllowed; + + pendingSlotAssignments = new HashMap<>(); + } + + @Override + public Collection<SlotExecutionVertexAssignment> allocateSlotsFor( + Collection<ExecutionVertexSchedulingRequirements> executionVertexSchedulingRequirements) { + + List<SlotExecutionVertexAssignment> slotExecutionVertexAssignments = + new ArrayList<>(executionVertexSchedulingRequirements.size()); + + Set<AllocationID> allPreviousAllocationIds = + computeAllPriorAllocationIdsIfRequiredByScheduling(executionVertexSchedulingRequirements); + + for (ExecutionVertexSchedulingRequirements schedulingRequirements : executionVertexSchedulingRequirements) { + final ExecutionVertexID executionVertexId = schedulingRequirements.getExecutionVertexId(); + final SlotRequestId slotRequestId = new SlotRequestId(); + final SlotSharingGroupId slotSharingGroupId = schedulingRequirements.getSlotSharingGroupId(); + + if (LOG.isDebugEnabled()) { + LOG.debug("Allocate slot with id {} for execution {}", slotRequestId, executionVertexId); + } + + // TODO: the calculation of preferred location should be refined. Review comment: I would remove _TODO_ because it might not be changed for a long time. If there is demand for this there should be an issue in jira and it will be fixed soon. ---------------------------------------------------------------- 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
