You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/01 00:09:25 UTC

[GitHub] [pulsar] mattisonchao commented on a change in pull request #14469: [Broker] Fix ``Future.join()`` causing deadlock.

mattisonchao commented on a change in pull request #14469:
URL: https://github.com/apache/pulsar/pull/14469#discussion_r816348536



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
##########
@@ -2256,44 +2256,52 @@ public void checkGC() {
             return CompletableFuture.completedFuture(null);
         }
         TopicName topicName = TopicName.get(TopicName.get(topic).getPartitionedTopicName());
-        try {
-            PartitionedTopicResources partitionedTopicResources = getBrokerService().pulsar().getPulsarResources()
-                    .getNamespaceResources()
-                    .getPartitionedTopicResources();
-            if (topicName.isPartitioned() && !partitionedTopicResources.partitionedTopicExists(topicName)) {
-                return CompletableFuture.completedFuture(null);
-            }
-            CompletableFuture<Void> deleteMetadataFuture = new CompletableFuture<>();
-            getBrokerService().fetchPartitionedTopicMetadataAsync(TopicName.get(topicName.getPartitionedTopicName()))
-                    .thenAccept((metadata -> {
-                        // make sure all sub partitions were deleted
-                        for (int i = 0; i < metadata.partitions; i++) {
-                            if (brokerService.getPulsar().getPulsarResources().getTopicResources()
-                                    .persistentTopicExists(topicName.getPartition(i)).join()) {
-                                throw new UnsupportedOperationException();
-                            }
-                        }
-                    }))
-                    .thenAccept((res) -> partitionedTopicResources.deletePartitionedTopicAsync(topicName)
-                            .thenAccept((r) -> {
-                        deleteMetadataFuture.complete(null);
-                    }).exceptionally(ex -> {
-                        deleteMetadataFuture.completeExceptionally(ex.getCause());
-                        return null;
-                    }))
-                    .exceptionally((e) -> {
-                        if (!(e.getCause() instanceof UnsupportedOperationException)) {
-                            log.error("delete metadata fail", e);
+        PartitionedTopicResources partitionedTopicResources = getBrokerService().pulsar().getPulsarResources()
+                .getNamespaceResources()
+                .getPartitionedTopicResources();
+        if (topicName.isPartitioned()) {
+            return partitionedTopicResources.partitionedTopicExistsAsync(topicName)
+                    .thenCompose(partitionedTopicExist -> {
+                        if (!partitionedTopicExist) {
+                            return CompletableFuture.completedFuture(null);
+                        } else {
+                            return innerDeletePartitionedMetadata(topicName, partitionedTopicResources);
                         }
-                        deleteMetadataFuture.complete(null);
-                        return null;
                     });
-            return deleteMetadataFuture;
-        } catch (Exception e) {
-            return FutureUtil.failedFuture(e);
+        } else {
+            return innerDeletePartitionedMetadata(topicName, partitionedTopicResources);
         }
     }
 
+    private CompletableFuture<Void> innerDeletePartitionedMetadata(TopicName topicName,
+                                                                   PartitionedTopicResources partitionedTopicResources)
+    {
+        return getBrokerService()
+                .fetchPartitionedTopicMetadataAsync(TopicName.get(topicName.getPartitionedTopicName()))
+                .thenCompose((metadata -> {
+                    List<CompletableFuture<Boolean>> persistentTopicExists = new ArrayList<>(metadata.partitions);

Review comment:
       @michaeljmarshall 
   Sorry, I missed this comment here.
   Very thanks for you.




-- 
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-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org