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


##########
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:
   [P2] Legacy stream tasks are omitted from worker handoff
   
   **Finding:** SeekableStreamIndexTaskIOConfig.getTaskGroupId() is nullable 
for backward-compatible task payloads. When such a task is running on the 
selected worker, this branch drops it while the endpoint still returns 202, so 
a subsequent worker shutdown can leave the task without an early-handoff notice.
   
   **Suggestion:** Resolve legacy task groups from supervisor state or return 
an explicit incomplete/error result so callers do not treat the worker drain as 
complete; add coverage for a null taskGroupId.



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