Skip to content

Commit c650f28

Browse files
committed
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 12bb41e)
1 parent 488460e commit c650f28

30 files changed

+117
-104
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class AsyncConnectionImpl implements AsyncConnection {
8383

8484
private final User user;
8585

86-
final AsyncRegistry registry;
86+
final ConnectionRegistry registry;
8787

8888
private final int rpcTimeout;
8989

@@ -118,7 +118,7 @@ class AsyncConnectionImpl implements AsyncConnection {
118118

119119
private final ClusterStatusListener clusterStatusListener;
120120

121-
public AsyncConnectionImpl(Configuration conf, AsyncRegistry registry, String clusterId,
121+
public AsyncConnectionImpl(Configuration conf, ConnectionRegistry registry, String clusterId,
122122
User user) {
123123
this.conf = conf;
124124
this.user = user;
@@ -248,7 +248,7 @@ AdminService.Interface getAdminStub(ServerName serverName) throws IOException {
248248
CompletableFuture<MasterService.Interface> getMasterStub() {
249249
return ConnectionUtils.getOrFetch(masterStub, masterStubMakeFuture, false, () -> {
250250
CompletableFuture<MasterService.Interface> future = new CompletableFuture<>();
251-
addListener(registry.getMasterAddress(), (addr, error) -> {
251+
addListener(registry.getActiveMaster(), (addr, error) -> {
252252
if (error != null) {
253253
future.completeExceptionally(error);
254254
} else if (addr == null) {
@@ -342,7 +342,7 @@ public AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName
342342
@Override
343343
public CompletableFuture<Hbck> getHbck() {
344344
CompletableFuture<Hbck> future = new CompletableFuture<>();
345-
addListener(registry.getMasterAddress(), (sn, error) -> {
345+
addListener(registry.getActiveMaster(), (sn, error) -> {
346346
if (error != null) {
347347
future.completeExceptionally(error);
348348
} else {

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncMetaRegionLocator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
@InterfaceAudience.Private
3737
class AsyncMetaRegionLocator {
3838

39-
private final AsyncRegistry registry;
39+
private final ConnectionRegistry registry;
4040

4141
private final AtomicReference<RegionLocations> metaRegionLocations = new AtomicReference<>();
4242

4343
private final AtomicReference<CompletableFuture<RegionLocations>> metaRelocateFuture =
4444
new AtomicReference<>();
4545

46-
AsyncMetaRegionLocator(AsyncRegistry registry) {
46+
AsyncMetaRegionLocator(ConnectionRegistry registry) {
4747
this.registry = registry;
4848
}
4949

@@ -58,7 +58,7 @@ class AsyncMetaRegionLocator {
5858
*/
5959
CompletableFuture<RegionLocations> getRegionLocations(int replicaId, boolean reload) {
6060
return ConnectionUtils.getOrFetch(metaRegionLocations, metaRelocateFuture, reload,
61-
registry::getMetaRegionLocation, locs -> isGood(locs, replicaId), "meta region location");
61+
registry::getMetaRegionLocations, locs -> isGood(locs, replicaId), "meta region location");
6262
}
6363

6464
private HRegionLocation getCacheLocation(HRegionLocation loc) {

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableRegionLocatorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public CompletableFuture<HRegionLocation> getRegionLocation(byte[] row, int repl
5555
@Override
5656
public CompletableFuture<List<HRegionLocation>> getAllRegionLocations() {
5757
if (TableName.isMetaTableName(tableName)) {
58-
return conn.registry.getMetaRegionLocation()
58+
return conn.registry.getMetaRegionLocations()
5959
.thenApply(locs -> Arrays.asList(locs.getRegionLocations()));
6060
}
6161
return AsyncMetaTableAccessor.getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME),

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public static CompletableFuture<AsyncConnection> createAsyncConnection(Configura
281281
public static CompletableFuture<AsyncConnection> createAsyncConnection(Configuration conf,
282282
final User user) {
283283
CompletableFuture<AsyncConnection> future = new CompletableFuture<>();
284-
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(conf);
284+
ConnectionRegistry registry = ConnectionRegistryFactory.getRegistry(conf);
285285
addListener(registry.getClusterId(), (clusterId, error) -> {
286286
if (error != null) {
287287
registry.close();

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
217217
/**
218218
* Cluster registry of basic info such as clusterid and meta region location.
219219
*/
220-
private final AsyncRegistry registry;
220+
private final ConnectionRegistry registry;
221221

222222
private final ClientBackoffPolicy backoffPolicy;
223223

@@ -303,7 +303,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
303303
this.conf.get(BufferedMutator.CLASSNAME_KEY);
304304

305305
try {
306-
this.registry = AsyncRegistryFactory.getRegistry(conf);
306+
this.registry = ConnectionRegistryFactory.getRegistry(conf);
307307
retrieveClusterId();
308308

309309
this.rpcClient = RpcClientFactory.createClient(this.conf, this.clusterId, this.metrics);
@@ -434,7 +434,7 @@ public Admin getAdmin() throws IOException {
434434

435435
@Override
436436
public Hbck getHbck() throws IOException {
437-
return getHbck(get(registry.getMasterAddress()));
437+
return getHbck(get(registry.getActiveMaster()));
438438
}
439439

440440
@Override
@@ -811,7 +811,7 @@ private RegionLocations locateMeta(final TableName tableName,
811811
}
812812

813813
// Look up from zookeeper
814-
locations = get(this.registry.getMetaRegionLocation());
814+
locations = get(this.registry.getMetaRegionLocations());
815815
if (locations != null) {
816816
cacheLocation(tableName, locations);
817817
}
@@ -1162,7 +1162,7 @@ private void isMasterRunning(MasterProtos.MasterService.BlockingInterface stub)
11621162
*/
11631163
private MasterProtos.MasterService.BlockingInterface makeStubNoRetries()
11641164
throws IOException, KeeperException {
1165-
ServerName sn = get(registry.getMasterAddress());
1165+
ServerName sn = get(registry.getActiveMaster());
11661166
if (sn == null) {
11671167
String msg = "ZooKeeper available but no active master location found";
11681168
LOG.info(msg);
@@ -1211,7 +1211,7 @@ MasterProtos.MasterService.BlockingInterface makeStub() throws IOException {
12111211

12121212
@Override
12131213
public AdminProtos.AdminService.BlockingInterface getAdminForMaster() throws IOException {
1214-
return getAdmin(get(registry.getMasterAddress()));
1214+
return getAdmin(get(registry.getActiveMaster()));
12151215
}
12161216

12171217
@Override

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegistry.java renamed to hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionRegistry.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424
import org.apache.yetus.audience.InterfaceAudience;
2525

2626
/**
27-
* Implementations hold cluster information such as this cluster's id, location of hbase:meta, etc..
27+
* Registry for meta information needed for connection setup to a HBase cluster. Implementations
28+
* hold cluster information such as this cluster's id, location of hbase:meta, etc..
2829
* Internal use only.
2930
*/
3031
@InterfaceAudience.Private
31-
interface AsyncRegistry extends Closeable {
32+
interface ConnectionRegistry extends Closeable {
3233

3334
/**
34-
* Get the location of meta region.
35+
* Get the location of meta region(s).
3536
*/
36-
CompletableFuture<RegionLocations> getMetaRegionLocation();
37+
CompletableFuture<RegionLocations> getMetaRegionLocations();
3738

3839
/**
3940
* Should only be called once.
@@ -43,9 +44,9 @@ interface AsyncRegistry extends Closeable {
4344
CompletableFuture<String> getClusterId();
4445

4546
/**
46-
* Get the address of HMaster.
47+
* Get the address of active HMaster.
4748
*/
48-
CompletableFuture<ServerName> getMasterAddress();
49+
CompletableFuture<ServerName> getActiveMaster();
4950

5051
/**
5152
* Closes this instance and releases any system resources associated with it

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegistryFactory.java renamed to hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionRegistryFactory.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Licensed to the Apache Software Foundation (ASF) under one
33
* or more contributor license agreements. See the NOTICE file
44
* distributed with this work for additional information
@@ -18,26 +18,28 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import org.apache.hadoop.conf.Configuration;
21-
import org.apache.yetus.audience.InterfaceAudience;
2221
import org.apache.hadoop.hbase.util.ReflectionUtils;
22+
import org.apache.yetus.audience.InterfaceAudience;
2323

2424
/**
25-
* Get instance of configured Registry.
25+
* Factory class to get the instance of configured connection registry.
2626
*/
2727
@InterfaceAudience.Private
28-
final class AsyncRegistryFactory {
28+
final class ConnectionRegistryFactory {
2929

30-
static final String REGISTRY_IMPL_CONF_KEY = "hbase.client.registry.impl";
30+
static final String CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY =
31+
"hbase.client.connection.registry.impl";
3132

32-
private AsyncRegistryFactory() {
33+
private ConnectionRegistryFactory() {
3334
}
3435

3536
/**
36-
* @return The cluster registry implementation to use.
37+
* @return The connection registry implementation to use.
3738
*/
38-
static AsyncRegistry getRegistry(Configuration conf) {
39-
Class<? extends AsyncRegistry> clazz =
40-
conf.getClass(REGISTRY_IMPL_CONF_KEY, ZKAsyncRegistry.class, AsyncRegistry.class);
39+
static ConnectionRegistry getRegistry(Configuration conf) {
40+
Class<? extends ConnectionRegistry> clazz = conf.getClass(
41+
CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, ZKConnectionRegistry.class,
42+
ConnectionRegistry.class);
4143
return ReflectionUtils.newInstance(clazz, conf);
4244
}
4345
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public CompletableFuture<Boolean> isTableAvailable(TableName tableName, byte[][]
722722
private CompletableFuture<Boolean> isTableAvailable(TableName tableName,
723723
Optional<byte[][]> splitKeys) {
724724
if (TableName.isMetaTableName(tableName)) {
725-
return connection.registry.getMetaRegionLocation().thenApply(locs -> Stream
725+
return connection.registry.getMetaRegionLocations().thenApply(locs -> Stream
726726
.of(locs.getRegionLocations()).allMatch(loc -> loc != null && loc.getServerName() != null));
727727
}
728728
CompletableFuture<Boolean> future = new CompletableFuture<>();
@@ -882,7 +882,7 @@ public CompletableFuture<List<RegionInfo>> getRegions(ServerName serverName) {
882882
@Override
883883
public CompletableFuture<List<RegionInfo>> getRegions(TableName tableName) {
884884
if (tableName.equals(META_TABLE_NAME)) {
885-
return connection.registry.getMetaRegionLocation()
885+
return connection.registry.getMetaRegionLocations()
886886
.thenApply(locs -> Stream.of(locs.getRegionLocations()).map(HRegionLocation::getRegion)
887887
.collect(Collectors.toList()));
888888
} else {
@@ -1098,8 +1098,9 @@ private CompletableFuture<List<HRegionLocation>> getTableHRegionLocations(TableN
10981098
if (TableName.META_TABLE_NAME.equals(tableName)) {
10991099
CompletableFuture<List<HRegionLocation>> future = new CompletableFuture<>();
11001100
// For meta table, we use zk to fetch all locations.
1101-
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(connection.getConfiguration());
1102-
addListener(registry.getMetaRegionLocation(), (metaRegions, err) -> {
1101+
ConnectionRegistry registry = ConnectionRegistryFactory.getRegistry(
1102+
connection.getConfiguration());
1103+
addListener(registry.getMetaRegionLocations(), (metaRegions, err) -> {
11031104
if (err != null) {
11041105
future.completeExceptionally(err);
11051106
} else if (metaRegions == null || metaRegions.isEmpty() ||
@@ -1127,7 +1128,7 @@ private CompletableFuture<Void> compact(TableName tableName, byte[] columnFamily
11271128

11281129
switch (compactType) {
11291130
case MOB:
1130-
addListener(connection.registry.getMasterAddress(), (serverName, err) -> {
1131+
addListener(connection.registry.getActiveMaster(), (serverName, err) -> {
11311132
if (err != null) {
11321133
future.completeExceptionally(err);
11331134
return;
@@ -2358,7 +2359,7 @@ CompletableFuture<HRegionLocation> getRegionLocation(byte[] regionNameOrEncodedR
23582359
String encodedName = Bytes.toString(regionNameOrEncodedRegionName);
23592360
if (encodedName.length() < RegionInfo.MD5_HEX_LENGTH) {
23602361
// old format encodedName, should be meta region
2361-
future = connection.registry.getMetaRegionLocation()
2362+
future = connection.registry.getMetaRegionLocations()
23622363
.thenApply(locs -> Stream.of(locs.getRegionLocations())
23632364
.filter(loc -> loc.getRegion().getEncodedName().equals(encodedName)).findFirst());
23642365
} else {
@@ -2369,7 +2370,7 @@ CompletableFuture<HRegionLocation> getRegionLocation(byte[] regionNameOrEncodedR
23692370
RegionInfo regionInfo =
23702371
MetaTableAccessor.parseRegionInfoFromRegionName(regionNameOrEncodedRegionName);
23712372
if (regionInfo.isMetaRegion()) {
2372-
future = connection.registry.getMetaRegionLocation()
2373+
future = connection.registry.getMetaRegionLocations()
23732374
.thenApply(locs -> Stream.of(locs.getRegionLocations())
23742375
.filter(loc -> loc.getRegion().getReplicaId() == regionInfo.getReplicaId())
23752376
.findFirst());
@@ -2942,7 +2943,7 @@ public CompletableFuture<CompactionState> getCompactionState(TableName tableName
29422943

29432944
switch (compactType) {
29442945
case MOB:
2945-
addListener(connection.registry.getMasterAddress(), (serverName, err) -> {
2946+
addListener(connection.registry.getActiveMaster(), (serverName, err) -> {
29462947
if (err != null) {
29472948
future.completeExceptionally(err);
29482949
return;

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java renamed to hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKConnectionRegistry.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@
5050
* Zookeeper based registry implementation.
5151
*/
5252
@InterfaceAudience.Private
53-
class ZKAsyncRegistry implements AsyncRegistry {
53+
class ZKConnectionRegistry implements ConnectionRegistry {
5454

55-
private static final Logger LOG = LoggerFactory.getLogger(ZKAsyncRegistry.class);
55+
private static final Logger LOG = LoggerFactory.getLogger(ZKConnectionRegistry.class);
5656

5757
private final ReadOnlyZKClient zk;
5858

5959
private final ZNodePaths znodePaths;
6060

61-
ZKAsyncRegistry(Configuration conf) {
61+
ZKConnectionRegistry(Configuration conf) {
6262
this.znodePaths = new ZNodePaths(conf);
6363
this.zk = new ReadOnlyZKClient(conf);
6464
}
@@ -93,7 +93,7 @@ private static String getClusterId(byte[] data) throws DeserializationException
9393

9494
@Override
9595
public CompletableFuture<String> getClusterId() {
96-
return getAndConvert(znodePaths.clusterIdZNode, ZKAsyncRegistry::getClusterId);
96+
return getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId);
9797
}
9898

9999
@VisibleForTesting
@@ -144,7 +144,7 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
144144
int replicaId = znodePaths.getMetaReplicaIdFromZnode(metaReplicaZNode);
145145
String path = ZNodePaths.joinZNode(znodePaths.baseZNode, metaReplicaZNode);
146146
if (replicaId == DEFAULT_REPLICA_ID) {
147-
addListener(getAndConvert(path, ZKAsyncRegistry::getMetaProto), (proto, error) -> {
147+
addListener(getAndConvert(path, ZKConnectionRegistry::getMetaProto), (proto, error) -> {
148148
if (error != null) {
149149
future.completeExceptionally(error);
150150
return;
@@ -162,7 +162,7 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
162162
tryComplete(remaining, locs, future);
163163
});
164164
} else {
165-
addListener(getAndConvert(path, ZKAsyncRegistry::getMetaProto), (proto, error) -> {
165+
addListener(getAndConvert(path, ZKConnectionRegistry::getMetaProto), (proto, error) -> {
166166
if (future.isDone()) {
167167
return;
168168
}
@@ -191,7 +191,7 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
191191
}
192192

193193
@Override
194-
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
194+
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
195195
CompletableFuture<RegionLocations> future = new CompletableFuture<>();
196196
addListener(
197197
zk.list(znodePaths.baseZNode)
@@ -217,8 +217,8 @@ private static ZooKeeperProtos.Master getMasterProto(byte[] data) throws IOExcep
217217
}
218218

219219
@Override
220-
public CompletableFuture<ServerName> getMasterAddress() {
221-
return getAndConvert(znodePaths.masterAddressZNode, ZKAsyncRegistry::getMasterProto)
220+
public CompletableFuture<ServerName> getActiveMaster() {
221+
return getAndConvert(znodePaths.masterAddressZNode, ZKConnectionRegistry::getMasterProto)
222222
.thenApply(proto -> {
223223
if (proto == null) {
224224
return null;

hbase-client/src/test/java/org/apache/hadoop/hbase/client/DoNothingAsyncRegistry.java renamed to hbase-client/src/test/java/org/apache/hadoop/hbase/client/DoNothingConnectionRegistry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
* Registry that does nothing. Otherwise, default Registry wants zookeeper up and running.
2828
*/
2929
@InterfaceAudience.Private
30-
class DoNothingAsyncRegistry implements AsyncRegistry {
30+
class DoNothingConnectionRegistry implements ConnectionRegistry {
3131

32-
public DoNothingAsyncRegistry(Configuration conf) {
32+
public DoNothingConnectionRegistry(Configuration conf) {
3333
}
3434

3535
@Override
36-
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
36+
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
3737
return CompletableFuture.completedFuture(null);
3838
}
3939

@@ -43,7 +43,7 @@ public CompletableFuture<String> getClusterId() {
4343
}
4444

4545
@Override
46-
public CompletableFuture<ServerName> getMasterAddress() {
46+
public CompletableFuture<ServerName> getActiveMaster() {
4747
return CompletableFuture.completedFuture(null);
4848
}
4949

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncAdminRpcPriority.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
142142
}).when(adminStub).stopServer(any(HBaseRpcController.class), any(StopServerRequest.class),
143143
any());
144144

145-
conn = new AsyncConnectionImpl(CONF, new DoNothingAsyncRegistry(CONF), "test",
145+
conn = new AsyncConnectionImpl(CONF, new DoNothingConnectionRegistry(CONF), "test",
146146
UserProvider.instantiate(CONF).getCurrent()) {
147147

148148
@Override

0 commit comments

Comments
 (0)