HBASE-23604: Clarify AsyncRegistry usage in the code. (#957)
* HBASE-23604: Cleanup AsyncRegistry interface - Cleans up the method names to make more sense and adds a little more javadocs for context. In future patches we can revisit the name of the actual class to make it more self explanatory. - Does AsyncRegistry -> ConnectionRegistry rename. "async" ness of the registry is kind of implicit based on the interface contents and need not be reflected in the name. Signed-off-by: Nick Dimiduk <ndimiduk@apache.org> Signed-off-by: stack <stack@apache.org> Signed-off-by: Viraj Jasani <vjasani@apache.org> (cherry picked from commit 12bb41eb2ca1871687b4c00ffc6b219f8dcc3b2b)
This commit is contained in:
parent
488460e840
commit
c650f28ab4
@ -83,7 +83,7 @@ class AsyncConnectionImpl implements AsyncConnection {
|
||||
|
||||
private final User user;
|
||||
|
||||
final AsyncRegistry registry;
|
||||
final ConnectionRegistry registry;
|
||||
|
||||
private final int rpcTimeout;
|
||||
|
||||
@ -118,7 +118,7 @@ class AsyncConnectionImpl implements AsyncConnection {
|
||||
|
||||
private final ClusterStatusListener clusterStatusListener;
|
||||
|
||||
public AsyncConnectionImpl(Configuration conf, AsyncRegistry registry, String clusterId,
|
||||
public AsyncConnectionImpl(Configuration conf, ConnectionRegistry registry, String clusterId,
|
||||
User user) {
|
||||
this.conf = conf;
|
||||
this.user = user;
|
||||
@ -248,7 +248,7 @@ class AsyncConnectionImpl implements AsyncConnection {
|
||||
CompletableFuture<MasterService.Interface> getMasterStub() {
|
||||
return ConnectionUtils.getOrFetch(masterStub, masterStubMakeFuture, false, () -> {
|
||||
CompletableFuture<MasterService.Interface> future = new CompletableFuture<>();
|
||||
addListener(registry.getMasterAddress(), (addr, error) -> {
|
||||
addListener(registry.getActiveMaster(), (addr, error) -> {
|
||||
if (error != null) {
|
||||
future.completeExceptionally(error);
|
||||
} else if (addr == null) {
|
||||
@ -342,7 +342,7 @@ class AsyncConnectionImpl implements AsyncConnection {
|
||||
@Override
|
||||
public CompletableFuture<Hbck> getHbck() {
|
||||
CompletableFuture<Hbck> future = new CompletableFuture<>();
|
||||
addListener(registry.getMasterAddress(), (sn, error) -> {
|
||||
addListener(registry.getActiveMaster(), (sn, error) -> {
|
||||
if (error != null) {
|
||||
future.completeExceptionally(error);
|
||||
} else {
|
||||
|
@ -36,14 +36,14 @@ import org.apache.yetus.audience.InterfaceAudience;
|
||||
@InterfaceAudience.Private
|
||||
class AsyncMetaRegionLocator {
|
||||
|
||||
private final AsyncRegistry registry;
|
||||
private final ConnectionRegistry registry;
|
||||
|
||||
private final AtomicReference<RegionLocations> metaRegionLocations = new AtomicReference<>();
|
||||
|
||||
private final AtomicReference<CompletableFuture<RegionLocations>> metaRelocateFuture =
|
||||
new AtomicReference<>();
|
||||
|
||||
AsyncMetaRegionLocator(AsyncRegistry registry) {
|
||||
AsyncMetaRegionLocator(ConnectionRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ class AsyncMetaRegionLocator {
|
||||
*/
|
||||
CompletableFuture<RegionLocations> getRegionLocations(int replicaId, boolean reload) {
|
||||
return ConnectionUtils.getOrFetch(metaRegionLocations, metaRelocateFuture, reload,
|
||||
registry::getMetaRegionLocation, locs -> isGood(locs, replicaId), "meta region location");
|
||||
registry::getMetaRegionLocations, locs -> isGood(locs, replicaId), "meta region location");
|
||||
}
|
||||
|
||||
private HRegionLocation getCacheLocation(HRegionLocation loc) {
|
||||
|
@ -55,7 +55,7 @@ class AsyncTableRegionLocatorImpl implements AsyncTableRegionLocator {
|
||||
@Override
|
||||
public CompletableFuture<List<HRegionLocation>> getAllRegionLocations() {
|
||||
if (TableName.isMetaTableName(tableName)) {
|
||||
return conn.registry.getMetaRegionLocation()
|
||||
return conn.registry.getMetaRegionLocations()
|
||||
.thenApply(locs -> Arrays.asList(locs.getRegionLocations()));
|
||||
}
|
||||
return AsyncMetaTableAccessor.getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME),
|
||||
|
@ -281,7 +281,7 @@ public class ConnectionFactory {
|
||||
public static CompletableFuture<AsyncConnection> createAsyncConnection(Configuration conf,
|
||||
final User user) {
|
||||
CompletableFuture<AsyncConnection> future = new CompletableFuture<>();
|
||||
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(conf);
|
||||
ConnectionRegistry registry = ConnectionRegistryFactory.getRegistry(conf);
|
||||
addListener(registry.getClusterId(), (clusterId, error) -> {
|
||||
if (error != null) {
|
||||
registry.close();
|
||||
|
@ -217,7 +217,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
|
||||
/**
|
||||
* Cluster registry of basic info such as clusterid and meta region location.
|
||||
*/
|
||||
private final AsyncRegistry registry;
|
||||
private final ConnectionRegistry registry;
|
||||
|
||||
private final ClientBackoffPolicy backoffPolicy;
|
||||
|
||||
@ -303,7 +303,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
|
||||
this.conf.get(BufferedMutator.CLASSNAME_KEY);
|
||||
|
||||
try {
|
||||
this.registry = AsyncRegistryFactory.getRegistry(conf);
|
||||
this.registry = ConnectionRegistryFactory.getRegistry(conf);
|
||||
retrieveClusterId();
|
||||
|
||||
this.rpcClient = RpcClientFactory.createClient(this.conf, this.clusterId, this.metrics);
|
||||
@ -434,7 +434,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
|
||||
|
||||
@Override
|
||||
public Hbck getHbck() throws IOException {
|
||||
return getHbck(get(registry.getMasterAddress()));
|
||||
return getHbck(get(registry.getActiveMaster()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -811,7 +811,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
|
||||
}
|
||||
|
||||
// Look up from zookeeper
|
||||
locations = get(this.registry.getMetaRegionLocation());
|
||||
locations = get(this.registry.getMetaRegionLocations());
|
||||
if (locations != null) {
|
||||
cacheLocation(tableName, locations);
|
||||
}
|
||||
@ -1162,7 +1162,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
|
||||
*/
|
||||
private MasterProtos.MasterService.BlockingInterface makeStubNoRetries()
|
||||
throws IOException, KeeperException {
|
||||
ServerName sn = get(registry.getMasterAddress());
|
||||
ServerName sn = get(registry.getActiveMaster());
|
||||
if (sn == null) {
|
||||
String msg = "ZooKeeper available but no active master location found";
|
||||
LOG.info(msg);
|
||||
@ -1211,7 +1211,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
|
||||
|
||||
@Override
|
||||
public AdminProtos.AdminService.BlockingInterface getAdminForMaster() throws IOException {
|
||||
return getAdmin(get(registry.getMasterAddress()));
|
||||
return getAdmin(get(registry.getActiveMaster()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,16 +24,17 @@ import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
/**
|
||||
* Implementations hold cluster information such as this cluster's id, location of hbase:meta, etc..
|
||||
* Registry for meta information needed for connection setup to a HBase cluster. Implementations
|
||||
* hold cluster information such as this cluster's id, location of hbase:meta, etc..
|
||||
* Internal use only.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
interface AsyncRegistry extends Closeable {
|
||||
interface ConnectionRegistry extends Closeable {
|
||||
|
||||
/**
|
||||
* Get the location of meta region.
|
||||
* Get the location of meta region(s).
|
||||
*/
|
||||
CompletableFuture<RegionLocations> getMetaRegionLocation();
|
||||
CompletableFuture<RegionLocations> getMetaRegionLocations();
|
||||
|
||||
/**
|
||||
* Should only be called once.
|
||||
@ -43,9 +44,9 @@ interface AsyncRegistry extends Closeable {
|
||||
CompletableFuture<String> getClusterId();
|
||||
|
||||
/**
|
||||
* Get the address of HMaster.
|
||||
* Get the address of active HMaster.
|
||||
*/
|
||||
CompletableFuture<ServerName> getMasterAddress();
|
||||
CompletableFuture<ServerName> getActiveMaster();
|
||||
|
||||
/**
|
||||
* Closes this instance and releases any system resources associated with it
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* 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
|
||||
@ -18,26 +18,28 @@
|
||||
package org.apache.hadoop.hbase.client;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.apache.hadoop.hbase.util.ReflectionUtils;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
/**
|
||||
* Get instance of configured Registry.
|
||||
* Factory class to get the instance of configured connection registry.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
final class AsyncRegistryFactory {
|
||||
final class ConnectionRegistryFactory {
|
||||
|
||||
static final String REGISTRY_IMPL_CONF_KEY = "hbase.client.registry.impl";
|
||||
static final String CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY =
|
||||
"hbase.client.connection.registry.impl";
|
||||
|
||||
private AsyncRegistryFactory() {
|
||||
private ConnectionRegistryFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The cluster registry implementation to use.
|
||||
* @return The connection registry implementation to use.
|
||||
*/
|
||||
static AsyncRegistry getRegistry(Configuration conf) {
|
||||
Class<? extends AsyncRegistry> clazz =
|
||||
conf.getClass(REGISTRY_IMPL_CONF_KEY, ZKAsyncRegistry.class, AsyncRegistry.class);
|
||||
static ConnectionRegistry getRegistry(Configuration conf) {
|
||||
Class<? extends ConnectionRegistry> clazz = conf.getClass(
|
||||
CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, ZKConnectionRegistry.class,
|
||||
ConnectionRegistry.class);
|
||||
return ReflectionUtils.newInstance(clazz, conf);
|
||||
}
|
||||
}
|
@ -722,7 +722,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||
private CompletableFuture<Boolean> isTableAvailable(TableName tableName,
|
||||
Optional<byte[][]> splitKeys) {
|
||||
if (TableName.isMetaTableName(tableName)) {
|
||||
return connection.registry.getMetaRegionLocation().thenApply(locs -> Stream
|
||||
return connection.registry.getMetaRegionLocations().thenApply(locs -> Stream
|
||||
.of(locs.getRegionLocations()).allMatch(loc -> loc != null && loc.getServerName() != null));
|
||||
}
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
@ -882,7 +882,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||
@Override
|
||||
public CompletableFuture<List<RegionInfo>> getRegions(TableName tableName) {
|
||||
if (tableName.equals(META_TABLE_NAME)) {
|
||||
return connection.registry.getMetaRegionLocation()
|
||||
return connection.registry.getMetaRegionLocations()
|
||||
.thenApply(locs -> Stream.of(locs.getRegionLocations()).map(HRegionLocation::getRegion)
|
||||
.collect(Collectors.toList()));
|
||||
} else {
|
||||
@ -1098,8 +1098,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||
if (TableName.META_TABLE_NAME.equals(tableName)) {
|
||||
CompletableFuture<List<HRegionLocation>> future = new CompletableFuture<>();
|
||||
// For meta table, we use zk to fetch all locations.
|
||||
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(connection.getConfiguration());
|
||||
addListener(registry.getMetaRegionLocation(), (metaRegions, err) -> {
|
||||
ConnectionRegistry registry = ConnectionRegistryFactory.getRegistry(
|
||||
connection.getConfiguration());
|
||||
addListener(registry.getMetaRegionLocations(), (metaRegions, err) -> {
|
||||
if (err != null) {
|
||||
future.completeExceptionally(err);
|
||||
} else if (metaRegions == null || metaRegions.isEmpty() ||
|
||||
@ -1127,7 +1128,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||
|
||||
switch (compactType) {
|
||||
case MOB:
|
||||
addListener(connection.registry.getMasterAddress(), (serverName, err) -> {
|
||||
addListener(connection.registry.getActiveMaster(), (serverName, err) -> {
|
||||
if (err != null) {
|
||||
future.completeExceptionally(err);
|
||||
return;
|
||||
@ -2358,7 +2359,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||
String encodedName = Bytes.toString(regionNameOrEncodedRegionName);
|
||||
if (encodedName.length() < RegionInfo.MD5_HEX_LENGTH) {
|
||||
// old format encodedName, should be meta region
|
||||
future = connection.registry.getMetaRegionLocation()
|
||||
future = connection.registry.getMetaRegionLocations()
|
||||
.thenApply(locs -> Stream.of(locs.getRegionLocations())
|
||||
.filter(loc -> loc.getRegion().getEncodedName().equals(encodedName)).findFirst());
|
||||
} else {
|
||||
@ -2369,7 +2370,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||
RegionInfo regionInfo =
|
||||
MetaTableAccessor.parseRegionInfoFromRegionName(regionNameOrEncodedRegionName);
|
||||
if (regionInfo.isMetaRegion()) {
|
||||
future = connection.registry.getMetaRegionLocation()
|
||||
future = connection.registry.getMetaRegionLocations()
|
||||
.thenApply(locs -> Stream.of(locs.getRegionLocations())
|
||||
.filter(loc -> loc.getRegion().getReplicaId() == regionInfo.getReplicaId())
|
||||
.findFirst());
|
||||
@ -2942,7 +2943,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||
|
||||
switch (compactType) {
|
||||
case MOB:
|
||||
addListener(connection.registry.getMasterAddress(), (serverName, err) -> {
|
||||
addListener(connection.registry.getActiveMaster(), (serverName, err) -> {
|
||||
if (err != null) {
|
||||
future.completeExceptionally(err);
|
||||
return;
|
||||
|
@ -50,15 +50,15 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos;
|
||||
* Zookeeper based registry implementation.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
class ZKAsyncRegistry implements AsyncRegistry {
|
||||
class ZKConnectionRegistry implements ConnectionRegistry {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ZKAsyncRegistry.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ZKConnectionRegistry.class);
|
||||
|
||||
private final ReadOnlyZKClient zk;
|
||||
|
||||
private final ZNodePaths znodePaths;
|
||||
|
||||
ZKAsyncRegistry(Configuration conf) {
|
||||
ZKConnectionRegistry(Configuration conf) {
|
||||
this.znodePaths = new ZNodePaths(conf);
|
||||
this.zk = new ReadOnlyZKClient(conf);
|
||||
}
|
||||
@ -93,7 +93,7 @@ class ZKAsyncRegistry implements AsyncRegistry {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<String> getClusterId() {
|
||||
return getAndConvert(znodePaths.clusterIdZNode, ZKAsyncRegistry::getClusterId);
|
||||
return getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@ -144,7 +144,7 @@ class ZKAsyncRegistry implements AsyncRegistry {
|
||||
int replicaId = znodePaths.getMetaReplicaIdFromZnode(metaReplicaZNode);
|
||||
String path = ZNodePaths.joinZNode(znodePaths.baseZNode, metaReplicaZNode);
|
||||
if (replicaId == DEFAULT_REPLICA_ID) {
|
||||
addListener(getAndConvert(path, ZKAsyncRegistry::getMetaProto), (proto, error) -> {
|
||||
addListener(getAndConvert(path, ZKConnectionRegistry::getMetaProto), (proto, error) -> {
|
||||
if (error != null) {
|
||||
future.completeExceptionally(error);
|
||||
return;
|
||||
@ -162,7 +162,7 @@ class ZKAsyncRegistry implements AsyncRegistry {
|
||||
tryComplete(remaining, locs, future);
|
||||
});
|
||||
} else {
|
||||
addListener(getAndConvert(path, ZKAsyncRegistry::getMetaProto), (proto, error) -> {
|
||||
addListener(getAndConvert(path, ZKConnectionRegistry::getMetaProto), (proto, error) -> {
|
||||
if (future.isDone()) {
|
||||
return;
|
||||
}
|
||||
@ -191,7 +191,7 @@ class ZKAsyncRegistry implements AsyncRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
|
||||
CompletableFuture<RegionLocations> future = new CompletableFuture<>();
|
||||
addListener(
|
||||
zk.list(znodePaths.baseZNode)
|
||||
@ -217,8 +217,8 @@ class ZKAsyncRegistry implements AsyncRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ServerName> getMasterAddress() {
|
||||
return getAndConvert(znodePaths.masterAddressZNode, ZKAsyncRegistry::getMasterProto)
|
||||
public CompletableFuture<ServerName> getActiveMaster() {
|
||||
return getAndConvert(znodePaths.masterAddressZNode, ZKConnectionRegistry::getMasterProto)
|
||||
.thenApply(proto -> {
|
||||
if (proto == null) {
|
||||
return null;
|
@ -27,13 +27,13 @@ import org.apache.yetus.audience.InterfaceAudience;
|
||||
* Registry that does nothing. Otherwise, default Registry wants zookeeper up and running.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
class DoNothingAsyncRegistry implements AsyncRegistry {
|
||||
class DoNothingConnectionRegistry implements ConnectionRegistry {
|
||||
|
||||
public DoNothingAsyncRegistry(Configuration conf) {
|
||||
public DoNothingConnectionRegistry(Configuration conf) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class DoNothingAsyncRegistry implements AsyncRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ServerName> getMasterAddress() {
|
||||
public CompletableFuture<ServerName> getActiveMaster() {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class TestAsyncAdminRpcPriority {
|
||||
}).when(adminStub).stopServer(any(HBaseRpcController.class), any(StopServerRequest.class),
|
||||
any());
|
||||
|
||||
conn = new AsyncConnectionImpl(CONF, new DoNothingAsyncRegistry(CONF), "test",
|
||||
conn = new AsyncConnectionImpl(CONF, new DoNothingConnectionRegistry(CONF), "test",
|
||||
UserProvider.instantiate(CONF).getCurrent()) {
|
||||
|
||||
@Override
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* 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
|
||||
@ -43,21 +43,21 @@ public class TestAsyncMetaRegionLocatorFailFast {
|
||||
|
||||
private static AsyncMetaRegionLocator LOCATOR;
|
||||
|
||||
private static final class FaultyAsyncRegistry extends DoNothingAsyncRegistry {
|
||||
private static final class FaultyConnectionRegistry extends DoNothingConnectionRegistry {
|
||||
|
||||
public FaultyAsyncRegistry(Configuration conf) {
|
||||
public FaultyConnectionRegistry(Configuration conf) {
|
||||
super(conf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
|
||||
return FutureUtils.failedFuture(new DoNotRetryRegionException("inject error"));
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
LOCATOR = new AsyncMetaRegionLocator(new FaultyAsyncRegistry(CONF));
|
||||
LOCATOR = new AsyncMetaRegionLocator(new FaultyConnectionRegistry(CONF));
|
||||
}
|
||||
|
||||
@Test(expected = DoNotRetryIOException.class)
|
||||
|
@ -462,7 +462,7 @@ public class TestAsyncProcess {
|
||||
* Returns our async process.
|
||||
*/
|
||||
static class MyConnectionImpl extends ConnectionImplementation {
|
||||
public static class TestRegistry extends DoNothingAsyncRegistry {
|
||||
public static class TestRegistry extends DoNothingConnectionRegistry {
|
||||
|
||||
public TestRegistry(Configuration conf) {
|
||||
super(conf);
|
||||
@ -481,8 +481,8 @@ public class TestAsyncProcess {
|
||||
}
|
||||
|
||||
private static Configuration setupConf(Configuration conf) {
|
||||
conf.setClass(AsyncRegistryFactory.REGISTRY_IMPL_CONF_KEY, TestRegistry.class,
|
||||
AsyncRegistry.class);
|
||||
conf.setClass(ConnectionRegistryFactory.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
|
||||
TestRegistry.class, ConnectionRegistry.class);
|
||||
return conf;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ public class TestAsyncTableRpcPriority {
|
||||
return null;
|
||||
}
|
||||
}).when(stub).get(any(HBaseRpcController.class), any(GetRequest.class), any());
|
||||
conn = new AsyncConnectionImpl(CONF, new DoNothingAsyncRegistry(CONF), "test",
|
||||
conn = new AsyncConnectionImpl(CONF, new DoNothingConnectionRegistry(CONF), "test",
|
||||
UserProvider.instantiate(CONF).getCurrent()) {
|
||||
|
||||
@Override
|
||||
|
@ -58,7 +58,8 @@ public class TestBufferedMutator {
|
||||
public void testAlternateBufferedMutatorImpl() throws IOException {
|
||||
BufferedMutatorParams params = new BufferedMutatorParams(TableName.valueOf(name.getMethodName()));
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
conf.set(AsyncRegistryFactory.REGISTRY_IMPL_CONF_KEY, DoNothingAsyncRegistry.class.getName());
|
||||
conf.set(ConnectionRegistryFactory.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
|
||||
DoNothingConnectionRegistry.class.getName());
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
BufferedMutator bm = connection.getBufferedMutator(params);
|
||||
// Assert we get default BM if nothing specified.
|
||||
|
@ -127,7 +127,7 @@ public class TestClientNoCluster extends Configured implements Tool {
|
||||
/**
|
||||
* Simple cluster registry inserted in place of our usual zookeeper based one.
|
||||
*/
|
||||
static class SimpleRegistry extends DoNothingAsyncRegistry {
|
||||
static class SimpleRegistry extends DoNothingConnectionRegistry {
|
||||
final ServerName META_HOST = META_SERVERNAME;
|
||||
|
||||
public SimpleRegistry(Configuration conf) {
|
||||
@ -135,7 +135,7 @@ public class TestClientNoCluster extends Configured implements Tool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
|
||||
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
|
||||
return CompletableFuture.completedFuture(new RegionLocations(
|
||||
new HRegionLocation(RegionInfoBuilder.FIRST_META_REGIONINFO, META_HOST)));
|
||||
}
|
||||
|
@ -38,17 +38,17 @@ import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category({ ClientTests.class, SmallTests.class })
|
||||
public class TestAsyncRegistryLeak {
|
||||
public class TestConnectionRegistryLeak {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestAsyncRegistryLeak.class);
|
||||
HBaseClassTestRule.forClass(TestConnectionRegistryLeak.class);
|
||||
|
||||
public static final class AsyncRegistryForTest extends DoNothingAsyncRegistry {
|
||||
public static final class ConnectionRegistryForTest extends DoNothingConnectionRegistry {
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
public AsyncRegistryForTest(Configuration conf) {
|
||||
public ConnectionRegistryForTest(Configuration conf) {
|
||||
super(conf);
|
||||
CREATED.add(this);
|
||||
}
|
||||
@ -64,14 +64,14 @@ public class TestAsyncRegistryLeak {
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<AsyncRegistryForTest> CREATED = new ArrayList<>();
|
||||
private static final List<ConnectionRegistryForTest> CREATED = new ArrayList<>();
|
||||
|
||||
private static Configuration CONF = HBaseConfiguration.create();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
CONF.setClass(AsyncRegistryFactory.REGISTRY_IMPL_CONF_KEY, AsyncRegistryForTest.class,
|
||||
AsyncRegistry.class);
|
||||
CONF.setClass(ConnectionRegistryFactory.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
|
||||
ConnectionRegistryForTest.class, ConnectionRegistry.class);
|
||||
}
|
||||
|
||||
@Test
|
@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -90,6 +89,7 @@ public class TestZooKeeperTableArchiveClient {
|
||||
private static RegionServerServices rss;
|
||||
private static DirScanPool POOL;
|
||||
|
||||
|
||||
/**
|
||||
* Setup the config for the cluster
|
||||
*/
|
||||
@ -132,9 +132,13 @@ public class TestZooKeeperTableArchiveClient {
|
||||
|
||||
@AfterClass
|
||||
public static void cleanupTest() throws Exception {
|
||||
CONNECTION.close();
|
||||
if (CONNECTION != null) {
|
||||
CONNECTION.close();
|
||||
}
|
||||
UTIL.shutdownMiniZKCluster();
|
||||
POOL.shutdownNow();
|
||||
if (POOL != null) {
|
||||
POOL.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -338,6 +342,7 @@ public class TestZooKeeperTableArchiveClient {
|
||||
* @throws IOException on failure
|
||||
* @throws KeeperException on failure
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:EmptyBlock")
|
||||
private List<BaseHFileCleanerDelegate> turnOnArchiving(String tableName, HFileCleaner cleaner)
|
||||
throws IOException, KeeperException {
|
||||
// turn on hfile retention
|
||||
|
@ -58,7 +58,8 @@ public abstract class AbstractTestRegionLocator {
|
||||
}
|
||||
UTIL.getAdmin().createTable(td, SPLIT_KEYS);
|
||||
UTIL.waitTableAvailable(TABLE_NAME);
|
||||
try (AsyncRegistry registry = AsyncRegistryFactory.getRegistry(UTIL.getConfiguration())) {
|
||||
try (ConnectionRegistry registry =
|
||||
ConnectionRegistryFactory.getRegistry(UTIL.getConfiguration())) {
|
||||
RegionReplicaTestHelper.waitUntilAllMetaReplicasHavingRegionLocation(UTIL.getConfiguration(),
|
||||
registry, REGION_REPLICATION);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public final class RegionReplicaTestHelper {
|
||||
|
||||
// waits for all replicas to have region location
|
||||
static void waitUntilAllMetaReplicasHavingRegionLocation(Configuration conf,
|
||||
AsyncRegistry registry, int regionReplication) throws IOException {
|
||||
ConnectionRegistry registry, int regionReplication) throws IOException {
|
||||
Waiter.waitFor(conf, conf.getLong("hbase.client.sync.wait.timeout.msec", 60000), 200, true,
|
||||
new ExplainingPredicate<IOException>() {
|
||||
@Override
|
||||
@ -55,7 +55,7 @@ public final class RegionReplicaTestHelper {
|
||||
@Override
|
||||
public boolean evaluate() throws IOException {
|
||||
try {
|
||||
RegionLocations locs = registry.getMetaRegionLocation().get();
|
||||
RegionLocations locs = registry.getMetaRegionLocations().get();
|
||||
if (locs.size() < regionReplication) {
|
||||
return false;
|
||||
}
|
||||
@ -66,7 +66,7 @@ public final class RegionReplicaTestHelper {
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
TestZKAsyncRegistry.LOG.warn("Failed to get meta region locations", e);
|
||||
TestZKConnectionRegistry.LOG.warn("Failed to get meta region locations", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,8 @@ public class TestAsyncAdminWithRegionReplicas extends TestAsyncAdminBase {
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3);
|
||||
TestAsyncAdminBase.setUpBeforeClass();
|
||||
try (AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration())) {
|
||||
try (ConnectionRegistry registry =
|
||||
ConnectionRegistryFactory.getRegistry(TEST_UTIL.getConfiguration())) {
|
||||
RegionReplicaTestHelper
|
||||
.waitUntilAllMetaReplicasHavingRegionLocation(TEST_UTIL.getConfiguration(), registry, 3);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class TestAsyncMetaRegionLocator {
|
||||
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
|
||||
private static AsyncRegistry REGISTRY;
|
||||
private static ConnectionRegistry REGISTRY;
|
||||
|
||||
private static AsyncMetaRegionLocator LOCATOR;
|
||||
|
||||
@ -53,7 +53,7 @@ public class TestAsyncMetaRegionLocator {
|
||||
TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3);
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
TEST_UTIL.waitUntilNoRegionsInTransition();
|
||||
REGISTRY = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
REGISTRY = ConnectionRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
RegionReplicaTestHelper
|
||||
.waitUntilAllMetaReplicasHavingRegionLocation(TEST_UTIL.getConfiguration(), REGISTRY, 3);
|
||||
TEST_UTIL.getAdmin().balancerSwitch(false, true);
|
||||
|
@ -79,7 +79,8 @@ public class TestAsyncNonMetaRegionLocator {
|
||||
public static void setUp() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
TEST_UTIL.getAdmin().balancerSwitch(false, true);
|
||||
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
ConnectionRegistry registry =
|
||||
ConnectionRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
CONN = new AsyncConnectionImpl(TEST_UTIL.getConfiguration(), registry,
|
||||
registry.getClusterId().get(), User.getCurrent());
|
||||
LOCATOR = new AsyncNonMetaRegionLocator(CONN);
|
||||
|
@ -123,7 +123,8 @@ public class TestAsyncNonMetaRegionLocatorConcurrenyLimit {
|
||||
conf.setInt(MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE, MAX_ALLOWED);
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
TEST_UTIL.getAdmin().balancerSwitch(false, true);
|
||||
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
ConnectionRegistry registry =
|
||||
ConnectionRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
CONN = new AsyncConnectionImpl(TEST_UTIL.getConfiguration(), registry,
|
||||
registry.getClusterId().get(), User.getCurrent());
|
||||
LOCATOR = new AsyncNonMetaRegionLocator(CONN);
|
||||
|
@ -98,7 +98,8 @@ public class TestAsyncRegionLocator {
|
||||
TEST_UTIL.startMiniCluster(1);
|
||||
TEST_UTIL.createTable(TABLE_NAME, FAMILY);
|
||||
TEST_UTIL.waitTableAvailable(TABLE_NAME);
|
||||
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
ConnectionRegistry registry =
|
||||
ConnectionRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
CONN = new AsyncConnectionImpl(TEST_UTIL.getConfiguration(), registry,
|
||||
registry.getClusterId().get(), User.getCurrent());
|
||||
LOCATOR = CONN.getLocator();
|
||||
|
@ -71,7 +71,8 @@ public class TestAsyncSingleRequestRpcRetryingCaller {
|
||||
TEST_UTIL.getAdmin().balancerSwitch(false, true);
|
||||
TEST_UTIL.createTable(TABLE_NAME, FAMILY);
|
||||
TEST_UTIL.waitTableAvailable(TABLE_NAME);
|
||||
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
ConnectionRegistry registry =
|
||||
ConnectionRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
CONN = new AsyncConnectionImpl(TEST_UTIL.getConfiguration(), registry,
|
||||
registry.getClusterId().get(), User.getCurrent());
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class TestAsyncTableUseMetaReplicas {
|
||||
conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
|
||||
FailPrimaryMetaScanCp.class.getName());
|
||||
UTIL.startMiniCluster(3);
|
||||
try (AsyncRegistry registry = AsyncRegistryFactory.getRegistry(conf)) {
|
||||
try (ConnectionRegistry registry = ConnectionRegistryFactory.getRegistry(conf)) {
|
||||
RegionReplicaTestHelper.waitUntilAllMetaReplicasHavingRegionLocation(conf, registry, 3);
|
||||
}
|
||||
try (Table table = UTIL.createTable(TABLE_NAME, FAMILY)) {
|
||||
|
@ -53,13 +53,13 @@ public class TestMetaRegionLocationCache {
|
||||
HBaseClassTestRule.forClass(TestMetaRegionLocationCache.class);
|
||||
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static AsyncRegistry REGISTRY;
|
||||
private static ConnectionRegistry REGISTRY;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3);
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REGISTRY = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
REGISTRY = ConnectionRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||
RegionReplicaTestHelper.waitUntilAllMetaReplicasHavingRegionLocation(
|
||||
TEST_UTIL.getConfiguration(), REGISTRY, 3);
|
||||
TEST_UTIL.getAdmin().balancerSwitch(false, true);
|
||||
|
@ -48,16 +48,16 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Category({ MediumTests.class, ClientTests.class })
|
||||
public class TestZKAsyncRegistry {
|
||||
public class TestZKConnectionRegistry {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestZKAsyncRegistry.class);
|
||||
HBaseClassTestRule.forClass(TestZKConnectionRegistry.class);
|
||||
|
||||
static final Logger LOG = LoggerFactory.getLogger(TestZKAsyncRegistry.class);
|
||||
static final Logger LOG = LoggerFactory.getLogger(TestZKConnectionRegistry.class);
|
||||
static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
|
||||
private static ZKAsyncRegistry REGISTRY;
|
||||
private static ZKConnectionRegistry REGISTRY;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@ -67,7 +67,7 @@ public class TestZKAsyncRegistry {
|
||||
// make sure that we do not depend on this config when getting locations for meta replicas, see
|
||||
// HBASE-21658.
|
||||
conf.setInt(META_REPLICAS_NUM, 1);
|
||||
REGISTRY = new ZKAsyncRegistry(conf);
|
||||
REGISTRY = new ZKConnectionRegistry(conf);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@ -84,10 +84,10 @@ public class TestZKAsyncRegistry {
|
||||
assertEquals("Expected " + expectedClusterId + ", found=" + clusterId, expectedClusterId,
|
||||
clusterId);
|
||||
assertEquals(TEST_UTIL.getHBaseCluster().getMaster().getServerName(),
|
||||
REGISTRY.getMasterAddress().get());
|
||||
REGISTRY.getActiveMaster().get());
|
||||
RegionReplicaTestHelper
|
||||
.waitUntilAllMetaReplicasHavingRegionLocation(TEST_UTIL.getConfiguration(), REGISTRY, 3);
|
||||
RegionLocations locs = REGISTRY.getMetaRegionLocation().get();
|
||||
RegionLocations locs = REGISTRY.getMetaRegionLocations().get();
|
||||
assertEquals(3, locs.getRegionLocations().length);
|
||||
IntStream.range(0, 3).forEach(i -> {
|
||||
HRegionLocation loc = locs.getRegionLocation(i);
|
||||
@ -101,8 +101,8 @@ public class TestZKAsyncRegistry {
|
||||
public void testIndependentZKConnections() throws IOException {
|
||||
try (ReadOnlyZKClient zk1 = REGISTRY.getZKClient()) {
|
||||
Configuration otherConf = new Configuration(TEST_UTIL.getConfiguration());
|
||||
otherConf.set(HConstants.ZOOKEEPER_QUORUM, "localhost");
|
||||
try (ZKAsyncRegistry otherRegistry = new ZKAsyncRegistry(otherConf)) {
|
||||
otherConf.set(HConstants.ZOOKEEPER_QUORUM, "127.0.0.1");
|
||||
try (ZKConnectionRegistry otherRegistry = new ZKConnectionRegistry(otherConf)) {
|
||||
ReadOnlyZKClient zk2 = otherRegistry.getZKClient();
|
||||
assertNotSame("Using a different configuration / quorum should result in different " +
|
||||
"backing zk connection.", zk1, zk2);
|
||||
@ -119,9 +119,9 @@ public class TestZKAsyncRegistry {
|
||||
public void testNoMetaAvailable() throws InterruptedException {
|
||||
Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
|
||||
conf.set("zookeeper.znode.metaserver", "whatever");
|
||||
try (ZKAsyncRegistry registry = new ZKAsyncRegistry(conf)) {
|
||||
try (ZKConnectionRegistry registry = new ZKConnectionRegistry(conf)) {
|
||||
try {
|
||||
registry.getMetaRegionLocation().get();
|
||||
registry.getMetaRegionLocations().get();
|
||||
fail("Should have failed since we set an incorrect meta znode prefix");
|
||||
} catch (ExecutionException e) {
|
||||
assertThat(e.getCause(), instanceOf(IOException.class));
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* 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
|
||||
@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.replication.regionserver;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -73,9 +72,7 @@ import org.junit.experimental.categories.Category;
|
||||
import org.junit.rules.TestName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.ByteString;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user