krishan1390 commented on code in PR #16433:
URL: https://github.com/apache/pinot/pull/16433#discussion_r2233706028


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java:
##########
@@ -776,6 +776,120 @@ public synchronized Map<String, TaskCount> 
getTaskCounts(String taskType) {
     return taskCounts;
   }
 
+  /**
+   * Fetch count of sub-tasks for each of the tasks for the given taskType, 
filtered by state.
+   *
+   * @param taskType      Pinot taskType / Helix JobQueue
+   * @param state         State(s) to filter by. Can be single state or 
comma-separated multiple states
+   *                      (waiting, running, error, completed, dropped, 
timedOut, aborted, unknown, total)
+   * @return Map of Pinot Task Name to TaskCount containing only tasks that 
have > 0 count for any of the
+   *         specified states
+   */
+  public synchronized Map<String, TaskCount> getTaskCounts(String taskType, 
String state) {
+    return getTaskCounts(taskType, state, null);
+  }
+
+  /**
+   * Fetch count of sub-tasks for each of the tasks for the given taskType, 
filtered by state and/or table.
+   *
+   * @param taskType           Pinot taskType / Helix JobQueue
+   * @param state              State(s) to filter by. Can be single state or 
comma-separated multiple states
+   *                           (NOT_STARTED, IN_PROGRESS, STOPPED, STOPPING, 
FAILED, COMPLETED, ABORTED, TIMED_OUT,
+   *                           TIMING_OUT, FAILING). Can be null to skip state 
filtering.
+   * @param tableNameWithType  Table name with type to filter by. Only tasks 
that have subtasks for this table
+   *                           will be returned. Can be null to skip table 
filtering.
+   * @return Map of Pinot Task Name to TaskCount containing only tasks that 
match the specified filters
+   */
+  public synchronized Map<String, TaskCount> getTaskCounts(String taskType, 
String state, String tableNameWithType) {
+    Set<String> tasks = getTasks(taskType);
+    if (tasks == null) {
+      return Collections.emptyMap();
+    }
+
+    // Parse and validate comma-separated states if provided
+    Set<TaskState> requestedStates = null;
+    if (state != null) {
+      String[] stateArray = state.trim().split(",");
+      requestedStates = new HashSet<>();
+      for (String s : stateArray) {
+        String normalizedState = s.trim().toUpperCase();
+        // Validate each state upfront
+        TaskState taskState = validateAndParseTaskState(normalizedState);
+        requestedStates.add(taskState);
+      }
+    }
+
+    // Get all task states if we need to filter by state
+    Map<String, TaskState> taskStates = null;
+    if (requestedStates != null) {
+      taskStates = getTaskStates(taskType);
+    }
+
+    Map<String, TaskCount> taskCounts = new TreeMap<>();
+    for (String taskName : tasks) {
+      TaskCount taskCount = getTaskCount(taskName);

Review Comment:
   given collecting task state is expensive, we can collect TaskCount after 
validating filters



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to