poorbarcode commented on code in PR #22245: URL: https://github.com/apache/pulsar/pull/22245#discussion_r1543965530
########## pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java: ########## @@ -472,18 +475,18 @@ protected NavigableSet<PositionImpl> filterOutEntriesWillBeDiscarded(NavigableSe // Maybe using HashRangeExclusiveStickyKeyConsumerSelector. continue; } - if (getAvailablePermits(c) == 0) { + groupedPositions.computeIfAbsent(c, k -> new ArrayList<>()).add(pos); + } + // Filter positions by the Recently Joined Position rule. + for (Map.Entry<Consumer, List<PositionImpl>> item : groupedPositions.entrySet()) { + int availablePermits = getAvailablePermits(item.getKey()); + if (availablePermits == 0) { continue; } - PositionImpl currentMaxReadPosition = recentlyJoinedConsumers.get(c); - if (currentMaxReadPosition == null) { - res.add(pos); - } else if (pos.compareTo(firstMaxReadPos) < 0 && pos.compareTo(currentMaxReadPosition) < 0) { - res.add(pos); - } else { - // The subsequent positions will also be larger than "firstMaxReadPos", why need to check continuous. - // Because the subsequent positions may be delivered to a consumer which does not in the - // "recentlyJoinedConsumers". + int posCountToRead = getRestrictedMaxEntriesForConsumer(item.getKey(), item.getValue(), availablePermits, + ReadType.Replay, null); + for (int i = 0; i < posCountToRead; i++) { + res.add(item.getValue().get(i)); Review Comment: Done -- 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