azagrebin commented on a change in pull request #12256:
URL: https://github.com/apache/flink/pull/12256#discussion_r435062282



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/OneSlotPerExecutionSlotAllocator.java
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.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.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotOwner;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest;
+import org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot;
+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.apache.flink.util.FlinkException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This slot allocator will request one physical slot for each single 
execution vertex.
+ * The slots will be requested in bulks so that the {@link SlotProvider} can 
check
+ * whether this bulk of slot requests can be fulfilled at the same time.
+ * It has several limitations:
+ *
+ * <p>1. Slot sharing will be ignored.
+ *
+ * <p>2. Co-location constraints are not allowed.
+ *
+ * <p>3. Intra-bulk input location preferences will be ignored.
+ */
+public class OneSlotPerExecutionSlotAllocator extends 
AbstractExecutionSlotAllocator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(OneSlotPerExecutionSlotAllocator.class);
+
+       private final SlotProvider slotProvider;
+
+       private final SlotOwner slotOwner;
+
+       private final boolean slotWillBeOccupiedIndefinitely;
+
+       private final Time allocationTimeout;
+
+       public OneSlotPerExecutionSlotAllocator(
+                       final SlotProvider slotProvider,

Review comment:
       Could we already make `OneSlotPerExecutionSlotAllocator` depending on 
`BulkSlotProvider` if `SlotProvider` interface extends `BulkSlotProvider` and 
we duplicate `cancelSlotRequest` in `BulkSlotProvider` interface? or make 
`BulkSlotProvider` extend `SlotOwner` later.
   If `cancelSlotRequest` is basically only used to release slots, then maybe 
we could rename it later to `releaseSlot` in `BulkSlotProvider`.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/OneSlotPerExecutionSlotAllocator.java
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.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.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotOwner;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest;
+import org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot;
+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.apache.flink.util.FlinkException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This slot allocator will request one physical slot for each single 
execution vertex.
+ * The slots will be requested in bulks so that the {@link SlotProvider} can 
check
+ * whether this bulk of slot requests can be fulfilled at the same time.
+ * It has several limitations:
+ *
+ * <p>1. Slot sharing will be ignored.
+ *
+ * <p>2. Co-location constraints are not allowed.
+ *
+ * <p>3. Intra-bulk input location preferences will be ignored.
+ */
+public class OneSlotPerExecutionSlotAllocator extends 
AbstractExecutionSlotAllocator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(OneSlotPerExecutionSlotAllocator.class);
+
+       private final SlotProvider slotProvider;
+
+       private final SlotOwner slotOwner;
+
+       private final boolean slotWillBeOccupiedIndefinitely;
+
+       private final Time allocationTimeout;
+
+       public OneSlotPerExecutionSlotAllocator(
+                       final SlotProvider slotProvider,
+                       final InputsLocationsRetriever inputsLocationsRetriever,
+                       final boolean slotWillBeOccupiedIndefinitely,
+                       final Time allocationTimeout) {
+
+               super(inputsLocationsRetriever);
+
+               this.slotProvider = checkNotNull(slotProvider);
+               this.slotWillBeOccupiedIndefinitely = 
slotWillBeOccupiedIndefinitely;
+               this.allocationTimeout = checkNotNull(allocationTimeout);
+
+               this.slotOwner = new 
OneSlotPerExecutionSlotAllocatorSlotOwner();
+       }
+
+       @Override
+       public List<SlotExecutionVertexAssignment> allocateSlotsFor(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements) {
+
+               
validateSchedulingRequirements(executionVertexSchedulingRequirements);
+
+               
validateNoCoLocationConstraint(executionVertexSchedulingRequirements);
+
+               final Set<ExecutionVertexID> allExecutionVertexIds = 
executionVertexSchedulingRequirements.stream()
+                       
.map(ExecutionVertexSchedulingRequirements::getExecutionVertexId)
+                       .collect(Collectors.toSet());
+
+               final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds =
+                       
generateExecutionVertexSlotRequestIds(allExecutionVertexIds);
+
+               final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                       
createSlotExecutionVertexAssignments(executionVertexSchedulingRequirements, 
executionVertexSlotRequestIds);
+
+               final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
+                       createPhysicalSlotRequestFutures(
+                               executionVertexSchedulingRequirements,
+                               allExecutionVertexIds,
+                               executionVertexSlotRequestIds);
+
+               allocateSlotsForAssignments(
+                       physicalSlotRequestFutures,
+                       slotExecutionVertexAssignments,
+                       executionVertexSlotRequestIds);
+
+               return slotExecutionVertexAssignments;
+       }
+
+       private static void validateNoCoLocationConstraint(
+                       final Collection<ExecutionVertexSchedulingRequirements> 
schedulingRequirements) {
+
+               final boolean hasCoLocationConstraint = 
schedulingRequirements.stream()
+                       .anyMatch(r -> r.getCoLocationConstraint() != null);
+               checkState(
+                       !hasCoLocationConstraint,
+                       "Jobs with co-location constraints are not allowed to 
run with pipelined region scheduling strategy.");
+       }
+
+       private Map<ExecutionVertexID, SlotRequestId> 
generateExecutionVertexSlotRequestIds(
+                       final Set<ExecutionVertexID> allExecutionVertexIds) {
+
+               final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds = new HashMap<>();
+               for (ExecutionVertexID executionVertexId : 
allExecutionVertexIds) {
+                       executionVertexSlotRequestIds.put(executionVertexId, 
new SlotRequestId());
+               }
+               return executionVertexSlotRequestIds;
+       }
+
+       private List<SlotExecutionVertexAssignment> 
createSlotExecutionVertexAssignments(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                       new 
ArrayList<>(executionVertexSchedulingRequirements.size());
+               for (ExecutionVertexSchedulingRequirements 
schedulingRequirements : executionVertexSchedulingRequirements) {
+                       final ExecutionVertexID executionVertexId = 
schedulingRequirements.getExecutionVertexId();
+                       final SlotRequestId slotRequestId = 
executionVertexSlotRequestIds.get(executionVertexId);
+
+                       final SlotExecutionVertexAssignment 
slotExecutionVertexAssignment =
+                               createAndRegisterSlotExecutionVertexAssignment(
+                                       executionVertexId,
+                                       new CompletableFuture<>(),
+                                       throwable -> 
slotProvider.cancelSlotRequest(slotRequestId, null, throwable));
+                       
slotExecutionVertexAssignments.add(slotExecutionVertexAssignment);
+               }
+
+               return slotExecutionVertexAssignments;
+       }
+
+       private List<CompletableFuture<PhysicalSlotRequest>> 
createPhysicalSlotRequestFutures(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements,
+                       final Set<ExecutionVertexID> allExecutionVertexIds,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final Set<AllocationID> allPreviousAllocationIds =
+                       
computeAllPriorAllocationIds(executionVertexSchedulingRequirements);
+
+               final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
+                       new 
ArrayList<>(executionVertexSchedulingRequirements.size());
+               for (ExecutionVertexSchedulingRequirements 
schedulingRequirements : executionVertexSchedulingRequirements) {
+                       final ExecutionVertexID executionVertexId = 
schedulingRequirements.getExecutionVertexId();
+                       final SlotRequestId slotRequestId = 
executionVertexSlotRequestIds.get(executionVertexId);
+
+                       LOG.debug("Allocate slot with id {} for execution {}", 
slotRequestId, executionVertexId);
+
+                       final 
CompletableFuture<Collection<TaskManagerLocation>> preferredLocationsFuture =
+                               calculatePreferredLocations(
+                                       executionVertexId,
+                                       
schedulingRequirements.getPreferredLocations(),
+                                       inputsLocationsRetriever,
+                                       allExecutionVertexIds);
+
+                       // use the task resource profile as the physical slot 
resource requirement since slot sharing is ignored
+                       final CompletableFuture<SlotProfile> slotProfileFuture 
= preferredLocationsFuture.thenApply(
+                               preferredLocations ->
+                                       SlotProfile.priorAllocation(
+                                               
schedulingRequirements.getTaskResourceProfile(),
+                                               
schedulingRequirements.getTaskResourceProfile(),
+                                               preferredLocations,
+                                               
Collections.singletonList(schedulingRequirements.getPreviousAllocationId()),
+                                               allPreviousAllocationIds));
+
+                       final CompletableFuture<PhysicalSlotRequest> 
physicalSlotRequestFuture =
+                               slotProfileFuture.thenApply(
+                                       slotProfile -> 
createPhysicalSlotRequest(slotRequestId, slotProfile));
+                       
physicalSlotRequestFutures.add(physicalSlotRequestFuture);
+               }
+
+               return physicalSlotRequestFutures;
+       }
+
+       private PhysicalSlotRequest createPhysicalSlotRequest(
+                       final SlotRequestId slotRequestId,
+                       final SlotProfile slotProfile) {
+               return new PhysicalSlotRequest(slotRequestId, slotProfile, 
slotWillBeOccupiedIndefinitely);
+       }
+
+       private void allocateSlotsForAssignments(
+                       final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures,
+                       final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final Map<ExecutionVertexID, SlotExecutionVertexAssignment> 
vertexToAssignmentMapping =
+                       slotExecutionVertexAssignments.stream()
+                               
.collect(Collectors.toMap(SlotExecutionVertexAssignment::getExecutionVertexId, 
Function.identity()));
+
+               final Map<SlotRequestId, ExecutionVertexID> slotToVertexMapping 
= new HashMap<>();
+               for (Map.Entry<ExecutionVertexID, SlotRequestId> entry : 
executionVertexSlotRequestIds.entrySet()) {
+                       slotToVertexMapping.put(entry.getValue(), 
entry.getKey());
+               }
+
+               FutureUtils.combineAll(physicalSlotRequestFutures)
+                       .thenCompose(physicalSlotRequests -> 
slotProvider.allocatePhysicalSlots(physicalSlotRequests, allocationTimeout))
+                       .thenAccept(physicalSlotRequestResults -> {
+                               for (PhysicalSlotRequest.Result result : 
physicalSlotRequestResults) {
+                                       final SlotRequestId slotRequestId = 
result.getSlotRequestId();
+                                       final ExecutionVertexID 
executionVertexId = slotToVertexMapping.get(slotRequestId);
+                                       final LogicalSlot logicalSlot = 
allocateSingleLogicalSlotFromPhysicalSlot(
+                                               slotRequestId,
+                                               result.getPhysicalSlot());
+                                       
vertexToAssignmentMapping.get(executionVertexId).getLogicalSlotFuture().complete(logicalSlot);
+                               }
+                       })
+                       .exceptionally(ex -> {
+                               executionVertexSlotRequestIds.values().stream()
+                                       .forEach(slotRequestId -> {
+                                               final ExecutionVertexID 
executionVertexId = slotToVertexMapping.get(slotRequestId);
+                                               
vertexToAssignmentMapping.get(executionVertexId).getLogicalSlotFuture().completeExceptionally(ex);
+                                       });
+                               return null;
+                       });
+       }
+
+       private LogicalSlot allocateSingleLogicalSlotFromPhysicalSlot(

Review comment:
       Maybe, this could be 
`SingleLogicalSlot#createAndAllocateFromPhysicalSlot`.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/OneSlotPerExecutionSlotAllocator.java
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.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.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotOwner;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest;
+import org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot;
+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.apache.flink.util.FlinkException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This slot allocator will request one physical slot for each single 
execution vertex.
+ * The slots will be requested in bulks so that the {@link SlotProvider} can 
check
+ * whether this bulk of slot requests can be fulfilled at the same time.
+ * It has several limitations:
+ *
+ * <p>1. Slot sharing will be ignored.
+ *
+ * <p>2. Co-location constraints are not allowed.
+ *
+ * <p>3. Intra-bulk input location preferences will be ignored.
+ */
+public class OneSlotPerExecutionSlotAllocator extends 
AbstractExecutionSlotAllocator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(OneSlotPerExecutionSlotAllocator.class);
+
+       private final SlotProvider slotProvider;
+
+       private final SlotOwner slotOwner;
+
+       private final boolean slotWillBeOccupiedIndefinitely;
+
+       private final Time allocationTimeout;
+
+       public OneSlotPerExecutionSlotAllocator(

Review comment:
       ```suggestion
        OneSlotPerExecutionSlotAllocator(
   ```

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultExecutionSlotAllocatorTest.java
##########
@@ -216,13 +221,37 @@ private SlotExecutionVertexAssignment 
findSlotAssignmentByExecutionVertexId(
                                Time timeout) {
 
                        slotAllocationRequests.add(Tuple3.of(slotRequestId, 
task, slotProfile));
-                       if (slotAllocationDisabled) {
+                       if (forceFailingSlotAllocation) {
+                               return FutureUtils.completedExceptionally(new 
Exception("Forced failure"));
+                       } else if (slotAllocationDisabled) {
                                return new CompletableFuture<>();
                        } else {
                                return CompletableFuture.completedFuture(new 
TestingLogicalSlotBuilder().createTestingLogicalSlot());
                        }
                }
 
+               public 
CompletableFuture<Collection<PhysicalSlotRequest.Result>> allocatePhysicalSlots(

Review comment:
       If we would manage to make `OneSlotPerExecutionSlotAllocator` depending 
on `BulkSlotProvider`, this `allocatePhysicalSlots` could in a separate 
`AllocationToggableBulkSlotProvider` or so, as a separate commit if we do it.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultExecutionSlotAllocatorTest.java
##########
@@ -200,14 +203,16 @@ private SlotExecutionVertexAssignment 
findSlotAssignmentByExecutionVertexId(
                                                executionVertexId)));
        }
 
-       private static class AllocationToggableSlotProvider implements 
SlotProvider {
+       static class AllocationToggableSlotProvider implements SlotProvider {
 
                private final List<Tuple3<SlotRequestId, ScheduledUnit, 
SlotProfile>> slotAllocationRequests = new ArrayList<>();
 
                private final List<SlotRequestId> cancelledSlotRequestIds = new 
ArrayList<>();
 
                private boolean slotAllocationDisabled;
 
+               private boolean forceFailingSlotAllocation = false;

Review comment:
       ```suggestion
                private boolean forceFailingSlotAllocation;
   ```

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/OneSlotPerExecutionSlotAllocatorFactory.java
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.api.common.time.Time;
+import org.apache.flink.runtime.jobmaster.slotpool.SlotProvider;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Factory for {@link OneSlotPerExecutionSlotAllocator}.
+ */
+public class OneSlotPerExecutionSlotAllocatorFactory implements 
ExecutionSlotAllocatorFactory {
+
+       private final SlotProvider slotProvider;
+
+       private final boolean slotWillBeOccupiedIndefinitely;
+
+       private final Time allocationTimeout;
+
+       public OneSlotPerExecutionSlotAllocatorFactory(

Review comment:
       ```suggestion
        OneSlotPerExecutionSlotAllocatorFactory(
   ```

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultExecutionSlotAllocatorTest.java
##########
@@ -189,7 +192,7 @@ private DefaultExecutionSlotAllocator 
createExecutionSlotAllocator(InputsLocatio
                return schedulingRequirements;
        }
 
-       private SlotExecutionVertexAssignment 
findSlotAssignmentByExecutionVertexId(
+       static SlotExecutionVertexAssignment 
findSlotAssignmentByExecutionVertexId(

Review comment:
       nit: would be nice to have a separate static util class for the shared 
static methods

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/OneSlotPerExecutionSlotAllocator.java
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.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.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotOwner;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest;
+import org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot;
+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.apache.flink.util.FlinkException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This slot allocator will request one physical slot for each single 
execution vertex.
+ * The slots will be requested in bulks so that the {@link SlotProvider} can 
check
+ * whether this bulk of slot requests can be fulfilled at the same time.
+ * It has several limitations:
+ *
+ * <p>1. Slot sharing will be ignored.
+ *
+ * <p>2. Co-location constraints are not allowed.
+ *
+ * <p>3. Intra-bulk input location preferences will be ignored.
+ */
+public class OneSlotPerExecutionSlotAllocator extends 
AbstractExecutionSlotAllocator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(OneSlotPerExecutionSlotAllocator.class);
+
+       private final SlotProvider slotProvider;
+
+       private final SlotOwner slotOwner;
+
+       private final boolean slotWillBeOccupiedIndefinitely;
+
+       private final Time allocationTimeout;
+
+       public OneSlotPerExecutionSlotAllocator(
+                       final SlotProvider slotProvider,
+                       final InputsLocationsRetriever inputsLocationsRetriever,
+                       final boolean slotWillBeOccupiedIndefinitely,
+                       final Time allocationTimeout) {
+
+               super(inputsLocationsRetriever);
+
+               this.slotProvider = checkNotNull(slotProvider);
+               this.slotWillBeOccupiedIndefinitely = 
slotWillBeOccupiedIndefinitely;
+               this.allocationTimeout = checkNotNull(allocationTimeout);
+
+               this.slotOwner = new 
OneSlotPerExecutionSlotAllocatorSlotOwner();
+       }
+
+       @Override
+       public List<SlotExecutionVertexAssignment> allocateSlotsFor(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements) {
+
+               
validateSchedulingRequirements(executionVertexSchedulingRequirements);
+
+               
validateNoCoLocationConstraint(executionVertexSchedulingRequirements);
+
+               final Set<ExecutionVertexID> allExecutionVertexIds = 
executionVertexSchedulingRequirements.stream()
+                       
.map(ExecutionVertexSchedulingRequirements::getExecutionVertexId)
+                       .collect(Collectors.toSet());
+
+               final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds =
+                       
generateExecutionVertexSlotRequestIds(allExecutionVertexIds);
+
+               final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                       
createSlotExecutionVertexAssignments(executionVertexSchedulingRequirements, 
executionVertexSlotRequestIds);
+
+               final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
+                       createPhysicalSlotRequestFutures(
+                               executionVertexSchedulingRequirements,
+                               allExecutionVertexIds,
+                               executionVertexSlotRequestIds);
+
+               allocateSlotsForAssignments(
+                       physicalSlotRequestFutures,
+                       slotExecutionVertexAssignments,
+                       executionVertexSlotRequestIds);
+
+               return slotExecutionVertexAssignments;
+       }
+
+       private static void validateNoCoLocationConstraint(
+                       final Collection<ExecutionVertexSchedulingRequirements> 
schedulingRequirements) {
+
+               final boolean hasCoLocationConstraint = 
schedulingRequirements.stream()
+                       .anyMatch(r -> r.getCoLocationConstraint() != null);
+               checkState(
+                       !hasCoLocationConstraint,
+                       "Jobs with co-location constraints are not allowed to 
run with pipelined region scheduling strategy.");
+       }
+
+       private Map<ExecutionVertexID, SlotRequestId> 
generateExecutionVertexSlotRequestIds(
+                       final Set<ExecutionVertexID> allExecutionVertexIds) {
+
+               final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds = new HashMap<>();
+               for (ExecutionVertexID executionVertexId : 
allExecutionVertexIds) {
+                       executionVertexSlotRequestIds.put(executionVertexId, 
new SlotRequestId());
+               }
+               return executionVertexSlotRequestIds;
+       }
+
+       private List<SlotExecutionVertexAssignment> 
createSlotExecutionVertexAssignments(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                       new 
ArrayList<>(executionVertexSchedulingRequirements.size());
+               for (ExecutionVertexSchedulingRequirements 
schedulingRequirements : executionVertexSchedulingRequirements) {
+                       final ExecutionVertexID executionVertexId = 
schedulingRequirements.getExecutionVertexId();
+                       final SlotRequestId slotRequestId = 
executionVertexSlotRequestIds.get(executionVertexId);
+
+                       final SlotExecutionVertexAssignment 
slotExecutionVertexAssignment =
+                               createAndRegisterSlotExecutionVertexAssignment(
+                                       executionVertexId,
+                                       new CompletableFuture<>(),
+                                       throwable -> 
slotProvider.cancelSlotRequest(slotRequestId, null, throwable));
+                       
slotExecutionVertexAssignments.add(slotExecutionVertexAssignment);
+               }
+
+               return slotExecutionVertexAssignments;
+       }
+
+       private List<CompletableFuture<PhysicalSlotRequest>> 
createPhysicalSlotRequestFutures(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements,
+                       final Set<ExecutionVertexID> allExecutionVertexIds,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final Set<AllocationID> allPreviousAllocationIds =
+                       
computeAllPriorAllocationIds(executionVertexSchedulingRequirements);
+
+               final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
+                       new 
ArrayList<>(executionVertexSchedulingRequirements.size());
+               for (ExecutionVertexSchedulingRequirements 
schedulingRequirements : executionVertexSchedulingRequirements) {
+                       final ExecutionVertexID executionVertexId = 
schedulingRequirements.getExecutionVertexId();
+                       final SlotRequestId slotRequestId = 
executionVertexSlotRequestIds.get(executionVertexId);
+
+                       LOG.debug("Allocate slot with id {} for execution {}", 
slotRequestId, executionVertexId);
+
+                       final 
CompletableFuture<Collection<TaskManagerLocation>> preferredLocationsFuture =
+                               calculatePreferredLocations(
+                                       executionVertexId,
+                                       
schedulingRequirements.getPreferredLocations(),
+                                       inputsLocationsRetriever,
+                                       allExecutionVertexIds);
+
+                       // use the task resource profile as the physical slot 
resource requirement since slot sharing is ignored
+                       final CompletableFuture<SlotProfile> slotProfileFuture 
= preferredLocationsFuture.thenApply(
+                               preferredLocations ->
+                                       SlotProfile.priorAllocation(
+                                               
schedulingRequirements.getTaskResourceProfile(),
+                                               
schedulingRequirements.getTaskResourceProfile(),
+                                               preferredLocations,
+                                               
Collections.singletonList(schedulingRequirements.getPreviousAllocationId()),
+                                               allPreviousAllocationIds));
+
+                       final CompletableFuture<PhysicalSlotRequest> 
physicalSlotRequestFuture =
+                               slotProfileFuture.thenApply(
+                                       slotProfile -> 
createPhysicalSlotRequest(slotRequestId, slotProfile));
+                       
physicalSlotRequestFutures.add(physicalSlotRequestFuture);
+               }
+
+               return physicalSlotRequestFutures;
+       }
+
+       private PhysicalSlotRequest createPhysicalSlotRequest(
+                       final SlotRequestId slotRequestId,
+                       final SlotProfile slotProfile) {
+               return new PhysicalSlotRequest(slotRequestId, slotProfile, 
slotWillBeOccupiedIndefinitely);
+       }
+
+       private void allocateSlotsForAssignments(
+                       final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures,
+                       final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final Map<ExecutionVertexID, SlotExecutionVertexAssignment> 
vertexToAssignmentMapping =
+                       slotExecutionVertexAssignments.stream()
+                               
.collect(Collectors.toMap(SlotExecutionVertexAssignment::getExecutionVertexId, 
Function.identity()));
+
+               final Map<SlotRequestId, ExecutionVertexID> slotToVertexMapping 
= new HashMap<>();
+               for (Map.Entry<ExecutionVertexID, SlotRequestId> entry : 
executionVertexSlotRequestIds.entrySet()) {
+                       slotToVertexMapping.put(entry.getValue(), 
entry.getKey());
+               }
+
+               FutureUtils.combineAll(physicalSlotRequestFutures)
+                       .thenCompose(physicalSlotRequests -> 
slotProvider.allocatePhysicalSlots(physicalSlotRequests, allocationTimeout))
+                       .thenAccept(physicalSlotRequestResults -> {
+                               for (PhysicalSlotRequest.Result result : 
physicalSlotRequestResults) {
+                                       final SlotRequestId slotRequestId = 
result.getSlotRequestId();
+                                       final ExecutionVertexID 
executionVertexId = slotToVertexMapping.get(slotRequestId);
+                                       final LogicalSlot logicalSlot = 
allocateSingleLogicalSlotFromPhysicalSlot(
+                                               slotRequestId,
+                                               result.getPhysicalSlot());
+                                       
vertexToAssignmentMapping.get(executionVertexId).getLogicalSlotFuture().complete(logicalSlot);
+                               }
+                       })
+                       .exceptionally(ex -> {
+                               executionVertexSlotRequestIds.values().stream()

Review comment:
       ```suggestion
                                executionVertexSlotRequestIds.values()
   ```

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/OneSlotPerExecutionSlotAllocator.java
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.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.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotOwner;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest;
+import org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot;
+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.apache.flink.util.FlinkException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This slot allocator will request one physical slot for each single 
execution vertex.
+ * The slots will be requested in bulks so that the {@link SlotProvider} can 
check
+ * whether this bulk of slot requests can be fulfilled at the same time.
+ * It has several limitations:
+ *
+ * <p>1. Slot sharing will be ignored.
+ *
+ * <p>2. Co-location constraints are not allowed.
+ *
+ * <p>3. Intra-bulk input location preferences will be ignored.
+ */
+public class OneSlotPerExecutionSlotAllocator extends 
AbstractExecutionSlotAllocator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(OneSlotPerExecutionSlotAllocator.class);
+
+       private final SlotProvider slotProvider;
+
+       private final SlotOwner slotOwner;
+
+       private final boolean slotWillBeOccupiedIndefinitely;
+
+       private final Time allocationTimeout;
+
+       public OneSlotPerExecutionSlotAllocator(
+                       final SlotProvider slotProvider,
+                       final InputsLocationsRetriever inputsLocationsRetriever,
+                       final boolean slotWillBeOccupiedIndefinitely,
+                       final Time allocationTimeout) {
+
+               super(inputsLocationsRetriever);
+
+               this.slotProvider = checkNotNull(slotProvider);
+               this.slotWillBeOccupiedIndefinitely = 
slotWillBeOccupiedIndefinitely;
+               this.allocationTimeout = checkNotNull(allocationTimeout);
+
+               this.slotOwner = new 
OneSlotPerExecutionSlotAllocatorSlotOwner();
+       }
+
+       @Override
+       public List<SlotExecutionVertexAssignment> allocateSlotsFor(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements) {
+
+               
validateSchedulingRequirements(executionVertexSchedulingRequirements);
+
+               
validateNoCoLocationConstraint(executionVertexSchedulingRequirements);
+
+               final Set<ExecutionVertexID> allExecutionVertexIds = 
executionVertexSchedulingRequirements.stream()
+                       
.map(ExecutionVertexSchedulingRequirements::getExecutionVertexId)
+                       .collect(Collectors.toSet());
+
+               final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds =
+                       
generateExecutionVertexSlotRequestIds(allExecutionVertexIds);
+
+               final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                       
createSlotExecutionVertexAssignments(executionVertexSchedulingRequirements, 
executionVertexSlotRequestIds);
+
+               final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
+                       createPhysicalSlotRequestFutures(
+                               executionVertexSchedulingRequirements,
+                               allExecutionVertexIds,
+                               executionVertexSlotRequestIds);
+
+               allocateSlotsForAssignments(
+                       physicalSlotRequestFutures,
+                       slotExecutionVertexAssignments,
+                       executionVertexSlotRequestIds);
+
+               return slotExecutionVertexAssignments;
+       }
+
+       private static void validateNoCoLocationConstraint(
+                       final Collection<ExecutionVertexSchedulingRequirements> 
schedulingRequirements) {
+
+               final boolean hasCoLocationConstraint = 
schedulingRequirements.stream()
+                       .anyMatch(r -> r.getCoLocationConstraint() != null);
+               checkState(
+                       !hasCoLocationConstraint,
+                       "Jobs with co-location constraints are not allowed to 
run with pipelined region scheduling strategy.");
+       }
+
+       private Map<ExecutionVertexID, SlotRequestId> 
generateExecutionVertexSlotRequestIds(
+                       final Set<ExecutionVertexID> allExecutionVertexIds) {
+
+               final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds = new HashMap<>();
+               for (ExecutionVertexID executionVertexId : 
allExecutionVertexIds) {
+                       executionVertexSlotRequestIds.put(executionVertexId, 
new SlotRequestId());
+               }
+               return executionVertexSlotRequestIds;
+       }
+
+       private List<SlotExecutionVertexAssignment> 
createSlotExecutionVertexAssignments(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                       new 
ArrayList<>(executionVertexSchedulingRequirements.size());
+               for (ExecutionVertexSchedulingRequirements 
schedulingRequirements : executionVertexSchedulingRequirements) {
+                       final ExecutionVertexID executionVertexId = 
schedulingRequirements.getExecutionVertexId();
+                       final SlotRequestId slotRequestId = 
executionVertexSlotRequestIds.get(executionVertexId);
+
+                       final SlotExecutionVertexAssignment 
slotExecutionVertexAssignment =
+                               createAndRegisterSlotExecutionVertexAssignment(
+                                       executionVertexId,
+                                       new CompletableFuture<>(),
+                                       throwable -> 
slotProvider.cancelSlotRequest(slotRequestId, null, throwable));
+                       
slotExecutionVertexAssignments.add(slotExecutionVertexAssignment);
+               }
+
+               return slotExecutionVertexAssignments;
+       }
+
+       private List<CompletableFuture<PhysicalSlotRequest>> 
createPhysicalSlotRequestFutures(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements,
+                       final Set<ExecutionVertexID> allExecutionVertexIds,
+                       final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds) {
+
+               final Set<AllocationID> allPreviousAllocationIds =
+                       
computeAllPriorAllocationIds(executionVertexSchedulingRequirements);
+
+               final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
+                       new 
ArrayList<>(executionVertexSchedulingRequirements.size());
+               for (ExecutionVertexSchedulingRequirements 
schedulingRequirements : executionVertexSchedulingRequirements) {
+                       final ExecutionVertexID executionVertexId = 
schedulingRequirements.getExecutionVertexId();
+                       final SlotRequestId slotRequestId = 
executionVertexSlotRequestIds.get(executionVertexId);
+
+                       LOG.debug("Allocate slot with id {} for execution {}", 
slotRequestId, executionVertexId);
+
+                       final 
CompletableFuture<Collection<TaskManagerLocation>> preferredLocationsFuture =
+                               calculatePreferredLocations(
+                                       executionVertexId,
+                                       
schedulingRequirements.getPreferredLocations(),
+                                       inputsLocationsRetriever,
+                                       allExecutionVertexIds);
+
+                       // use the task resource profile as the physical slot 
resource requirement since slot sharing is ignored
+                       final CompletableFuture<SlotProfile> slotProfileFuture 
= preferredLocationsFuture.thenApply(
+                               preferredLocations ->
+                                       SlotProfile.priorAllocation(
+                                               
schedulingRequirements.getTaskResourceProfile(),
+                                               
schedulingRequirements.getTaskResourceProfile(),
+                                               preferredLocations,
+                                               
Collections.singletonList(schedulingRequirements.getPreviousAllocationId()),
+                                               allPreviousAllocationIds));

Review comment:
       ```
   private CompletableFuture<SlotProfile> getSlotProfileFuture(
                        Set<ExecutionVertexID> allExecutionVertexIds,
                        Set<AllocationID> allPreviousAllocationIds,
                        ExecutionVertexSchedulingRequirements 
schedulingRequirements) {
                final CompletableFuture<Collection<TaskManagerLocation>> 
preferredLocationsFuture =
                        calculatePreferredLocations(
                                schedulingRequirements.getExecutionVertexId(),
                                allExecutionVertexIds);
   
                // use the task resource profile as the physical slot resource 
requirement since slot sharing is ignored
                return preferredLocationsFuture.thenApply(
                        preferredLocations ->
                                SlotProfile.priorAllocation(
                                        
schedulingRequirements.getTaskResourceProfile(),
                                        
schedulingRequirements.getTaskResourceProfile(),
                                        preferredLocations,
                                        
Collections.singletonList(schedulingRequirements.getPreviousAllocationId()),
                                        allPreviousAllocationIds));
        }
   ```
   
   Maybe even deduplicate it with `DefaultExecutionSlotAllocator` by adding an 
additional `ResourceProfile physicalSlotResourceProfile` arg.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultExecutionSlotAllocatorTest.java
##########
@@ -200,14 +203,16 @@ private SlotExecutionVertexAssignment 
findSlotAssignmentByExecutionVertexId(
                                                executionVertexId)));
        }
 
-       private static class AllocationToggableSlotProvider implements 
SlotProvider {
+       static class AllocationToggableSlotProvider implements SlotProvider {
 
                private final List<Tuple3<SlotRequestId, ScheduledUnit, 
SlotProfile>> slotAllocationRequests = new ArrayList<>();
 
                private final List<SlotRequestId> cancelledSlotRequestIds = new 
ArrayList<>();
 
                private boolean slotAllocationDisabled;
 
+               private boolean forceFailingSlotAllocation = false;

Review comment:
       nit: it would be nice to introduce `enum AllocationTypeEnum {ENABLED, 
DISABLED, FAILING}`

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/OneSlotPerExecutionSlotAllocator.java
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.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.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotOwner;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot;
+import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest;
+import org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot;
+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.apache.flink.util.FlinkException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This slot allocator will request one physical slot for each single 
execution vertex.
+ * The slots will be requested in bulks so that the {@link SlotProvider} can 
check
+ * whether this bulk of slot requests can be fulfilled at the same time.
+ * It has several limitations:
+ *
+ * <p>1. Slot sharing will be ignored.
+ *
+ * <p>2. Co-location constraints are not allowed.
+ *
+ * <p>3. Intra-bulk input location preferences will be ignored.
+ */
+public class OneSlotPerExecutionSlotAllocator extends 
AbstractExecutionSlotAllocator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(OneSlotPerExecutionSlotAllocator.class);
+
+       private final SlotProvider slotProvider;
+
+       private final SlotOwner slotOwner;
+
+       private final boolean slotWillBeOccupiedIndefinitely;
+
+       private final Time allocationTimeout;
+
+       public OneSlotPerExecutionSlotAllocator(
+                       final SlotProvider slotProvider,
+                       final InputsLocationsRetriever inputsLocationsRetriever,
+                       final boolean slotWillBeOccupiedIndefinitely,
+                       final Time allocationTimeout) {
+
+               super(inputsLocationsRetriever);
+
+               this.slotProvider = checkNotNull(slotProvider);
+               this.slotWillBeOccupiedIndefinitely = 
slotWillBeOccupiedIndefinitely;
+               this.allocationTimeout = checkNotNull(allocationTimeout);
+
+               this.slotOwner = new 
OneSlotPerExecutionSlotAllocatorSlotOwner();
+       }
+
+       @Override
+       public List<SlotExecutionVertexAssignment> allocateSlotsFor(
+                       final List<ExecutionVertexSchedulingRequirements> 
executionVertexSchedulingRequirements) {
+
+               
validateSchedulingRequirements(executionVertexSchedulingRequirements);
+
+               
validateNoCoLocationConstraint(executionVertexSchedulingRequirements);
+
+               final Set<ExecutionVertexID> allExecutionVertexIds = 
executionVertexSchedulingRequirements.stream()
+                       
.map(ExecutionVertexSchedulingRequirements::getExecutionVertexId)
+                       .collect(Collectors.toSet());
+
+               final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds =
+                       
generateExecutionVertexSlotRequestIds(allExecutionVertexIds);
+
+               final List<SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
+                       
createSlotExecutionVertexAssignments(executionVertexSchedulingRequirements, 
executionVertexSlotRequestIds);
+
+               final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
+                       createPhysicalSlotRequestFutures(
+                               executionVertexSchedulingRequirements,
+                               allExecutionVertexIds,
+                               executionVertexSlotRequestIds);
+
+               allocateSlotsForAssignments(
+                       physicalSlotRequestFutures,
+                       slotExecutionVertexAssignments,
+                       executionVertexSlotRequestIds);
+
+               return slotExecutionVertexAssignments;

Review comment:
       ```suggestion
                final Map<SlotRequestId, SlotExecutionVertexAssignment> 
slotExecutionVertexAssignments =
                        
createSlotExecutionVertexAssignments(executionVertexSchedulingRequirements);
   
                final Map<ExecutionVertexID, SlotRequestId> 
executionVertexSlotRequestIds = slotExecutionVertexAssignments
                        .entrySet()
                        .stream()
                        .collect(Collectors.toMap(e -> 
e.getValue().getExecutionVertexId(), Map.Entry::getKey));
   
                final List<CompletableFuture<PhysicalSlotRequest>> 
physicalSlotRequestFutures =
                        createPhysicalSlotRequestFutures(
                                executionVertexSchedulingRequirements,
                                executionVertexSlotRequestIds);
   
                allocateSlotsForAssignments(
                        physicalSlotRequestFutures,
                        slotExecutionVertexAssignments);
   
                return new ArrayList<>(slotExecutionVertexAssignments.values());
   ```
   This seems to be a bit less indexing... It also implies some simplification 
of the called private methods.




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