You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/09/30 03:53:39 UTC

[bookkeeper] branch master updated: [TABLE SERVICE] [CLIENT] Provide a timeout mechanism on closing the client

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

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c4accb  [TABLE SERVICE] [CLIENT] Provide a timeout mechanism on closing the client
0c4accb is described below

commit 0c4accbce977fbc6191689bcb5792e2a3563eb78
Author: Sijie Guo <gu...@gmail.com>
AuthorDate: Sat Sep 29 20:53:34 2018 -0700

    [TABLE SERVICE] [CLIENT] Provide a timeout mechanism on closing the client
    
    Descriptions of the changes in this PR:
    
    ### Motivation
    
    Closing the storage client sometime takes long time. And closing the client typically happens at the last step. So we don't necessarily to be blocking at waiting it to complete.
    
    ### Changes
    
    Provide a timeout version of sync close. And timeout the closing operation if it doesn't complete within 1 second.
    
    
    
    
    Author:
    
    Reviewers: Jia Zhai <None>, Enrico Olivelli <eo...@gmail.com>
    
    This closes #1717 from sijie/close_storage_client
---
 .../main/java/org/apache/bookkeeper/clients/StorageClientImpl.java  | 6 +++++-
 .../java/org/apache/bookkeeper/common/util/AutoAsyncCloseable.java  | 5 +++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/stream/clients/java/all/src/main/java/org/apache/bookkeeper/clients/StorageClientImpl.java b/stream/clients/java/all/src/main/java/org/apache/bookkeeper/clients/StorageClientImpl.java
index fca1e5a..9d49556 100644
--- a/stream/clients/java/all/src/main/java/org/apache/bookkeeper/clients/StorageClientImpl.java
+++ b/stream/clients/java/all/src/main/java/org/apache/bookkeeper/clients/StorageClientImpl.java
@@ -128,7 +128,11 @@ class StorageClientImpl extends AbstractAutoAsyncCloseable implements StorageCli
 
     @Override
     public void close() {
-        super.close();
+        try {
+            super.close(1, TimeUnit.SECONDS);
+        } catch (Exception e) {
+            log.warn("Encountered exceptions on closing the storage client", e);
+        }
         scheduler.forceShutdown(100, TimeUnit.MILLISECONDS);
     }
 }
diff --git a/stream/common/src/main/java/org/apache/bookkeeper/common/util/AutoAsyncCloseable.java b/stream/common/src/main/java/org/apache/bookkeeper/common/util/AutoAsyncCloseable.java
index d4fc82c..febcd09 100644
--- a/stream/common/src/main/java/org/apache/bookkeeper/common/util/AutoAsyncCloseable.java
+++ b/stream/common/src/main/java/org/apache/bookkeeper/common/util/AutoAsyncCloseable.java
@@ -18,6 +18,7 @@
 
 package org.apache.bookkeeper.common.util;
 
+import java.util.concurrent.TimeUnit;
 import org.apache.bookkeeper.common.concurrent.FutureUtils;
 
 /**
@@ -39,4 +40,8 @@ public interface AutoAsyncCloseable extends AsyncCloseable, AutoCloseable {
             // ignore the exception
         }
     }
+
+    default void close(long waitTimeout, TimeUnit waitTimeUnit) throws Exception {
+        FutureUtils.result(closeAsync(), waitTimeout, waitTimeUnit);
+    }
 }