hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhang...@apache.org
Subject [hbase] 17/28: HBASE-22223 Implement RegionLocator based on AsyncTableRegionLocator
Date Mon, 03 Jun 2019 09:49:28 GMT
This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch HBASE-21512
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit 16fa4b8cb74e4e025530ced58c2fc13219383304
Author: Duo Zhang <zhangduo@apache.org>
AuthorDate: Tue Apr 16 16:52:54 2019 +0800

    HBASE-22223 Implement RegionLocator based on AsyncTableRegionLocator
---
 .../hadoop/hbase/client/AsyncConnectionImpl.java   | 12 +---
 .../client/ConnectionOverAsyncConnection.java      | 16 ++---
 .../RegionLocatorOverAsyncTableRegionLocator.java  | 70 ++++++++++++++++++++++
 3 files changed, 76 insertions(+), 22 deletions(-)

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 4a00412..84e1da6 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
@@ -28,7 +28,6 @@ import static org.apache.hadoop.hbase.client.NonceGenerator.CLIENT_NONCES_ENABLE
 import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
 
 import java.io.IOException;
-import java.io.UncheckedIOException;
 import java.net.SocketAddress;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
@@ -208,7 +207,7 @@ class AsyncConnectionImpl implements AsyncConnection {
     metrics.ifPresent(MetricsConnection::shutdown);
     ConnectionOverAsyncConnection c = this.conn;
     if (c != null) {
-      c.closeConnImpl();
+      c.closePool();
     }
     closed = true;
   }
@@ -362,14 +361,7 @@ class AsyncConnectionImpl implements AsyncConnection {
       if (c != null) {
         return c;
       }
-      try {
-        c = new ConnectionOverAsyncConnection(this,
-          ConnectionFactory.createConnectionImpl(conf, null, user));
-      } catch (IOException e) {
-        // TODO: finally we will not rely on ConnectionImplementation anymore and there will
no
-        // IOException here.
-        throw new UncheckedIOException(e);
-      }
+      c = new ConnectionOverAsyncConnection(this);
       this.conn = c;
     }
     return c;
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionOverAsyncConnection.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionOverAsyncConnection.java
index 8ec7ab8..861aab0 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionOverAsyncConnection.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionOverAsyncConnection.java
@@ -43,20 +43,12 @@ class ConnectionOverAsyncConnection implements Connection {
 
   private volatile ExecutorService batchPool = null;
 
-  protected final AsyncConnectionImpl conn;
-
-  /**
-   * @deprecated we can not implement all the related stuffs at once so keep it here for
now, will
-   *             remove it after we implement all the stuffs, like Admin, RegionLocator,
etc.
-   */
-  @Deprecated
-  private final ConnectionImplementation oldConn;
+  private final AsyncConnectionImpl conn;
 
   private final ConnectionConfiguration connConf;
 
-  ConnectionOverAsyncConnection(AsyncConnectionImpl conn, ConnectionImplementation oldConn)
{
+  ConnectionOverAsyncConnection(AsyncConnectionImpl conn) {
     this.conn = conn;
-    this.oldConn = oldConn;
     this.connConf = new ConnectionConfiguration(conn.getConfiguration());
   }
 
@@ -109,7 +101,7 @@ class ConnectionOverAsyncConnection implements Connection {
 
   @Override
   public RegionLocator getRegionLocator(TableName tableName) throws IOException {
-    return oldConn.getRegionLocator(tableName);
+    return new RegionLocatorOverAsyncTableRegionLocator(conn.getRegionLocator(tableName));
   }
 
   @Override
@@ -129,7 +121,7 @@ class ConnectionOverAsyncConnection implements Connection {
 
   // will be called from AsyncConnection, to avoid infinite loop as in the above method we
will call
   // AsyncConnection.close.
-  void closeConnImpl() {
+  void closePool() {
     ExecutorService batchPool = this.batchPool;
     if (batchPool != null) {
       ConnectionUtils.shutdownPool(batchPool);
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionLocatorOverAsyncTableRegionLocator.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionLocatorOverAsyncTableRegionLocator.java
new file mode 100644
index 0000000..5e21e3b
--- /dev/null
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionLocatorOverAsyncTableRegionLocator.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.client;
+
+import static org.apache.hadoop.hbase.util.FutureUtils.get;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * The {@link RegionLocator} implementation based on {@link AsyncTableRegionLocator}.
+ */
+@InterfaceAudience.Private
+class RegionLocatorOverAsyncTableRegionLocator implements RegionLocator {
+
+  private final AsyncTableRegionLocator locator;
+
+  RegionLocatorOverAsyncTableRegionLocator(AsyncTableRegionLocator locator) {
+    this.locator = locator;
+  }
+
+  @Override
+  public void close() {
+  }
+
+  @Override
+  public HRegionLocation getRegionLocation(byte[] row, int replicaId, boolean reload)
+      throws IOException {
+    return get(locator.getRegionLocation(row, replicaId, reload));
+  }
+
+  @Override
+  public List<HRegionLocation> getRegionLocations(byte[] row, boolean reload) throws
IOException {
+    return get(locator.getRegionLocations(row, reload));
+  }
+
+  @Override
+  public void clearRegionLocationCache() {
+    locator.clearRegionLocationCache();
+  }
+
+  @Override
+  public List<HRegionLocation> getAllRegionLocations() throws IOException {
+    return get(locator.getAllRegionLocations());
+  }
+
+  @Override
+  public TableName getName() {
+    return locator.getName();
+  }
+
+}


Mime
View raw message