Skip to content
Merged
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 @@ -128,17 +128,11 @@ public void initiateWithoutRecovery() {
initiate();
}

private void closeLedgerHandle() {
try {
if (lh != null) {
lh.close();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.info("InterruptedException while closing ledger {}", ledgerId, e);
} catch (BKException e) {
LOG.warn("BKException while closing ledger {} ", ledgerId, e);
private CompletableFuture<Void> closeLedgerHandleAsync() {
if (lh != null) {
return lh.closeAsync();
}
return CompletableFuture.completedFuture(null);
}

private void openWithMetadata(Versioned<LedgerMetadata> versionedMetadata) {
Expand Down Expand Up @@ -208,10 +202,13 @@ public void safeOperationComplete(int rc, Void result) {
if (rc == BKException.Code.OK) {
openComplete(BKException.Code.OK, lh);
} else if (rc == BKException.Code.UnauthorizedAccessException) {
closeLedgerHandle();
openComplete(BKException.Code.UnauthorizedAccessException, null);
closeLedgerHandleAsync().whenComplete((r, ex) -> {
if (ex != null) {
LOG.error("Ledger {} close failed", ledgerId, ex);
}
openComplete(BKException.Code.UnauthorizedAccessException, null);
});
} else {
closeLedgerHandle();
openComplete(bk.getReturnRc(BKException.Code.LedgerRecoveryException), null);
}
}
Expand All @@ -226,8 +223,12 @@ public String toString() {
public void readLastConfirmedComplete(int rc,
long lastConfirmed, Object ctx) {
if (rc != BKException.Code.OK) {
closeLedgerHandle();
openComplete(bk.getReturnRc(BKException.Code.ReadException), null);
closeLedgerHandleAsync().whenComplete((r, ex) -> {
if (ex != null) {
LOG.error("Ledger {} close failed", ledgerId, ex);
}
openComplete(bk.getReturnRc(BKException.Code.ReadException), null);
});
} else {
lh.lastAddConfirmed = lh.lastAddPushed = lastConfirmed;
openComplete(BKException.Code.OK, lh);
Expand Down