pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] lovelle commented on a change in pull request #963: Partitioned Consumer UnAckedMessageTracker
Date Thu, 01 Jan 1970 00:00:00 GMT
lovelle commented on a change in pull request #963: Partitioned Consumer UnAckedMessageTracker
URL: https://github.com/apache/incubator-pulsar/pull/963#discussion_r156956190
 
 

 ##########
 File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/PartitionedConsumerImpl.java
 ##########
 @@ -418,23 +449,23 @@ private ConsumerConfiguration getInternalConsumerConfig() {
 
     @Override
     public void redeliverUnacknowledgedMessages() {
-        for (ConsumerImpl c : consumers) {
-            c.redeliverUnacknowledgedMessages();
+        synchronized (this) {
+            incomingMessages.clear();
+            unAckedMessageTracker.clear();
+            for (ConsumerImpl c : consumers) {
+                c.redeliverUnacknowledgedMessages();
+            }
         }
+
     }
 
     @Override
     public void redeliverUnacknowledgedMessages(Set<MessageIdImpl> messageIds) {
+        removeExpiredMessagesFromQueue(messageIds);
+        Map<Integer, Set<MessageIdImpl>> setMap = messageIds.stream()
+                .collect(Collectors.groupingBy(MessageIdImpl::getPartitionIndex, Collectors.toSet()));
         for (ConsumerImpl c : consumers) {
-            Set<MessageIdImpl> consumerMessageIds = new HashSet<>();
-            messageIds.removeIf(messageId -> {
-                if (messageId.getPartitionIndex() == c.getPartitionIndex()) {
-                    consumerMessageIds.add(messageId);
-                    return true;
-                }
-                return false;
-            });
-            c.redeliverUnacknowledgedMessages(consumerMessageIds);
+            c.redeliverUnacknowledgedMessages(setMap.get(c.getPartitionIndex()));
 
 Review comment:
   I believe that these code could lead to a bug.
   
   setMap might not have expired messages for all partitions, therefore `setMap.get(c.getPartitionIndex()))`
is going to be `null` generating some possible `NullPointerException` on `redeliverUnacknowledgedMessages`
method.
   I imagine two possible solutions:
   1. instead of using `.get` use `.getOrDefault` checking if default was obtained before
calling `redeliverUnacknowledgedMessages` method.
   2. Just check if setMap has proper partition index.
   ```java
   int cPartitionIdx = c.getPartitionIndex();
   if (setMap.containsKey(cPartitionIdx)) {
       c.redeliverUnacknowledgedMessages(setMap.get(cPartitionIdx));
   }
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message