codelipenghui commented on a change in pull request #12240:
URL: https://github.com/apache/pulsar/pull/12240#discussion_r725487937



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
##########
@@ -1006,24 +1006,33 @@ public void deleteLedgerFailed(ManagedLedgerException 
exception, Object ctx) {
     }
 
     private void asyncDeleteCursor(String subscriptionName, 
CompletableFuture<Void> unsubscribeFuture) {
+        lock.writeLock().lock();
         ledger.asyncDeleteCursor(Codec.encode(subscriptionName), new 
DeleteCursorCallback() {
             @Override
             public void deleteCursorComplete(Object ctx) {
-                if (log.isDebugEnabled()) {
-                    log.debug("[{}][{}] Cursor deleted successfully", topic, 
subscriptionName);
+                try {
+                    if (log.isDebugEnabled()) {
+                        log.debug("[{}][{}] Cursor deleted successfully", 
topic, subscriptionName);
+                    }
+                    removeSubscription(subscriptionName);
+                    unsubscribeFuture.complete(null);
+                    lastActive = System.nanoTime();
+                } finally {
+                    lock.writeLock().unlock();
                 }
-                removeSubscription(subscriptionName);
-                unsubscribeFuture.complete(null);
-                lastActive = System.nanoTime();
             }
 
             @Override
             public void deleteCursorFailed(ManagedLedgerException exception, 
Object ctx) {
-                if (log.isDebugEnabled()) {
-                    log.debug("[{}][{}] Error deleting cursor for 
subscription",
-                            topic, subscriptionName, exception);
+                try {
+                    if (log.isDebugEnabled()) {
+                        log.debug("[{}][{}] Error deleting cursor for 
subscription",
+                                topic, subscriptionName, exception);
+                    }
+                    unsubscribeFuture.completeExceptionally(new 
PersistenceException(exception));

Review comment:
       We'd better to handle the cursor not found exception to avoid introduce 
write lock.




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