ltamber commented on a change in pull request #6187: [Issue 5904]Support 
`unload` all partitions of a partitioned topic
URL: https://github.com/apache/pulsar/pull/6187#discussion_r374049792
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
 ##########
 @@ -655,12 +655,65 @@ protected void 
internalDeletePartitionedTopic(AsyncResponse asyncResponse, boole
         });
     }
 
-    protected void internalUnloadTopic(boolean authoritative) {
+//    protected void internalUnloadTopic(boolean authoritative) {
+//        log.info("[{}] Unloading topic {}", clientAppId(), topicName);
+//        if (topicName.isGlobal()) {
+//            validateGlobalNamespaceOwnership(namespaceName);
+//        }
+//        unloadTopic(topicName, authoritative);
+//    }
+
+    protected void internalUnloadTopic(AsyncResponse asyncResponse, boolean 
authoritative) {
         log.info("[{}] Unloading topic {}", clientAppId(), topicName);
         if (topicName.isGlobal()) {
             validateGlobalNamespaceOwnership(namespaceName);
         }
-        unloadTopic(topicName, authoritative);
+
+        PartitionedTopicMetadata partitionMetadata = 
getPartitionedTopicMetadata(topicName, authoritative, false);
+        if (partitionMetadata.partitions > 0) {
+            final List<CompletableFuture<Void>> futures = Lists.newArrayList();
+
+            for (int i = 0; i < partitionMetadata.partitions; i++) {
+                TopicName topicNamePartition = topicName.getPartition(i);
+                try {
+                    
futures.add(pulsar().getAdminClient().topics().unloadAsync(topicNamePartition.toString()));
+                } catch (Exception e) {
+                    log.error("[{}] Failed to unload topic {}", clientAppId(), 
topicNamePartition, e);
+                    asyncResponse.resume(new RestException(e));
+                    return;
+                }
+            }
+
+            FutureUtil.waitForAll(futures).handle((result, exception) -> {
+                if (exception != null) {
+                    Throwable t = exception.getCause();
+                    if (t instanceof NotFoundException) {
+                        asyncResponse.resume(new 
RestException(Status.NOT_FOUND, t.getMessage()));
+                        return null;
+                    } else {
+                        log.error("[{}] Failed to unload topic {}", 
clientAppId(), topicName, exception);
+                        asyncResponse.resume(new RestException(exception));
+                        return null;
+                    }
+                }
+
+                asyncResponse.resume(Response.noContent().build());
+                return null;
+            });
+        } else {
+            validateSuperUserAccess();
 
 Review comment:
   ok

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to