Fixed race condition on deleting topic with active readers
@@ -94,6 +94,7 @@ import org.apache.bookkeeper.mledger.ManagedLedger;
import org.apache.bookkeeper.mledger.ManagedLedgerConfig;
import org.apache.bookkeeper.mledger.ManagedLedgerException;
import org.apache.bookkeeper.mledger.ManagedLedgerException.BadVersionException;
+import org.apache.bookkeeper.mledger.ManagedLedgerException.CursorNotFoundException;
import org.apache.bookkeeper.mledger.ManagedLedgerException.InvalidCursorPositionException;
import org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerAlreadyClosedException;
import org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerFencedException;
@@ -2229,7 +2230,14 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
@Override
public void deleteCursorFailed(ManagedLedgerException exception, Object ctx) {
- log.warn("[{}] Failed to delete cursor {} : {}", name, cursor, exception);
+ if (exception instanceof CursorNotFoundException) {
+ // This could happen if a cursor is getting deleted while we are deleting the topic
+ // Treating this as a "success" case, since the cursor is gone in any case.
+ deleteCursorComplete(ctx);
+ return;
+ }
+
+ log.warn("[{}] Failed to delete cursor {}: {}", name, cursor, exception.getMessage(), exception);
cursorDeleteException.compareAndSet(null, exception);
if (cursorsToDelete.decrementAndGet() == 0) {
// Trigger callback only once
