poorbarcode commented on code in PR #19737:
URL: https://github.com/apache/pulsar/pull/19737#discussion_r1155087785


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -429,6 +431,25 @@ public AtomicLong getPendingWriteOps() {
         return pendingWriteOps;
     }
 
+    public CompletableFuture<Void> unloadSubscription(String subName) {
+        final PersistentSubscription sub = subscriptions.get(subName);
+        if (sub == null) {
+            return CompletableFuture.failedFuture(new 
RestException(Response.Status.NOT_FOUND,
+                    String.format("Subscription %s not found", subName)));
+        }
+        if (Compactor.COMPACTION_SUBSCRIPTION.equals(sub.getName())){
+            return CompletableFuture.failedFuture(new 
RestException(Response.Status.BAD_REQUEST,
+                    "Could not reload the compaction subscription"));
+        }
+        // Fence old subscription -> Rewind cursor -> Replace with a new 
subscription.
+        return sub.disconnect().thenAccept(ignore -> {
+            sub.getCursor().rewind();

Review Comment:
   `unloadTopic` will close the `ManagedLedger` and close all cursors, which 
guarantees that the states of ML and cursors are consistent. Only closing one 
cursor under the ML will affect the work of ML, which is a dangerous behavior.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to