|
24 | 24 | import org.apache.kafka.coordinator.group.api.assignor.SubscribedTopicDescriber;
|
25 | 25 | import org.apache.kafka.coordinator.group.modern.MemberAssignmentImpl;
|
26 | 26 |
|
27 |
| -import org.slf4j.Logger; |
28 |
| -import org.slf4j.LoggerFactory; |
29 |
| - |
30 | 27 | import java.util.ArrayList;
|
31 | 28 | import java.util.Arrays;
|
32 | 29 | import java.util.Collection;
|
|
55 | 52 | * Balance > Stickiness.
|
56 | 53 | */
|
57 | 54 | public class UniformHeterogeneousAssignmentBuilder {
|
58 |
| - private static final Logger LOG = LoggerFactory.getLogger(UniformHeterogeneousAssignmentBuilder.class); |
59 | 55 |
|
60 | 56 | /**
|
61 | 57 | * The maximum number of iterations to perform in the final iterative balancing phase.
|
@@ -181,50 +177,44 @@ public UniformHeterogeneousAssignmentBuilder(GroupSpec groupSpec, SubscribedTopi
|
181 | 177 | }
|
182 | 178 | }
|
183 | 179 |
|
184 |
| - this.topicComparator = new Comparator<Uuid>() { |
185 |
| - @Override |
186 |
| - public int compare(final Uuid topic1Id, final Uuid topic2Id) { |
187 |
| - int topic1PartitionCount = subscribedTopicDescriber.numPartitions(topic1Id); |
188 |
| - int topic2PartitionCount = subscribedTopicDescriber.numPartitions(topic2Id); |
189 |
| - int topic1SubscriberCount = topicSubscribers.get(topic1Id).size(); |
190 |
| - int topic2SubscriberCount = topicSubscribers.get(topic2Id).size(); |
191 |
| - |
192 |
| - // Order by partitions per subscriber, descending. |
193 |
| - int order = Double.compare( |
194 |
| - (double) topic2PartitionCount / topic2SubscriberCount, |
195 |
| - (double) topic1PartitionCount / topic1SubscriberCount |
196 |
| - ); |
197 |
| - |
198 |
| - // Then order by subscriber count, ascending. |
199 |
| - if (order == 0) { |
200 |
| - order = Integer.compare(topic1SubscriberCount, topic2SubscriberCount); |
201 |
| - } |
202 |
| - |
203 |
| - // Then order by topic id, ascending. |
204 |
| - if (order == 0) { |
205 |
| - order = topic1Id.compareTo(topic2Id); |
206 |
| - } |
| 180 | + this.topicComparator = (topic1Id, topic2Id) -> { |
| 181 | + int topic1PartitionCount = subscribedTopicDescriber.numPartitions(topic1Id); |
| 182 | + int topic2PartitionCount = subscribedTopicDescriber.numPartitions(topic2Id); |
| 183 | + int topic1SubscriberCount = topicSubscribers.get(topic1Id).size(); |
| 184 | + int topic2SubscriberCount = topicSubscribers.get(topic2Id).size(); |
| 185 | + |
| 186 | + // Order by partitions per subscriber, descending. |
| 187 | + int order = Double.compare( |
| 188 | + (double) topic2PartitionCount / topic2SubscriberCount, |
| 189 | + (double) topic1PartitionCount / topic1SubscriberCount |
| 190 | + ); |
| 191 | + |
| 192 | + // Then order by subscriber count, ascending. |
| 193 | + if (order == 0) { |
| 194 | + order = Integer.compare(topic1SubscriberCount, topic2SubscriberCount); |
| 195 | + } |
207 | 196 |
|
208 |
| - return order; |
| 197 | + // Then order by topic id, ascending. |
| 198 | + if (order == 0) { |
| 199 | + order = topic1Id.compareTo(topic2Id); |
209 | 200 | }
|
210 |
| - }; |
211 | 201 |
|
212 |
| - this.memberComparator = new Comparator<Integer>() { |
213 |
| - @Override |
214 |
| - public int compare(final Integer memberIndex1, final Integer memberIndex2) { |
215 |
| - // Order by number of assigned partitions, ascending. |
216 |
| - int order = Integer.compare( |
217 |
| - memberTargetAssignmentSizes[memberIndex1], |
218 |
| - memberTargetAssignmentSizes[memberIndex2] |
219 |
| - ); |
| 202 | + return order; |
| 203 | + }; |
220 | 204 |
|
221 |
| - // Then order by member index, ascending. |
222 |
| - if (order == 0) { |
223 |
| - order = memberIndex1.compareTo(memberIndex2); |
224 |
| - } |
| 205 | + this.memberComparator = (memberIndex1, memberIndex2) -> { |
| 206 | + // Order by number of assigned partitions, ascending. |
| 207 | + int order = Integer.compare( |
| 208 | + memberTargetAssignmentSizes[memberIndex1], |
| 209 | + memberTargetAssignmentSizes[memberIndex2] |
| 210 | + ); |
225 | 211 |
|
226 |
| - return order; |
| 212 | + // Then order by member index, ascending. |
| 213 | + if (order == 0) { |
| 214 | + order = memberIndex1.compareTo(memberIndex2); |
227 | 215 | }
|
| 216 | + |
| 217 | + return order; |
228 | 218 | };
|
229 | 219 |
|
230 | 220 | // Initialize partition owners for the target assignments.
|
@@ -851,14 +841,6 @@ private void assignPartition(Uuid topicId, int partition, int memberIndex) {
|
851 | 841 | addPartitionToTargetAssignment(topicId, partition, memberIndex);
|
852 | 842 | }
|
853 | 843 |
|
854 |
| - /** |
855 |
| - * @param memberIndex The member index. |
856 |
| - * @return The current assignment size for the given member. |
857 |
| - */ |
858 |
| - private int targetAssignmentSize(int memberIndex) { |
859 |
| - return memberTargetAssignmentSizes[memberIndex]; |
860 |
| - } |
861 |
| - |
862 | 844 | /**
|
863 | 845 | * Assigns a partition to a member and updates the current assignment size.
|
864 | 846 | *
|
|
0 commit comments