poorbarcode commented on code in PR #24730: URL: https://github.com/apache/pulsar/pull/24730#discussion_r2343411712
########## pulsar-broker/src/main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java: ########## @@ -73,47 +74,41 @@ private synchronized Optional<ImpactedConsumersResult> internalAddConsumer(Consu + conflictingConsumer); } for (IntRange intRange : consumer.getKeySharedMeta().getHashRangesList()) { - rangeMap.put(intRange.getStart(), consumer); - rangeMap.put(intRange.getEnd(), consumer); + rangeMap.put(intRange.getStart(), Pair.of(Range.of(intRange.getStart(), intRange.getEnd()), consumer)); } return Optional.empty(); } @Override public synchronized Optional<ImpactedConsumersResult> removeConsumer(Consumer consumer) { - rangeMap.entrySet().removeIf(entry -> entry.getValue().equals(consumer)); + rangeMap.entrySet().removeIf(entry -> entry.getValue().getRight().equals(consumer)); return Optional.empty(); } @Override public synchronized ConsumerHashAssignmentsSnapshot getConsumerHashAssignmentsSnapshot() { List<HashRangeAssignment> result = new ArrayList<>(); - Map.Entry<Integer, Consumer> prev = null; - for (Map.Entry<Integer, Consumer> entry: rangeMap.entrySet()) { - if (prev == null) { - prev = entry; - } else { - if (prev.getValue().equals(entry.getValue())) { - result.add(new HashRangeAssignment(Range.of(prev.getKey(), entry.getKey()), entry.getValue())); - } - prev = null; - } + for (Map.Entry<Integer, Pair<Range, Consumer>> entry : rangeMap.entrySet()) { + Range assignedRange = entry.getValue().getLeft(); + Consumer assignedConsumer = entry.getValue().getRight(); + result.add(new HashRangeAssignment(assignedRange, assignedConsumer)); Review Comment: I am thinking that maybe we can cache the `hash range assignments` after adding or removing consumers, which may help for GC(to avoid re-creating objects typed `HashRangeAssignment `) -- 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: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org