squah-confluent commented on code in PR #23733: URL: https://github.com/apache/kafka/pull/23733#discussion_r4273672430
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/uniform2/AssignRemainingExtraPartitions.java: ########## @@ -0,0 +1,265 @@ +/* + * 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.uniform2; + +import org.apache.kafka.coordinator.group.assignor.uniform2.util.IntPair; +import org.apache.kafka.coordinator.group.assignor.uniform2.util.LongHeap; + +import java.util.Arrays; + +/** + * The second step deciding the {@link Quotas}: assigns the extra partitions that no owner kept, + * one at a time, to subscribers not having one of the topic yet, among the ones with the smallest + * assignments. + * + * <p>The topics with the fewest subscribers go first, so that they get the smallest of their few + * candidates: when the subscriptions are nested, this alone balances the assignment sizes. The + * extra partition goes to the cohort holding the smallest assignment, and among its members those + * with the smallest assignment are served round robin in member order. The member with the + * smallest assignment may already have an extra partition of the topic, and another member of the + * cohort then gets it: the balance step moves it if it has to. Without owners, a homogeneous group + * is served round robin. + * + * <p>On exit every topic has exactly its number of extra partitions, on distinct subscribers. + */ +final class AssignRemainingExtraPartitions { + /** + * The state of a cohort while the extra partitions are handed out. + */ + private static final class CohortState { + /** + * The members of the cohort. + */ + final int[] members; + + /** + * The position in the members of the next member to serve, round robin. + */ + int cursor; + + /** + * The lowest number of extra partitions of the members. + */ + int lowest; + + /** + * How many members have the lowest number of extra partitions. + */ + int atLowest; + + /** + * How many members have an extra partition of the topic being handed out. + */ + int holders; + + CohortState(int[] members) { + this.members = members; + } + } + + /** + * The members and topics of the group. + */ + private final IndexedGroup group; + + /** + * The quotas, which the step completes. + */ + private final Quotas quotas; + + /** + * The cohorts of the topic being handed out which can still take an extra partition of it, by + * increasing smallest assignment size among their members, whether that member has an extra + * partition of the topic or not, then in cohort order, see {@link #sizeAndCohort(int)}. + */ + private LongHeap candidates; Review Comment: Sounds good to me -- 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]
