zhuzhurk commented on a change in pull request #12256: URL: https://github.com/apache/flink/pull/12256#discussion_r429755150
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotRequestBulkTracker.java ########## @@ -0,0 +1,86 @@ +/* + * 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.util.clock.Clock; + +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Set; + +import static org.apache.flink.util.Preconditions.checkState; + +/** + * Tracks physical slot request bulks. + */ +class PhysicalSlotRequestBulkTracker { + + private final Clock clock; + + /** Timestamps indicate when bulks become unfulfillable. */ + private final Map<PhysicalSlotRequestBulk, Long> bulkUnfulfillableTimestamps; + + PhysicalSlotRequestBulkTracker(final Clock clock) { + this.clock = clock; + this.bulkUnfulfillableTimestamps = new IdentityHashMap<>(); + } + + void track(final PhysicalSlotRequestBulk bulk) { + // a bulk is initially unfulfillable + bulkUnfulfillableTimestamps.put(bulk, clock.relativeTimeMillis()); + } + + void untrack(final PhysicalSlotRequestBulk bulk) { + bulkUnfulfillableTimestamps.remove(bulk); + } + + boolean isTracked(final PhysicalSlotRequestBulk bulk) { + return bulkUnfulfillableTimestamps.containsKey(bulk); + } + + void markBulkFulfillable(final PhysicalSlotRequestBulk bulk) { + checkState(isTracked(bulk)); + + bulkUnfulfillableTimestamps.put(bulk, Long.MAX_VALUE); + } + + void markBulkUnfulfillable(final PhysicalSlotRequestBulk bulk, final long currentTimestamp) { Review comment: This is to reduce the invocations of `System.nanoTime()` and ensures the timestamp is consistent in `SchedulerImpl#checkPhysicalSlotRequestBulkTimeout(...)`. ---------------------------------------------------------------- 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]
