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


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/AbstractUniformAssignor.java:
##########
@@ -0,0 +1,220 @@
+/*
+ * 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.coordinator.group.common.TopicIdPartition;
+import org.apache.kafka.common.Uuid;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * The Uniform Assignor distributes Kafka topic partitions among group members 
for balanced assignment.
+ * The assignor employs two different strategies based on the nature of topic
+ * subscriptions across the group members:
+ * <ul>
+ *     <li>
+ *         <b> Optimized Uniform Assignor: </b> This strategy is used when all 
members have subscribed
+ *         to the same set of topics.
+ *     </li>
+ *     <li>
+ *         <b> General Uniform Assignor: </b> This strategy is used when 
members have varied topic
+ *         subscriptions.
+ *     </li>
+ * </ul>
+ *
+ * The appropriate strategy is automatically chosen based on the current 
members' topic subscriptions.
+ *
+ * @see OptimizedUniformAssignor
+ * @see GeneralUniformAssignor
+ */
+public abstract class AbstractUniformAssignor implements PartitionAssignor {
+    private static final Logger log = 
LoggerFactory.getLogger(AbstractUniformAssignor.class);
+    public static final String UNIFORM_ASSIGNOR_NAME = "uniform";
+
+    @Override
+    public String name() {
+        return UNIFORM_ASSIGNOR_NAME;
+    }
+
+    /**
+     * Perform the group assignment given the current members and
+     * topic metadata.
+     *
+     * @param assignmentSpec           The member assignment spec.
+     * @param subscribedTopicDescriber The topic and cluster metadata 
describer {@link SubscribedTopicDescriber}.
+     * @return The new assignment for the group.
+     */
+    @Override
+    public GroupAssignment assign(AssignmentSpec assignmentSpec, 
SubscribedTopicDescriber subscribedTopicDescriber) throws 
PartitionAssignorException {
+        if (allSubscriptionsEqual(assignmentSpec.members())) {
+            log.debug("Detected that all members are subscribed to the same 
set of topics, invoking the "
+                + "optimized assignment algorithm");
+            OptimizedUniformAssignor optimizedUniformAssignor = new 
OptimizedUniformAssignor(assignmentSpec, subscribedTopicDescriber);
+            return optimizedUniformAssignor.build();
+        } else {
+            GeneralUniformAssignor generalUniformAssignor = new 
GeneralUniformAssignor();
+            log.debug("Detected that all members are subscribed to a different 
set of topics, invoking the "
+                + "general assignment algorithm");
+            return generalUniformAssignor.build();
+        }
+    }
+
+    /**
+     * Builds the assignment for the given topic and member metadata.
+     *
+     * @return The new assignment for the group.
+     */
+    protected abstract GroupAssignment build();

Review Comment:
   AssignorBuilder.build() makes sense. Assignor.build() implies that we're 
building an assignor, not building an 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: jira-unsubscr...@kafka.apache.org

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

Reply via email to