gabriellefu commented on code in PR #23924:
URL: https://github.com/apache/kafka/pull/23924#discussion_r4568832579
##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/assignor/BalancedTaskAssignor.java:
##########
@@ -373,29 +447,143 @@ private static Map<String, Set<Integer>>
toCompactedTaskIds(final Set<TaskId> ta
return ret;
}
+ /**
+ * The per-member quota on active plus standby tasks: the tasks left over
the members left, rounded up, where a
+ * member that reaches it leaves with its tasks. The members of a process
are levelled once the placement is final,
+ * so the member that takes the n-th task of a process with c members
reaches ceil(n / c).
+ */
+ private static final class TaskQuota {
+ private int totalMembersWithTaskCapacity;
+ private long totalTasks;
+ private int totalTasksPerMember;
+
+ /**
+ * @param standbysToPlace The standbys still to place; the tasks the
processes hold count as placed one by one.
+ */
+ private TaskQuota(final Collection<ProcessTasks> processes, final long
standbysToPlace) {
+ totalTasks = standbysToPlace;
+ for (final ProcessTasks process : processes) {
+ totalMembersWithTaskCapacity += process.capacity();
+ totalTasks += process.assignedTaskCount();
+ }
+ totalTasksPerMember = computeTasksPerMember(totalTasks,
totalMembersWithTaskCapacity);
+ for (final ProcessTasks process : processes) {
+ for (int taskCount = 1; taskCount <=
process.assignedTaskCount(); taskCount++) {
+ maybeUpdateTotalTasksPerMember(memberTaskCount(taskCount,
process.capacity()));
+ }
+ }
+ }
+
+ /** Whether one of the members of the process is below the quota. */
+ private boolean hasRoom(final ProcessTasks process) {
+ return process.assignedTaskCount() < (long) process.capacity() *
totalTasksPerMember;
+ }
+
+ private void maybeUpdateTotalTasksPerMember(final int taskNo) {
+ if (taskNo == totalTasksPerMember) {
+ totalMembersWithTaskCapacity--;
+ totalTasks -= taskNo;
+ totalTasksPerMember = computeTasksPerMember(totalTasks,
totalMembersWithTaskCapacity);
+ }
+ }
+
+ private static int computeTasksPerMember(final long numberOfTasks,
final int numberOfMembers) {
+ return numberOfMembers == 0 ? 0 : (int) ((numberOfTasks +
numberOfMembers - 1) / numberOfMembers);
+ }
+
+ /** The task count of the member that takes the {@code
processTaskCount}-th task of a levelled process. */
+ private static int memberTaskCount(final int processTaskCount, final
int capacity) {
+ return (processTaskCount + capacity - 1) / capacity;
+ }
+ }
+
+ /**
+ * The processes holding each stateful task, to tell whether moving a
standby lowers the rack diversity of its task:
Review Comment:
i have updated it, so for each task, if one of its replica go to a
least-loaded member, but the rack diversity decrease, this move will be
prohibited. two diversities are compared lexicographically in
rack.aware.assignment.tags order
--
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]