jolshan commented on code in PR #13637: URL: https://github.com/apache/kafka/pull/13637#discussion_r1179440573
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/consumer/TargetAssignmentBuilder.java: ########## @@ -0,0 +1,327 @@ +/* + * 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.consumer; + +import org.apache.kafka.common.Uuid; +import org.apache.kafka.coordinator.group.Record; +import org.apache.kafka.coordinator.group.assignor.AssignmentMemberSpec; +import org.apache.kafka.coordinator.group.assignor.AssignmentSpec; +import org.apache.kafka.coordinator.group.assignor.AssignmentTopicMetadata; +import org.apache.kafka.coordinator.group.assignor.GroupAssignment; +import org.apache.kafka.coordinator.group.assignor.MemberAssignment; +import org.apache.kafka.coordinator.group.assignor.PartitionAssignor; +import org.apache.kafka.coordinator.group.assignor.PartitionAssignorException; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import static org.apache.kafka.coordinator.group.RecordHelpers.newTargetAssignmentEpochRecord; +import static org.apache.kafka.coordinator.group.RecordHelpers.newTargetAssignmentRecord; + +/** + * Build a new Target Assignment based on the provided parameters. As a result, + * it yields the records that must be persisted to the log and the new member + * assignments as a map. + * + * Records are only created for members which have a new target assignment. If + * their assignment did not change, no new record is needed. + * + * When a member is deleted, it is assumed that its target assignment record + * is deleted as part of the member deletion process. In other words, this class + * does not yield a tombstone for removed members. + */ +public class TargetAssignmentBuilder { + /** + * The assignment result returned by {{@link TargetAssignmentBuilder#build()}}. + */ + public static class TargetAssignmentResult { + /** + * The records that must be applied to the __consumer_offsets + * topics to persist the new target assignment. + */ + private final List<Record> records; + + /** + * The new target assignment for all members. + */ + private final Map<String, Assignment> assignments; + + TargetAssignmentResult( + List<org.apache.kafka.coordinator.group.Record> records, + Map<String, Assignment> assignments + ) { + Objects.requireNonNull(records); + Objects.requireNonNull(assignments); + this.records = records; + this.assignments = assignments; + } + + /** + * @return The records. + */ + public List<Record> records() { + return records; + } + + /** + * @return The assignments. + */ + public Map<String, Assignment> assignments() { + return assignments; + } + } + + /** + * The group id. + */ + private final String groupId; + + /** + * The group epoch. + */ + private final int groupEpoch; + + /** + * The partition assignor used to compute the assignment. + */ + private final PartitionAssignor assignor; + + /** + * The members in the group. + */ + private Map<String, ConsumerGroupMember> members = Collections.emptyMap(); + + /** + * The subscription metadata. + */ + private Map<String, TopicMetadata> subscriptionMetadata = Collections.emptyMap(); + + /** + * The current target assignment. + */ + private Map<String, Assignment> assignments = Collections.emptyMap(); Review Comment: I think Jeff already touched this, but there is a small amount of confusion with this name (ie, between this and the result's assignment field). It could be useful to use the same phrasing in the comments (ie, current vs. existing) -- 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