From bd109506f356db49e67e897cafa193dceb5b04ab Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Tue, 16 Apr 2019 16:52:54 +0800 Subject: [PATCH] HBASE-22223 Implement RegionLocator based on AsyncTableRegionLocator --- .../hbase/client/AsyncConnectionImpl.java | 12 +--- .../client/ConnectionOverAsyncConnection.java | 16 ++--- ...ionLocatorOverAsyncTableRegionLocator.java | 70 +++++++++++++++++++ 3 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionLocatorOverAsyncTableRegionLocator.java 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 4a0041290ab..84e1da635fa 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 8ec7ab83504..861aab086d4 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 00000000000..5e21e3b4eab --- /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 getRegionLocations(byte[] row, boolean reload) throws IOException { + return get(locator.getRegionLocations(row, reload)); + } + + @Override + public void clearRegionLocationCache() { + locator.clearRegionLocationCache(); + } + + @Override + public List getAllRegionLocations() throws IOException { + return get(locator.getAllRegionLocations()); + } + + @Override + public TableName getName() { + return locator.getName(); + } + +}