TakaHiro0208 commented on code in PR #15217:
URL: https://github.com/apache/pulsar/pull/15217#discussion_r853017089


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -4052,7 +4052,26 @@ private CompletableFuture<Void> 
updatePartitionedTopic(TopicName topicName, int
             return future;
         }).thenAccept(__ -> result.complete(null)).exceptionally(ex -> {
             if (force && ex.getCause() instanceof 
PulsarAdminException.ConflictException) {
-                result.complete(null);
+                CompletableFuture<Void> future = 
namespaceResources().getPartitionedTopicResources()
+                        .updatePartitionedTopicAsync(topicName, p -> new 
PartitionedTopicMetadata(numPartitions));
+                future.thenAccept(__ -> 
result.complete(null)).exceptionally(ex2 -> {
+                    // If the update operation fails, clean up the partitions 
that were created
+                    getPartitionedTopicMetadataAsync(topicName, false, 
false).thenAccept(metadata -> {
+                        int oldPartition = metadata.partitions;
+                        for (int i = oldPartition; i < numPartitions; i++) {
+                            
topicResources().deletePersistentTopicAsync(topicName.getPartition(i)).exceptionally(ex1
 -> {
+                                log.warn("[{}] Failed to clean up 
managedLedger {}", clientAppId(), topicName,
+                                        ex1.getCause());
+                                return null;
+                            });
+                        }
+                    }).exceptionally(e -> {
+                        log.warn("[{}] Failed to clean up managedLedger", 
topicName, e);
+                        return null;
+                    });
+                    result.completeExceptionally(ex2);
+                    return null;
+                });

Review Comment:
   I think it do not handle since the code between 4033-4035 also delegate the 
exception. And I think I can help refactor this method. 



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