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 2020/02/04 19:33:48 UTC
[GitHub] [pulsar] sijie commented on a change in pull request #6187: [Issue
5904]Support `unload` all partitions of a partitioned topic
sijie 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_r374878779
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -655,12 +655,56 @@ protected void internalDeletePartitionedTopic(AsyncResponse asyncResponse, boole
});
}
- protected void internalUnloadTopic(boolean 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()));
+ } 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 {
+ validateAdminAccessForTenant(topicName.getTenant());
+ validateTopicOwnership(topicName, authoritative);
+
+ Topic topic = getTopicReference(topicName);
+ try {
+ topic.close(false).get();
Review comment:
If this is already an async method, can you put the logic in the callback?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services