afedulov commented on a change in pull request #15054:
URL: https://github.com/apache/flink/pull/15054#discussion_r602915450



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/webmonitor/stats/TaskStatsRequestCoordinator.java
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.webmonitor.stats;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.guava18.com.google.common.collect.Maps;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.GuardedBy;
+
+import java.util.ArrayDeque;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/**
+ * Encapsulates the common functionality for requesting statistics from 
individual tasks and
+ * combining their responses.
+ *
+ * @param <T> Type of the statistics to be gathered.
+ * @param <V> Type of the combined response.
+ */
+public class TaskStatsRequestCoordinator<T, V> {
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+
+    protected final int numGhostSampleIds = 10;
+
+    protected final Object lock = new Object();
+
+    /** Executor used to run the futures. */
+    protected final Executor executor;
+
+    /** Request time out of a triggered task stats request. */
+    protected final Time requestTimeout;
+
+    /** In progress samples. */
+    @GuardedBy("lock")
+    protected final Map<Integer, PendingStatsRequest<T, V>> pendingRequests = 
new HashMap<>();
+
+    /** A list of recent request IDs to identify late messages vs. invalid 
ones. */
+    protected final ArrayDeque<Integer> recentPendingRequestIds =
+            new ArrayDeque<>(numGhostSampleIds);
+
+    /** Sample ID counter. */
+    @GuardedBy("lock")
+    protected int requestIdCounter;
+
+    /** Flag indicating whether the coordinator is still running. */
+    @GuardedBy("lock")
+    protected boolean isShutDown;
+
+    /**
+     * Creates a new coordinator for the cluster.
+     *
+     * @param executor Used to execute the futures.
+     * @param requestTimeout Request time out of a triggered task stats 
request.
+     */
+    public TaskStatsRequestCoordinator(Executor executor, long requestTimeout) 
{
+        checkArgument(requestTimeout >= 0L, "The request timeout must be 
non-negative.");

Review comment:
       As described 
[here](https://github.com/apache/flink/pull/15054/files#diff-803556ada30870d9cec571303d2d7d89a63f9980c26a79020a15ab239e2a837eR49),
 it is added on top of the expected duration for sampling, so techinally it can 
also be 0: 
   
https://github.com/apache/flink/pull/15054/files#diff-803556ada30870d9cec571303d2d7d89a63f9980c26a79020a15ab239e2a837eR117
   As this class is a generic abstraction that is supposed to be reused 
whenever sampling of any other type of statistics would be required, it seems 
that it would be allowing such cases. Not sure. What do you think?




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