RocMarshal commented on code in PR #23635: URL: https://github.com/apache/flink/pull/23635#discussion_r1415650282
########## flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/GlobalViewDeclarativeSlotPoolBridge.java: ########## @@ -0,0 +1,261 @@ +/* + * 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.JobID; +import org.apache.flink.api.common.time.Time; +import org.apache.flink.runtime.clusterframework.types.AllocationID; +import org.apache.flink.runtime.clusterframework.types.ResourceProfile; +import org.apache.flink.runtime.clusterframework.types.SlotProfile; +import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor; +import org.apache.flink.runtime.jobmaster.JobMasterId; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.taskexecutor.slot.DefaultTimerService; +import org.apache.flink.runtime.taskexecutor.slot.TimeoutListener; +import org.apache.flink.runtime.taskexecutor.slot.TimerService; +import org.apache.flink.runtime.util.ResourceCounter; +import org.apache.flink.util.FlinkException; +import org.apache.flink.util.Preconditions; +import org.apache.flink.util.clock.Clock; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ScheduledThreadPoolExecutor; + +/** + * {@link SlotPool} implementation which could use the {@link GlobalViewDeclarativeSlotPoolBridge} + * to allocate slots in a global view. Note: It's only used for streaming mode now. + */ +public class GlobalViewDeclarativeSlotPoolBridge extends DeclarativeSlotPoolBridge + implements TimeoutListener<GlobalViewDeclarativeSlotPoolBridge> { + + public static final Logger LOG = + LoggerFactory.getLogger(GlobalViewDeclarativeSlotPoolBridge.class); + private final Map<SlotRequestId, Boolean> increasedResourceRequirements; + + private final TimerService<GlobalViewDeclarativeSlotPoolBridge> timerService; + + private final @Nonnull Set<PhysicalSlot> receivedNewSlots; + + private final @Nonnull Map<SlotRequestId, PhysicalSlot> preFulfilledFromAvailableSlots; + private final Time slotRequestMaxInterval; + + public GlobalViewDeclarativeSlotPoolBridge( + JobID jobId, + DeclarativeSlotPoolFactory declarativeSlotPoolFactory, + Clock clock, + Time rpcTimeout, + Time idleSlotTimeout, + Time batchSlotTimeout, + Time slotRequestMaxInterval, + RequestSlotMatchingStrategy requestSlotMatchingStrategy) { + super( + jobId, + declarativeSlotPoolFactory, + clock, + rpcTimeout, + idleSlotTimeout, + batchSlotTimeout, + requestSlotMatchingStrategy); + this.slotRequestMaxInterval = Preconditions.checkNotNull(slotRequestMaxInterval); + this.receivedNewSlots = new HashSet<>(); + this.preFulfilledFromAvailableSlots = new HashMap<>(); + this.increasedResourceRequirements = new HashMap<>(); + this.timerService = + new DefaultTimerService<>( + new ScheduledThreadPoolExecutor(1), Review Comment: +1 for the proposal. -- 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. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org