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


##########
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:
   We have `internalCreateSubscription` method which will handle the 
subscription creation. Can we just use the existing method 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