zentol commented on a change in pull request #13722: URL: https://github.com/apache/flink/pull/13722#discussion_r517928748
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/DefaultDeclarativeSlotPool.java ########## @@ -0,0 +1,461 @@ +/* + * 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.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.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.messages.Acknowledge; +import org.apache.flink.runtime.slots.ResourceRequirement; +import org.apache.flink.runtime.taskexecutor.slot.SlotOffer; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.FlinkException; +import org.apache.flink.util.Preconditions; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +/** + * Default {@link DeclarativeSlotPool} implementation. + * + * <p>The implementation collects the current resource requirements and declares them + * at the ResourceManager. Whenever new slots are offered, the slot pool compares the + * offered slots to the set of available and required resources and only accepts those + * slots which are required. + * + * <p>Slots which are released won't be returned directly to their owners. Instead, + * the slot pool implementation will only return them after the idleSlotTimeout has + * been exceeded by a free slot. + * + * <p>The slot pool will call {@link #notifyNewSlots} whenever newly offered slots are + * accepted or if an allocated slot should become free after it is being + * {@link #freeReservedSlot released}. + */ +public class DefaultDeclarativeSlotPool implements DeclarativeSlotPool { + + private static final Logger LOG = LoggerFactory.getLogger(DefaultDeclarativeSlotPool.class); + + private final Consumer<? super Collection<ResourceRequirement>> notifyNewResourceRequirements; + + private final Consumer<? super Collection<? extends PhysicalSlot>> notifyNewSlots; + + private final Time idleSlotTimeout; + private final Time rpcTimeout; + + private final AllocatedSlotPool slotPool; + + private final Map<AllocationID, ResourceProfile> slotToRequirementProfileMappings; Review comment: Agreed, the resource tracker doesn't really fit; in particular because it cannot really handle the concept of slots being reserved. I've moved the matching logic from it into a re-usable `RequirementMatcher` component that is now used by the tracker and slot pool. ---------------------------------------------------------------- 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]
