poorbarcode commented on code in PR #23795:
URL: https://github.com/apache/pulsar/pull/23795#discussion_r1901421451
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumersClassic.java:
##########
@@ -560,8 +593,11 @@ public boolean hasSameKeySharedPolicy(KeySharedMeta ksm) {
&& ksm.isAllowOutOfOrderDelivery() ==
this.allowOutOfOrderDelivery);
}
- public LinkedHashMap<Consumer, Position> getRecentlyJoinedConsumers() {
- return recentlyJoinedConsumers;
+ public synchronized LinkedHashMap<Consumer, Position>
getRecentlyJoinedConsumers() {
+ if (recentlyJoinedConsumers == null) {
+ return null;
+ }
+ return new LinkedHashMap<>(recentlyJoinedConsumers);
Review Comment:
> We should return a unmodified map instead of a new copy of the map?
No, the thread that gets the unmodified map may encounter a
`ConcurrentModificationException`, see following case:
- `thread-1`: get an unmodified map
- call `map.foreach`
- `thread-2`: get the lock and remove an item from the map.
- `thread-1` will get a `ConcurrentModificationException` because its
`foreach` is in progress
--
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]