Class TaskStatsRequestCoordinator<T,V>

java.lang.Object
org.apache.flink.runtime.webmonitor.stats.TaskStatsRequestCoordinator<T,V>
Type Parameters:
T - Type of the statistics to be gathered.
V - Type of the combined response.
Direct Known Subclasses:
ThreadInfoRequestCoordinator

public class TaskStatsRequestCoordinator<T,V> extends Object
Encapsulates the common functionality for requesting statistics from tasks and combining their responses.
  • Field Details

    • log

      protected final org.slf4j.Logger log
    • NUM_GHOST_SAMPLE_IDS

      protected static final int NUM_GHOST_SAMPLE_IDS
      See Also:
    • lock

      protected final Object lock
    • executor

      protected final Executor executor
      Executor used to run the futures.
    • requestTimeout

      protected final Duration requestTimeout
      Request time out of the triggered tasks stats request.
    • pendingRequests

      protected final Map<Integer,TaskStatsRequestCoordinator.PendingStatsRequest<T,V>> pendingRequests
      In progress samples.
    • recentPendingRequestIds

      protected final ArrayDeque<Integer> recentPendingRequestIds
      A list of recent request IDs to identify late messages vs. invalid ones.
    • requestIdCounter

      protected int requestIdCounter
      Sample ID counter.
    • isShutDown

      protected boolean isShutDown
      Flag indicating whether the coordinator is still running.
  • Constructor Details

    • TaskStatsRequestCoordinator

      public TaskStatsRequestCoordinator(Executor executor, Duration requestTimeout)
      Creates a new coordinator for the cluster.
      Parameters:
      executor - Used to execute the futures.
      requestTimeout - Request time out of the triggered tasks stats request.
  • Method Details

    • handleFailedResponse

      public void handleFailedResponse(int requestId, @Nullable Throwable cause)
      Handles the failed stats response by canceling the corresponding unfinished pending request.
      Parameters:
      requestId - ID of the request to cancel.
      cause - Cause of the cancelling (can be null).
    • shutDown

      public void shutDown()
      Shuts down the coordinator.

      After shut down, no further operations are executed.

    • handleSuccessfulResponse

      public void handleSuccessfulResponse(int requestId, org.apache.flink.shaded.guava32.com.google.common.collect.ImmutableSet<ExecutionAttemptID> executionIds, T result)
      Handles the successfully returned tasks stats response by collecting the corresponding subtask samples.
      Parameters:
      requestId - ID of the request.
      executionIds - ID of the sampled task.
      result - Result of stats request returned by an individual task.
      Throws:
      IllegalStateException - If unknown request ID and not recently finished or cancelled sample.
    • getNumberOfPendingRequests

      @VisibleForTesting public int getNumberOfPendingRequests()