lhotari commented on code in PR #22854:
URL: https://github.com/apache/pulsar/pull/22854#discussion_r1628923187


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MultiTopicsConsumerImpl.java:
##########
@@ -1067,30 +1074,43 @@ private void doSubscribeTopicPartitions(Schema<T> 
schema,
             ConsumerConfigurationData<T> configurationData = 
getInternalConsumerConfig();
             configurationData.setReceiverQueueSize(receiverQueueSize);
 
-            futureList = IntStream
-                .range(0, numPartitions)
-                .mapToObj(
-                    partitionIndex -> {
-                        String partitionName = 
TopicName.get(topicName).getPartition(partitionIndex).toString();
-                        CompletableFuture<Consumer<T>> subFuture = new 
CompletableFuture<>();
-                        configurationData.setStartPaused(paused);
-                        ConsumerImpl<T> newConsumer = 
createInternalConsumer(configurationData, partitionName,
-                                partitionIndex, subFuture, 
createIfDoesNotExist, schema);
-                        synchronized (pauseMutex) {
-                            if (paused) {
-                                newConsumer.pause();
-                            } else {
-                                newConsumer.resume();
-                            }
-                            consumers.putIfAbsent(newConsumer.getTopic(), 
newConsumer);
+            CompletableFuture<List<Integer>> partitionsFuture;
+            if (createIfDoesNotExist || 
!TopicName.get(topicName).isPersistent()) {
+                partitionsFuture = 
CompletableFuture.completedFuture(IntStream.range(0, numPartitions)
+                        .mapToObj(i -> Integer.valueOf(i))
+                        .collect(Collectors.toList()));
+            } else {
+                partitionsFuture = getExistsPartitions(topicName.toString());
+            }
+            subscribeAllPartitionsFuture = 
partitionsFuture.thenCompose(partitions -> {
+                if (partitions.isEmpty()) {
+                    partitionedTopics.remove(topicName, numPartitions);
+                    return CompletableFuture.completedFuture(null);
+                }
+                List<CompletableFuture<Consumer<T>>> subscribeList = new 
ArrayList<>();
+                for (int partitionIndex : partitions) {
+                    String partitionName = 
TopicName.get(topicName).getPartition(partitionIndex).toString();
+                    CompletableFuture<Consumer<T>> subFuture = new 
CompletableFuture<>();
+                    configurationData.setStartPaused(paused);
+                    ConsumerImpl<T> newConsumer = 
createInternalConsumer(configurationData, partitionName,
+                            partitionIndex, subFuture, createIfDoesNotExist, 
schema);
+                    synchronized (pauseMutex) {
+                        if (paused) {
+                            newConsumer.pause();
+                        } else {
+                            newConsumer.resume();
                         }
-                        return subFuture;
-                    })
-                .collect(Collectors.toList());
+                        consumers.putIfAbsent(newConsumer.getTopic(), 
newConsumer);

Review Comment:
   What if there's an existing entry for the key? does the `newConsumer` have 
to be closed in that case?



-- 
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

Reply via email to