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/05/30 17:16:14 UTC

[GitHub] [pulsar] AnonHxy commented on a diff in pull request #15843: fix: allow delete topic async

AnonHxy commented on code in PR #15843:
URL: https://github.com/apache/pulsar/pull/15843#discussion_r884996988


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -1003,32 +1006,36 @@ private void internalUnloadTransactionCoordinatorAsync(AsyncResponse asyncRespon
                 });
     }
 
-    protected void internalDeleteTopic(boolean authoritative, boolean force) {
+    protected void internalDeleteTopic(AsyncResponse asyncResponse, boolean authoritative, boolean force) {
         if (force) {
-            internalDeleteTopicForcefully(authoritative);
+            internalDeleteTopicForcefully(asyncResponse, authoritative);
         } else {
-            internalDeleteTopic(authoritative);
+            internalDeleteTopic(asyncResponse, authoritative);
         }
     }
 
-    protected void internalDeleteTopic(boolean authoritative) {
-        validateNamespaceOperation(topicName.getNamespaceObject(), NamespaceOperation.DELETE_TOPIC);
-        validateTopicOwnership(topicName, authoritative);
+    protected void internalDeleteTopic(AsyncResponse asyncResponse, boolean authoritative) {
 
-        try {
-            pulsar().getBrokerService().deleteTopic(topicName.toString(), false).get();
-            log.info("[{}] Successfully removed topic {}", clientAppId(), topicName);
-        } catch (Exception e) {
-            Throwable t = e.getCause();
-            log.error("[{}] Failed to delete topic {}", clientAppId(), topicName, t);
-            if (t instanceof TopicBusyException) {
-                throw new RestException(Status.PRECONDITION_FAILED, "Topic has active producers/subscriptions");
-            } else if (isManagedLedgerNotFoundException(e)) {
-                throw new RestException(Status.NOT_FOUND, getTopicNotFoundErrorMessage(topicName.toString()));
-            } else {
-                throw new RestException(t);
-            }
-        }
+        validateTopicOwnershipAsync(topicName, authoritative).thenCompose(
+                        __ -> validateNamespaceOperationAsync(topicName.getNamespaceObject(),
+                                NamespaceOperation.DELETE_TOPIC))
+                .thenAccept(__ -> pulsar().getBrokerService().deleteTopic(topicName.toString(), false))

Review Comment:
   `deleteTopic` return  `CompletableFuture<Void>`, so  we need `thenCompose` here:
   https://github.com/apache/pulsar/blob/b367b9153919b83fad829669f1f96281a2a8d8d5/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L1018-L1024



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