lucasbru commented on code in PR #23588:
URL: https://github.com/apache/kafka/pull/23588#discussion_r4513057277


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/assignor/StickyTaskAssignor.java:
##########
@@ -468,38 +504,60 @@ private static boolean hasUnfulfilledTaskQuota(
         return process.memberToTaskCounts().get(member.memberId) < 
localState.totalTasksPerMember;
     }
 
+    /**
+     * The previous member to take a standby of {@code task}: the previous 
active member, else the least-loaded previous
+     * standby member, each only while below the quota and on a process that 
meets {@code prevMemberCondition}. Null if
+     * neither.
+     */
+    private static Member findPrevMemberForStandby(
+        final LocalState localState,
+        final TaskId task,
+        final Predicate<ProcessState> prevMemberCondition
+    ) {
+        // prev active task
+        final Member prevActiveMember = 
localState.activeTaskToPrevMember.get(task);
+        if (prevActiveMember != null) {
+            final ProcessState prevActiveMemberProcessState = 
localState.processIdToState.get(prevActiveMember.processId);
+            if (prevMemberCondition.test(prevActiveMemberProcessState) && 
!prevActiveMemberProcessState.hasTask(task) && 
hasUnfulfilledTaskQuota(localState, prevActiveMemberProcessState, 
prevActiveMember)) {
+                return prevActiveMember;
+            }
+        }
+
+        // prev standby tasks, checking the quota per member so that a full 
member does not hide one that has room

Review Comment:
   This also changes the assignment for groups without rack tags, since step 3 
goes through here with `process -> true`. If I take 
`shouldPlaceRackAwareStandbyOnPreviousStandbyMemberWithRoomWhenAnotherOneIsFull`
 and drop the tags, trunk puts task 0's standby on m1b (every member ends up 
with 2 tasks), while this PR puts it back on m2. That's stickier, but a0 then 
ends up with 3 tasks and m1b with 1.
   
   The description says the tag-free assignment is unchanged. Could you either 
mention it there and add a test without tags, or move this part into the 
follow-up you mentioned?



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/assignor/StickyTaskAssignor.java:
##########
@@ -132,13 +140,16 @@ private static LocalState initialize(final GroupSpec 
groupSpec, final TopologyDe
         localState.totalTasksPerMember = 
computeTasksPerMember(localState.totalTasks, 
localState.totalMembersWithTaskCapacity);
 
         localState.processIdToState = 
Utils.newHashMap(localState.totalMembersWithActiveTaskCapacity);
+        localState.processIdToClientTags = 
Utils.newHashMap(localState.totalMembersWithActiveTaskCapacity);
         localState.activeTaskToPrevMember = 
Utils.newHashMap(localState.totalActiveTasks);
+        localState.activeTaskToProcess = 
Utils.newHashMap(localState.totalActiveTasks);

Review Comment:
   nit: these two maps are only filled in `initializeRackAwareState` now, so 
could they be allocated there as well? Maybe also mention in the `LocalState` 
comment that they're only populated for rack-aware standby assignment.



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