aliehsaeedii commented on code in PR #18652: URL: https://github.com/apache/kafka/pull/18652#discussion_r1936919748
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/assignor/StickyTaskAssignor.java: ########## @@ -0,0 +1,440 @@ +/* + * 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.streams.assignor; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +public class StickyTaskAssignor implements TaskAssignor { + + private static final String STICKY_ASSIGNOR_NAME = "sticky"; + private static final Logger log = LoggerFactory.getLogger(StickyTaskAssignor.class); + + // helper data structures: + private TaskPairs taskPairs; + Map<TaskId, Member> activeTaskToPrevMember; + Map<TaskId, Set<Member>> standbyTaskToPrevMember; + Map<String, ProcessState> processIdToState; + + int allTasks; + int totalCapacity; + int tasksPerMember; + + @Override + public String name() { + return STICKY_ASSIGNOR_NAME; + } + + @Override + public GroupAssignment assign(final GroupSpec groupSpec, final TopologyDescriber topologyDescriber) throws TaskAssignorException { + initialize(groupSpec, topologyDescriber); + GroupAssignment assignments = doAssign(groupSpec, topologyDescriber); + terminate(); + return assignments; + } + + private GroupAssignment doAssign(final GroupSpec groupSpec, final TopologyDescriber topologyDescriber) { + //active + Set<TaskId> activeTasks = taskIds(topologyDescriber, true); + assignActive(activeTasks); + + //standby + final int numStandbyReplicas = + groupSpec.assignmentConfigs().isEmpty() ? 0 + : Integer.parseInt(groupSpec.assignmentConfigs().get("num.standby.replicas")); + if (numStandbyReplicas > 0) { + Set<TaskId> statefulTasks = taskIds(topologyDescriber, false); + assignStandby(statefulTasks, numStandbyReplicas); + } + + return buildGroupAssignment(groupSpec.members().keySet()); + } + + private void terminate() { + taskPairs = null; + activeTaskToPrevMember = null; + standbyTaskToPrevMember = null; + processIdToState = null; Review Comment: >You are not resetting the integer fields here. We did not set them in the first place as well. They are initialized in `initialize` method. I agree with defining the `LocalState` class and making it `null` after computing the assignment, but I disagree with passing a parameter to a method and then manipulating that. In other words, I think following the code is a bit hard when the output of a method is at the same time its input. WDYT? Bill was also in the side of fieldless class. If you think, this is better, please do it yourself. You can suggest it here in this PR and I accept the suggestion. -- 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