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_r376424632
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -655,12 +655,67 @@ 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);
+
+ getPartitionedTopicMetadataAsync(topicName, authoritative, false)
+ .whenComplete((metadata, ex) -> {
+ if (ex != null) {
+ log.error("[{}] Failed to unload topic {}",
clientAppId(), topicName);
+ asyncResponse.resume(new RestException(ex));
+ } else {
+ if (metadata.partitions > 0) {
+ final List<CompletableFuture<Void>> futures =
Lists.newArrayList();
+
+ for (int i = 0; i < metadata.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:
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