HBASE-22223 Implement RegionLocator based on AsyncTableRegionLocator

This commit is contained in:
Duo Zhang 2019-04-16 16:52:54 +08:00 committed by zhangduo
parent a50154dd0a
commit bd109506f3
3 changed files with 76 additions and 22 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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();
}
}