You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2019/02/14 03:52:52 UTC
[hbase] branch branch-2.2 updated: HBASE-21888 Add a isClosed
method to AsyncConnection
This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.2 by this push:
new 187853d HBASE-21888 Add a isClosed method to AsyncConnection
187853d is described below
commit 187853d8b2781ead9b31acaee393f53fdfcf4305
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Thu Feb 14 11:41:05 2019 +0800
HBASE-21888 Add a isClosed method to AsyncConnection
Signed-off-by: Guanghao Zhang <zg...@apache.org>
---
.../org/apache/hadoop/hbase/client/AsyncConnection.java | 7 ++++++-
.../org/apache/hadoop/hbase/client/AsyncConnectionImpl.java | 13 +++++++++++++
.../java/org/apache/hadoop/hbase/client/TestAsyncTable.java | 2 ++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnection.java
index 564d4db..75971ad 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnection.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnection.java
@@ -21,7 +21,6 @@ import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
-
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.ServerName;
@@ -197,6 +196,12 @@ public interface AsyncConnection extends Closeable {
AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName, ExecutorService pool);
/**
+ * Returns whether the connection is closed or not.
+ * @return true if this connection is closed
+ */
+ boolean isClosed();
+
+ /**
* Retrieve an Hbck implementation to fix an HBase cluster. The returned Hbck is not guaranteed to
* be thread-safe. A new instance should be created by each thread. This is a lightweight
* operation. Pooling or caching of the returned Hbck instance is not recommended.
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java
index 07f62a8..e47d4cc 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java
@@ -105,6 +105,8 @@ class AsyncConnectionImpl implements AsyncConnection {
private ChoreService authService;
+ private volatile boolean closed = false;
+
public AsyncConnectionImpl(Configuration conf, AsyncRegistry registry, String clusterId,
User user) {
this.conf = conf;
@@ -140,11 +142,22 @@ class AsyncConnectionImpl implements AsyncConnection {
@Override
public void close() {
+ // As the code below is safe to be executed in parallel, here we do not use CAS or lock, just a
+ // simple volatile flag.
+ if (closed) {
+ return;
+ }
IOUtils.closeQuietly(rpcClient);
IOUtils.closeQuietly(registry);
if (authService != null) {
authService.shutdown();
}
+ closed = true;
+ }
+
+ @Override
+ public boolean isClosed() {
+ return closed;
}
@Override
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTable.java
index 85a6d9d..89ebf8d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTable.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTable.java
@@ -111,11 +111,13 @@ public class TestAsyncTable {
TEST_UTIL.createTable(TABLE_NAME, FAMILY);
TEST_UTIL.waitTableAvailable(TABLE_NAME);
ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
+ assertFalse(ASYNC_CONN.isClosed());
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
IOUtils.closeQuietly(ASYNC_CONN);
+ assertTrue(ASYNC_CONN.isClosed());
TEST_UTIL.shutdownMiniCluster();
}