315157973 commented on code in PR #19992: URL: https://github.com/apache/pulsar/pull/19992#discussion_r1155911442
########## managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java: ########## @@ -2931,39 +2949,53 @@ public void deleteCursorFailed(ManagedLedgerException exception, Object ctx) { private void asyncDeleteLedgerFromBookKeeper(long ledgerId) { asyncDeleteLedger(ledgerId, DEFAULT_LEDGER_DELETE_RETRIES); } - - private void asyncDeleteLedger(long ledgerId, LedgerInfo info) { + public CompletableFuture<Void> asyncDeleteLedger(long ledgerId, LedgerInfo info) { + List<CompletableFuture<Void>> futures = new ArrayList<>(); if (!info.getOffloadContext().getBookkeeperDeleted()) { // only delete if it hasn't been previously deleted for offload - asyncDeleteLedger(ledgerId, DEFAULT_LEDGER_DELETE_RETRIES); + futures.add(asyncDeleteLedger(ledgerId, DEFAULT_LEDGER_DELETE_RETRIES, null)); } - if (info.getOffloadContext().hasUidMsb()) { UUID uuid = new UUID(info.getOffloadContext().getUidMsb(), info.getOffloadContext().getUidLsb()); - OffloadUtils.cleanupOffloaded(ledgerId, uuid, config, + futures.add(OffloadUtils.cleanupOffloaded(ledgerId, uuid, config, OffloadUtils.getOffloadDriverMetadata(info, config.getLedgerOffloader().getOffloadDriverMetadata()), - "Trimming", name, scheduledExecutor); + "Trimming", name, scheduledExecutor)); } + if (!futures.isEmpty()) { + return FutureUtil.waitForAll(futures); + } + return CompletableFuture.completedFuture(null); } private void asyncDeleteLedger(long ledgerId, long retry) { - if (retry <= 0) { - log.warn("[{}] Failed to delete ledger after retries {}", name, ledgerId); - return; - } + asyncDeleteLedger(ledgerId, retry, null); + } + @VisibleForTesting + public CompletableFuture<Void> asyncDeleteLedger(long ledgerId, long retry, + CompletableFuture<Void> callbackFuture) { + CompletableFuture<Void> future = callbackFuture == null ? new CompletableFuture<>() : callbackFuture; bookKeeper.asyncDeleteLedger(ledgerId, (rc, ctx) -> { + if (rc != BKException.Code.OK) { Review Comment: Good idea -- 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: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org