lhotari commented on code in PR #23795:
URL: https://github.com/apache/pulsar/pull/23795#discussion_r1900051298
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumersClassic.java:
##########
@@ -146,11 +146,43 @@ public synchronized CompletableFuture<Void>
addConsumer(Consumer consumer) {
&& consumerList.size() > 1
&&
cursor.getNumberOfEntriesSinceFirstNotAckedMessage() > 1) {
recentlyJoinedConsumers.put(consumer,
readPositionWhenJoining);
+ sortRecentlyJoinedConsumersIfNeeded();
}
}
});
}
+ private void sortRecentlyJoinedConsumersIfNeeded() {
+ if (recentlyJoinedConsumers.size() == 1) {
+ return;
+ }
+ boolean sortNeeded = false;
+ Position posPre = null;
+ Position posAfter = null;
+ for (Map.Entry<Consumer, Position> entry :
recentlyJoinedConsumers.entrySet()) {
+ if (posPre == null) {
+ posPre = entry.getValue();
+ } else {
+ posAfter = entry.getValue();
+ }
+ if (posPre != null && posAfter != null) {
+ if (posPre.compareTo(posAfter) > 0) {
+ sortNeeded = true;
+ break;
+ }
+ }
+ }
Review Comment:
what is the purpose of `posPre` and `posAfter`? It seems that `posPre` is
never updated.
Is this logic correct?
--
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]