Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,10 @@ public void closeFailed(ManagedLedgerException exception, Object ctx) {
? bookkeeperFactory.get()
: CompletableFuture.completedFuture(null);
return bookkeeperFuture
.thenRun(() -> {
.thenCompose(__ -> {
log.info().attr("numLedgers", ledgers.size()).log("Closing ledgers");
//make sure all callbacks is called.
List<CompletableFuture<Void>> remainingFutures = new ArrayList<>();
ledgers.forEach(((ledgerName, ledgerFuture) -> {
if (!ledgerFuture.isDone()) {
ledgerFuture.completeExceptionally(
Expand All @@ -719,14 +720,26 @@ public void closeFailed(ManagedLedgerException exception, Object ctx) {
if (managedLedger == null) {
return;
}
try {
managedLedger.close();
} catch (Throwable throwable) {
log.warn().attr("managedLedger", managedLedger.getName()).exception(throwable)
.log("Got exception when closing managed ledger");
}
// Close asynchronously so a slow close cannot block, serially, the thread
// that completes the shutdown future.
CompletableFuture<Void> closeFuture = new CompletableFuture<>();
remainingFutures.add(closeFuture);
managedLedger.asyncClose(new AsyncCallbacks.CloseCallback() {
@Override
public void closeComplete(Object ctx) {
closeFuture.complete(null);
}

@Override
public void closeFailed(ManagedLedgerException exception, Object ctx) {
log.warn().attr("managedLedger", managedLedger.getName()).exception(exception)
.log("Got exception when closing managed ledger");
closeFuture.complete(null);
}
}, null);
}
}));
return Futures.waitForAll(remainingFutures);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this path used managedLedger.close(), which bounded the wait with AsyncOperationTimeoutSeconds before continuing shutdown. With the new asyncClose() + waitForAll flow, do we still want to keep a bounded wait here?

}).whenCompleteAsync((__, ___) -> {
//wait for tasks in scheduledExecutor executed.
openTelemetryManagedCursorStats.close();
Expand Down
Loading