This is an automated email from the ASF dual-hosted git repository.

yong pushed a commit to branch branch-4.15
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git

commit e903e619d64cd4721b88c640b05e38fa5ebd206d
Author: Andrey Yegorov <[email protected]>
AuthorDate: Fri Oct 7 19:20:27 2022 -0700

    LedgerOpenOp: Do not call blocking close() in the callback (#3513)
    
    * Do not call blocking close() in the callback
         * CR feedback, remove lombok from LedgerOpenOp
    
    (cherry picked from commit 2734e8bcec6371cb139913624fd30953fc6c1def)
---
 .../org/apache/bookkeeper/client/LedgerOpenOp.java | 31 +++++++++++-----------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
index 34404fabaf..0f688639d2 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
@@ -129,17 +129,11 @@ class LedgerOpenOp {
         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) 
{
@@ -209,10 +203,13 @@ class LedgerOpenOp {
                     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);
                     }
                 }
@@ -227,8 +224,12 @@ class LedgerOpenOp {
                 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);

Reply via email to