Skip to content

Commit f94d2bc

Browse files
committed
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.
1 parent e41b46c commit f94d2bc

File tree

13 files changed

+33
-32
lines changed

13 files changed

+33
-32
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ AdminService.Interface getAdminStub(ServerName serverName) throws IOException {
257257
CompletableFuture<MasterService.Interface> getMasterStub() {
258258
return ConnectionUtils.getOrFetch(masterStub, masterStubMakeFuture, false, () -> {
259259
CompletableFuture<MasterService.Interface> future = new CompletableFuture<>();
260-
addListener(registry.getMasterAddress(), (addr, error) -> {
260+
addListener(registry.getActiveMaster(), (addr, error) -> {
261261
if (error != null) {
262262
future.completeExceptionally(error);
263263
} else if (addr == null) {
@@ -368,7 +368,7 @@ public Connection toConnection() {
368368
@Override
369369
public CompletableFuture<Hbck> getHbck() {
370370
CompletableFuture<Hbck> future = new CompletableFuture<>();
371-
addListener(registry.getMasterAddress(), (sn, error) -> {
371+
addListener(registry.getActiveMaster(), (sn, error) -> {
372372
if (error != null) {
373373
future.completeExceptionally(error);
374374
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AsyncMetaRegionLocator {
6060
*/
6161
CompletableFuture<RegionLocations> getRegionLocations(int replicaId, boolean reload) {
6262
return ConnectionUtils.getOrFetch(metaRegionLocations, metaRelocateFuture, reload,
63-
registry::getMetaRegionLocation, locs -> isGood(locs, replicaId), "meta region location");
63+
registry::getMetaRegionLocations, locs -> isGood(locs, replicaId), "meta region location");
6464
}
6565

6666
private HRegionLocation getCacheLocation(HRegionLocation loc) {

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

Lines changed: 6 additions & 5 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
3132
interface AsyncRegistry 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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import org.apache.hadoop.hbase.util.ReflectionUtils;
2323

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

30-
static final String REGISTRY_IMPL_CONF_KEY = "hbase.client.registry.impl";
30+
static final String CLIENT_REGISTRY_IMPL_CONF_KEY = "hbase.client.registry.impl";
3131

3232
private AsyncRegistryFactory() {
3333
}
@@ -37,7 +37,7 @@ private AsyncRegistryFactory() {
3737
*/
3838
static AsyncRegistry getRegistry(Configuration conf) {
3939
Class<? extends AsyncRegistry> clazz =
40-
conf.getClass(REGISTRY_IMPL_CONF_KEY, ZKAsyncRegistry.class, AsyncRegistry.class);
40+
conf.getClass(CLIENT_REGISTRY_IMPL_CONF_KEY, ZKAsyncRegistry.class, AsyncRegistry.class);
4141
return ReflectionUtils.newInstance(clazz, conf);
4242
}
4343
}

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/RawAsyncHBaseAdmin.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ public CompletableFuture<Boolean> isTableDisabled(TableName tableName) {
709709
@Override
710710
public CompletableFuture<Boolean> isTableAvailable(TableName tableName) {
711711
if (TableName.isMetaTableName(tableName)) {
712-
return connection.registry.getMetaRegionLocation().thenApply(locs -> Stream
712+
return connection.registry.getMetaRegionLocations().thenApply(locs -> Stream
713713
.of(locs.getRegionLocations()).allMatch(loc -> loc != null && loc.getServerName() != null));
714714
}
715715
CompletableFuture<Boolean> future = new CompletableFuture<>();
@@ -847,7 +847,7 @@ public CompletableFuture<List<RegionInfo>> getRegions(ServerName serverName) {
847847
@Override
848848
public CompletableFuture<List<RegionInfo>> getRegions(TableName tableName) {
849849
if (tableName.equals(META_TABLE_NAME)) {
850-
return connection.registry.getMetaRegionLocation()
850+
return connection.registry.getMetaRegionLocations()
851851
.thenApply(locs -> Stream.of(locs.getRegionLocations()).map(HRegionLocation::getRegion)
852852
.collect(Collectors.toList()));
853853
} else {
@@ -1076,7 +1076,7 @@ private CompletableFuture<List<HRegionLocation>> getTableHRegionLocations(TableN
10761076
CompletableFuture<List<HRegionLocation>> future = new CompletableFuture<>();
10771077
// For meta table, we use zk to fetch all locations.
10781078
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(connection.getConfiguration());
1079-
addListener(registry.getMetaRegionLocation(), (metaRegions, err) -> {
1079+
addListener(registry.getMetaRegionLocations(), (metaRegions, err) -> {
10801080
if (err != null) {
10811081
future.completeExceptionally(err);
10821082
} else if (metaRegions == null || metaRegions.isEmpty() ||
@@ -1104,7 +1104,7 @@ private CompletableFuture<Void> compact(TableName tableName, byte[] columnFamily
11041104

11051105
switch (compactType) {
11061106
case MOB:
1107-
addListener(connection.registry.getMasterAddress(), (serverName, err) -> {
1107+
addListener(connection.registry.getActiveMaster(), (serverName, err) -> {
11081108
if (err != null) {
11091109
future.completeExceptionally(err);
11101110
return;
@@ -2347,7 +2347,7 @@ CompletableFuture<HRegionLocation> getRegionLocation(byte[] regionNameOrEncodedR
23472347
String encodedName = Bytes.toString(regionNameOrEncodedRegionName);
23482348
if (encodedName.length() < RegionInfo.MD5_HEX_LENGTH) {
23492349
// old format encodedName, should be meta region
2350-
future = connection.registry.getMetaRegionLocation()
2350+
future = connection.registry.getMetaRegionLocations()
23512351
.thenApply(locs -> Stream.of(locs.getRegionLocations())
23522352
.filter(loc -> loc.getRegion().getEncodedName().equals(encodedName)).findFirst());
23532353
} else {
@@ -2358,7 +2358,7 @@ CompletableFuture<HRegionLocation> getRegionLocation(byte[] regionNameOrEncodedR
23582358
RegionInfo regionInfo =
23592359
MetaTableAccessor.parseRegionInfoFromRegionName(regionNameOrEncodedRegionName);
23602360
if (regionInfo.isMetaRegion()) {
2361-
future = connection.registry.getMetaRegionLocation()
2361+
future = connection.registry.getMetaRegionLocations()
23622362
.thenApply(locs -> Stream.of(locs.getRegionLocations())
23632363
.filter(loc -> loc.getRegion().getReplicaId() == regionInfo.getReplicaId())
23642364
.findFirst());
@@ -2931,7 +2931,7 @@ public CompletableFuture<CompactionState> getCompactionState(TableName tableName
29312931

29322932
switch (compactType) {
29332933
case MOB:
2934-
addListener(connection.registry.getMasterAddress(), (serverName, err) -> {
2934+
addListener(connection.registry.getActiveMaster(), (serverName, err) -> {
29352935
if (err != null) {
29362936
future.completeExceptionally(err);
29372937
return;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 +217,7 @@ private static ZooKeeperProtos.Master getMasterProto(byte[] data) throws IOExcep
217217
}
218218

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public DoNothingAsyncRegistry(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/TestAsyncMetaRegionLocatorFailFast.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public FaultyAsyncRegistry(Configuration conf) {
5050
}
5151

5252
@Override
53-
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
53+
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
5454
return FutureUtils.failedFuture(new DoNotRetryRegionException("inject error"));
5555
}
5656
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void close() {
7070

7171
@BeforeClass
7272
public static void setUp() {
73-
CONF.setClass(AsyncRegistryFactory.REGISTRY_IMPL_CONF_KEY, AsyncRegistryForTest.class,
73+
CONF.setClass(AsyncRegistryFactory.CLIENT_REGISTRY_IMPL_CONF_KEY, AsyncRegistryForTest.class,
7474
AsyncRegistry.class);
7575
}
7676

hbase-server/src/test/java/org/apache/hadoop/hbase/client/DummyAsyncRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
*/
2828
public class DummyAsyncRegistry implements AsyncRegistry {
2929

30-
public static final String REGISTRY_IMPL_CONF_KEY = AsyncRegistryFactory.REGISTRY_IMPL_CONF_KEY;
30+
public static final String REGISTRY_IMPL_CONF_KEY = AsyncRegistryFactory.CLIENT_REGISTRY_IMPL_CONF_KEY;
3131

3232
@Override
33-
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
33+
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
3434
return null;
3535
}
3636

@@ -40,7 +40,7 @@ public CompletableFuture<String> getClusterId() {
4040
}
4141

4242
@Override
43-
public CompletableFuture<ServerName> getMasterAddress() {
43+
public CompletableFuture<ServerName> getActiveMaster() {
4444
return null;
4545
}
4646

hbase-server/src/test/java/org/apache/hadoop/hbase/client/RegionReplicaTestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public String explainFailure() throws IOException {
5050
@Override
5151
public boolean evaluate() throws IOException {
5252
try {
53-
RegionLocations locs = registry.getMetaRegionLocation().get();
53+
RegionLocations locs = registry.getMetaRegionLocations().get();
5454
if (locs.size() < regionReplication) {
5555
return false;
5656
}

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public void test() throws InterruptedException, ExecutionException, IOException
8484
assertEquals("Expected " + expectedClusterId + ", found=" + clusterId, expectedClusterId,
8585
clusterId);
8686
assertEquals(TEST_UTIL.getHBaseCluster().getMaster().getServerName(),
87-
REGISTRY.getMasterAddress().get());
87+
REGISTRY.getActiveMaster().get());
8888
RegionReplicaTestHelper
8989
.waitUntilAllMetaReplicasHavingRegionLocation(TEST_UTIL.getConfiguration(), REGISTRY, 3);
90-
RegionLocations locs = REGISTRY.getMetaRegionLocation().get();
90+
RegionLocations locs = REGISTRY.getMetaRegionLocations().get();
9191
assertEquals(3, locs.getRegionLocations().length);
9292
IntStream.range(0, 3).forEach(i -> {
9393
HRegionLocation loc = locs.getRegionLocation(i);
@@ -121,7 +121,7 @@ public void testNoMetaAvailable() throws InterruptedException {
121121
conf.set("zookeeper.znode.metaserver", "whatever");
122122
try (ZKAsyncRegistry registry = new ZKAsyncRegistry(conf)) {
123123
try {
124-
registry.getMetaRegionLocation().get();
124+
registry.getMetaRegionLocations().get();
125125
fail("Should have failed since we set an incorrect meta znode prefix");
126126
} catch (ExecutionException e) {
127127
assertThat(e.getCause(), instanceOf(IOException.class));

0 commit comments

Comments
 (0)