aruraghuwanshi commented on code in PR #20674:
URL: https://github.com/apache/druid/pull/20674#discussion_r4353050638


##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/WorkerHandoffHelper.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.druid.indexing.overlord;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import org.apache.druid.indexing.common.task.Task;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorManager;
+import org.apache.druid.indexing.seekablestream.SeekableStreamIndexTask;
+import org.apache.druid.java.util.common.logger.Logger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.function.Function;
+
+/**
+ * Groups streaming tasks running on one Middle Manager and queues early 
handoff
+ * through the existing supervisor notice path.
+ */
+public final class WorkerHandoffHelper
+{
+  private static final Logger LOG = new Logger(WorkerHandoffHelper.class);
+
+  private WorkerHandoffHelper()
+  {
+  }
+
+  public static Optional<ImmutableWorkerInfo> findWorker(
+      Collection<ImmutableWorkerInfo> workers,
+      String host
+  )
+  {
+    return Iterables.tryFind(
+        workers,
+        entry -> entry.getWorker().getHost().equals(host)
+    );
+  }
+
+  public static Map<String, List<Integer>> groupTaskGroups(
+      Collection<String> runningTaskIds,
+      Function<String, Optional<Task>> taskLookup
+  )
+  {
+    final Map<String, Set<Integer>> grouped = new LinkedHashMap<>();
+    for (String taskId : runningTaskIds) {
+      final Optional<Task> taskOptional = taskLookup.apply(taskId);
+      if (!taskOptional.isPresent()) {
+        continue;
+      }
+      final Task task = taskOptional.get();
+      if (!(task instanceof SeekableStreamIndexTask<?, ?, ?>)) {
+        continue;
+      }
+      final SeekableStreamIndexTask<?, ?, ?> streamTask = 
(SeekableStreamIndexTask<?, ?, ?>) task;
+      final Integer taskGroupId = streamTask.getIOConfig().getTaskGroupId();
+      if (taskGroupId == null) {

Review Comment:
   Thanks for the flag. I agree the skip of a null `taskGroupId` should be 
visible to the caller, not only in logs.
   
   `202` would still be the right status IMO, and it matches what the 
supervisor handoff endpoint returns. This endpoint only queues supervisor 
notices (pause → persist → publish happens later), same as `POST 
/druid/indexer/v1/supervisor/{id}/taskGroups/handoff`. A `200` would imply 
handoff had already finished; a `4xx`/`5xx` would fail the whole worker call 
because of one payload we cannot group.
   
   The current `202` body is the set that was queued:
   
   json
   ```
   {
     "host": "...",
     "taskGroups": {
       "<supervisorId>": [0, 2]
     }
   }
   ```
   
   That is supervisor id → task group ids, not task ids. A seekable-stream task 
with a null taskGroupId is omitted today, so a caller cannot see that we did 
not queue it.
   
   As part of the first version of this API, I will add a skipped list of 
stream task ids we did not queue (e.g. missing_taskGroupId, 
missing_supervisorId), plus a test for a null taskGroupId. That should tell the 
caller what was not queued, for example:
   
   ```
   {
     "host": "mm-0.druid.default.svc.cluster.local:8091",
     "taskGroups": {
       "wikipedia": [0, 2]
     },
     "skipped": [
       { "id": "index_kafka_legacy_abc", "reason": "missing_taskGroupId" },
       { "id": "index_kafka_manual_xyz", "reason": "missing_supervisorId" }
     ]
   }
   ```



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