Skip to content

Commit

Permalink
remove future of completed exceptionally
Browse files Browse the repository at this point in the history
  • Loading branch information
coderzc committed Apr 18, 2023
1 parent a2d0f78 commit 2a65382
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ private CompletableFuture<LedgerHandle> createLedger(String bucketKey, String to
}

private CompletableFuture<LedgerHandle> getLedgerHandle(Long ledgerId) {
return ledgerHandleFutureCache.computeIfAbsent(ledgerId, k -> openLedger(ledgerId));
CompletableFuture<LedgerHandle> ledgerHandleCompletableFuture =
ledgerHandleFutureCache.computeIfAbsent(ledgerId, k -> openLedger(ledgerId));
// remove future of completed exceptionally
ledgerHandleCompletableFuture.whenComplete((__, ex) -> {
if (ex != null) {
ledgerHandleFutureCache.remove(ledgerId, ledgerHandleCompletableFuture);
}
});
return ledgerHandleCompletableFuture;
}

private CompletableFuture<LedgerHandle> openLedger(Long ledgerId) {
Expand All @@ -178,7 +186,6 @@ private CompletableFuture<LedgerHandle> openLedger(Long ledgerId) {
LedgerPassword,
(rc, handle, ctx) -> {
if (rc != BKException.Code.OK) {
ledgerHandleFutureCache.remove(ledgerId, future);
if (handle != null) {
closeLedger(handle);
}
Expand Down

0 comments on commit 2a65382

Please sign in to comment.