jeffkbkim commented on code in PR #14182:
URL: https://github.com/apache/kafka/pull/14182#discussion_r1290813322


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/OptimizedUniformAssignor.java:
##########
@@ -0,0 +1,396 @@
+/*
+ * 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.kafka.coordinator.group.assignor;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.coordinator.group.common.TopicIdPartition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+
+import static java.lang.Math.min;
+
+/**
+ * Assigns Kafka partitions to members of a consumer group ensuring a balanced 
distribution with
+ * considerations for sticky assignments and rack-awareness.
+ *
+ * <p> Here's the step-by-step breakdown of the assignment process:
+ *
+ * <ul>
+ *     <li> Compute the quotas of partitions for each member based on the 
total partitions and member count.</li>
+ *     <li> For existing assignments, retain partitions based on the 
determined quota and member's rack compatibility.
+ *     <li> If a partition's rack mismatches with its member, track it with 
its prior owner.</li>
+ *     <li> Identify members that haven't fulfilled their partition quota or 
are eligible to receive extra partitions.</li>
+ *     <li> Derive the unassigned partitions by taking the difference between 
total partitions and the sticky assignments.</li>
+ *     <li> Depending on members needing extra partitions, select members from 
the potentially unfilled list and add them to the unfilled list.</li>
+ *     <li> Proceed with a round-robin assignment adhering to rack awareness.
+ *          For each unassigned partition, locate the first compatible member 
from the unfilled list.</li>
+ *     <li> If no rack-compatible member is found, revert to the tracked 
previous owner.
+ *          If that member can't accommodate the partition due to quota 
limits, resort to a generic round-robin assignment.</li>
+ * </ul>
+ */
+public class OptimizedUniformAssignor extends UniformAssignor {
+    private static final Logger log = 
LoggerFactory.getLogger(OptimizedUniformAssignor.class);
+    // List of topics subscribed to by all members.
+    private final List<Uuid> subscriptionList;
+    private final AssignmentSpec assignmentSpec;
+    private final SubscribedTopicDescriber subscribedTopicDescriber;
+    private final RackInfo rackInfo;
+    // The minimum required quota that each member needs to meet for a 
balanced assignment.
+    // This is the same for all members.
+    private final int minQuota;
+    // Count of members expected to receive an extra partition beyond the 
minimum quota,
+    // to account for the distribution of the remaining partitions.
+    private int expectedNumMembersWithExtraPartition;

Review Comment:
   `numMembersWithExtraPartition` : number of members to get the extra 
partition, no?
   
   there is no expected vs. actual though, we always distribute that number



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to