mjsax commented on code in PR #23924:
URL: https://github.com/apache/kafka/pull/23924#discussion_r4560581814


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/assignor/BalancedTaskAssignor.java:
##########
@@ -273,7 +283,63 @@ private static void assignStandbyReplicaTasks(final 
Collection<ProcessTasks> pro
                 tasksShortOfReplicas, statefulTasks.size(), 
numStandbyReplicas, missingReplicas, processes.size());
         }
 
-        balanceTasksOverProcesses(processes, process -> process.standbyTasks);
+        balanceTasksOverProcesses(
+            processes,
+            process -> process.standbyTasks,
+            rackAwareAssignmentTags.isEmpty() ? null : new 
RackDiversity(processes, statefulTasks.size(), rackAwareAssignmentTags)
+        );
+    }
+
+    /**
+     * Places the standby tasks that make their task more rack-diverse, each 
on the least loaded process among the
+     * most diverse ones, and returns the number placed per task. A process 
takes them while one of its members is
+     * below the per-member task quota.
+     */
+    private static Map<TaskId, Integer> assignRackAwareStandbys(final 
Collection<ProcessTasks> processes,
+                                                               final 
SortedSet<TaskId> statefulTasks,
+                                                               final int 
numStandbyReplicas,
+                                                               final 
List<String> rackAwareAssignmentTags) {
+        final Map<TaskId, ProcessTasks> activeTaskToProcess = 
Utils.newHashMap(statefulTasks.size());
+        for (final ProcessTasks process : processes) {
+            for (final TaskId task : process.statefulActiveTasks) {
+                activeTaskToProcess.put(task, process);
+            }
+        }
+
+        final TaskQuota quota = new TaskQuota(processes, (long) 
statefulTasks.size() * numStandbyReplicas);
+        // The processes are in sorted order of their ID, so a load tie goes 
to the smaller ID, as in BY_ASSIGNED_LOAD.
+        final RackAwareStandbyPicker<ProcessTasks> picker = new 
RackAwareStandbyPicker<>(
+            rackAwareAssignmentTags,
+            processes,
+            process -> process.clientTags,
+            ProcessTasks::assignedTaskLoad,
+            quota::hasRoom
+        );
+        final Map<TaskId, Integer> rackAwareStandbys = 
Utils.newHashMap(statefulTasks.size());
+        for (final TaskId task : statefulTasks) {
+            picker.startTask(List.of(activeTaskToProcess.get(task)));
+            int placed = 0;
+            while (placed < numStandbyReplicas) {

Review Comment:
   Similar question as for the "sticky" case -- would it make sense to flip the 
nested-loop from:
   ```
   for each task
     for R replicas
       assign standby
   ```
   to
   ```
   for R replicas
     for each task
       assign standby
   ```



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

Reply via email to