mjsax commented on code in PR #23790: URL: https://github.com/apache/kafka/pull/23790#discussion_r4545989071
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/assignor/RackAwareStandbyPicker.java: ########## @@ -0,0 +1,452 @@ +/* + * 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.apache.kafka.coordinator.group.Utils; + +import java.util.ArrayList; +import java.util.BitSet; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeSet; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.ToDoubleFunction; +import java.util.stream.IntStream; + +/** + * Picks the conditions for the next standby of one task: the most tag keys that a process with room can meet, + * preferring the keys earlier in {@code rack.aware.assignment.tags}. A process meets a tag key when it has a value + * for it that no holder of the task has yet. A pick also returns the least-loaded process with room that meets the + * conditions, and the picker can tell whether a process meets them. The caller reports every change to a load or room + * with {@link #updated(Object)} or {@link #updatedAll()}. + * <p> + * The processes sit in a tree with one level per tag key, those with the same values sharing a leaf. Scanning every + * leaf per standby is too slow once there are many, e.g. one per process for a host tag. Each node keeps its + * least-loaded process with room, and its children are ordered by theirs. A query skips a subtree whose own value is + * used and stops at the first child no lighter than the best process found. + * + * @param <P> The assignor's process type. + */ +final class RackAwareStandbyPicker<P> { Review Comment: In the test code I see we set the type to `String`, and yes, the `process_id` is a string. But why do we need a generic type for it? -- 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]
