Pomelongan commented on code in PR #17946:
URL: https://github.com/apache/pulsar/pull/17946#discussion_r1013094569


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -4562,6 +4564,60 @@ private CompletableFuture<Void> 
createSubscriptions(TopicName topicName, int num
         return result;
     }
 
+    /**
+     * It creates subscriptions for new partitions of existing 
partitioned-topics.
+     *
+     * @param topicName     : topic-name: persistent://prop/cluster/ns/topic
+     * @param numPartitions : number partitions for the topics
+     *
+     */
+    private CompletableFuture<Void> createMissedSubscriptionsAsync(TopicName 
topicName, List<String> subscriptions,
+                                                                   int 
numPartitions) {
+        CompletableFuture<Void> result = new CompletableFuture<>();
+        if (CollectionUtils.isEmpty(subscriptions)) {
+            result.complete(null);
+            return result;
+        }
+        PulsarAdmin admin;
+        try {
+            admin = pulsar().getAdminClient();
+        } catch (PulsarServerException ex) {
+            result.completeExceptionally(ex);
+            return result;
+        }
+
+        List<CompletableFuture<Void>> subscriptionFutures = new 
ArrayList<>(subscriptions.size());
+
+        subscriptions.forEach(subscription -> {
+            for (int i = 0; i < numPartitions; i++) {
+                CompletableFuture<Void> future = new CompletableFuture<>();
+                
admin.topics().createSubscriptionAsync(topicName.getPartition(i).toString(), 
subscription,
+                        MessageId.latest).whenComplete((__, ex) -> {
+                    if (ex == null) {
+                        future.complete(null);
+                    } else {
+                        if (ex instanceof 
PulsarAdminException.ConflictException) {
+                            future.complete(null);
+                        } else {
+                            future.completeExceptionally(ex);
+                        }
+                    }
+                });
+                subscriptionFutures.add(future);
+            }

Review Comment:
   @codelipenghui Okay~I have updated, PTAL.
   Calling `internalCreateSubscription` directly requires implementing the 
AsyncResponse interface first, which is troublesome. So I try to extract the 
common part of the two methods to avoid duplicated code. 



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

Reply via email to