murong00 commented on a change in pull request #6383: [Issue 6043] Support 
force deleting subscription
URL: https://github.com/apache/pulsar/pull/6383#discussion_r389344071
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
 ##########
 @@ -1032,6 +1040,73 @@ private void 
internalDeleteSubscriptionForNonPartitionedTopic(AsyncResponse asyn
         }
     }
 
+    protected void internalDeleteSubscriptionForcefully(AsyncResponse 
asyncResponse, String subName, boolean authoritative) {
+        if (topicName.isGlobal()) {
+            validateGlobalNamespaceOwnership(namespaceName);
+        }
+        // If the topic name is a partition name, no need to get partition 
topic metadata again
+        if (topicName.isPartitioned()) {
+            
internalDeleteSubscriptionForNonPartitionedTopicForcefully(asyncResponse, 
subName, authoritative);
+        } else {
+            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()
+                            
.deleteSubscriptionAsync(topicNamePartition.toString(), subName, true));
+                    } catch (Exception e) {
+                        log.error("[{}] Failed to delete subscription 
forcefully {} {}", clientAppId(), topicNamePartition, subName,
+                            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, "Subscription not found"));
+                            return null;
+                        } else {
+                            log.error("[{}] Failed to delete subscription 
forcefully {} {}", clientAppId(), topicName, subName, t);
+                            asyncResponse.resume(new RestException(t));
+                            return null;
+                        }
+                    }
+
+                    asyncResponse.resume(Response.noContent().build());
+                    return null;
+                });
+            } else {
+                
internalDeleteSubscriptionForNonPartitionedTopicForcefully(asyncResponse, 
subName, authoritative);
+            }
+        }
+    }
+
+    private void 
internalDeleteSubscriptionForNonPartitionedTopicForcefully(AsyncResponse 
asyncResponse, String subName, boolean authoritative) {
+        validateAdminAccessForSubscriber(subName, authoritative);
 
 Review comment:
   done.

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