diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegistry.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegistry.java index 96329dcfb878..9537777db1ad 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegistry.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegistry.java @@ -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,15 +19,12 @@ import java.io.Closeable; import java.util.concurrent.CompletableFuture; - import org.apache.hadoop.hbase.RegionLocations; 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.. - * All stuffs that may be related to zookeeper at client side are placed here. - *

* Internal use only. */ @InterfaceAudience.Private @@ -45,21 +42,11 @@ interface AsyncRegistry extends Closeable { */ CompletableFuture getClusterId(); - /** - * Get the number of 'running' regionservers. - */ - CompletableFuture getCurrentNrHRS(); - /** * Get the address of HMaster. */ CompletableFuture getMasterAddress(); - /** - * Get the info port of HMaster. - */ - CompletableFuture getMasterInfoPort(); - /** * Closes this instance and releases any system resources associated with it */ diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java index 9b2222b9f429..9968404de2ce 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java @@ -323,10 +323,4 @@ HRegionLocation getRegionLocation(TableName tableName, byte[] row, boolean reloa * supports cell blocks. */ boolean hasCellBlockSupport(); - - /** - * @return the number of region servers that are currently running - * @throws IOException if a remote or network exception occurs - */ - int getCurrentNrHRS() throws IOException; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java index 0164746e64ed..7bdda26e05be 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java @@ -2011,11 +2011,6 @@ public boolean isAborted(){ return this.aborted; } - @Override - public int getCurrentNrHRS() throws IOException { - return get(this.registry.getCurrentNrHRS()); - } - @Override public void close() { if (this.closed) { diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java index 36fa6bba7544..08e3846e39d2 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java @@ -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 @@ -24,7 +24,6 @@ import static org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.lengthOfPBMagic; import static org.apache.hadoop.hbase.util.FutureUtils.addListener; import static org.apache.hadoop.hbase.zookeeper.ZKMetadata.removeMetaData; - import java.io.IOException; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -43,14 +42,12 @@ import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; - import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos; /** - * Fetch the registry data from zookeeper. + * Zookeeper based registry implementation. */ @InterfaceAudience.Private class ZKAsyncRegistry implements AsyncRegistry { @@ -210,11 +207,6 @@ public CompletableFuture getMetaRegionLocation() { return future; } - @Override - public CompletableFuture getCurrentNrHRS() { - return zk.exists(znodePaths.rsZNode).thenApply(s -> s != null ? s.getNumChildren() : 0); - } - private static ZooKeeperProtos.Master getMasterProto(byte[] data) throws IOException { if (data == null || data.length == 0) { return null; @@ -237,12 +229,6 @@ public CompletableFuture getMasterAddress() { }); } - @Override - public CompletableFuture getMasterInfoPort() { - return getAndConvert(znodePaths.masterAddressZNode, ZKAsyncRegistry::getMasterProto) - .thenApply(proto -> proto != null ? proto.getInfoPort() : 0); - } - @Override public void close() { zk.close(); diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/DoNothingAsyncRegistry.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/DoNothingAsyncRegistry.java index 66330687a26a..8c7b07384c72 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/DoNothingAsyncRegistry.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/DoNothingAsyncRegistry.java @@ -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,7 +18,6 @@ package org.apache.hadoop.hbase.client; import java.util.concurrent.CompletableFuture; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.RegionLocations; import org.apache.hadoop.hbase.ServerName; @@ -43,21 +42,11 @@ public CompletableFuture getClusterId() { return CompletableFuture.completedFuture(null); } - @Override - public CompletableFuture getCurrentNrHRS() { - return CompletableFuture.completedFuture(0); - } - @Override public CompletableFuture getMasterAddress() { return CompletableFuture.completedFuture(null); } - @Override - public CompletableFuture getMasterInfoPort() { - return CompletableFuture.completedFuture(0); - } - @Override public void close() { } diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java index 81dcc46f4840..6afe0b59b82e 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java @@ -472,11 +472,6 @@ public TestRegistry(Configuration conf) { public CompletableFuture getClusterId() { return CompletableFuture.completedFuture("testClusterId"); } - - @Override - public CompletableFuture getCurrentNrHRS() { - return CompletableFuture.completedFuture(1); - } } final AtomicInteger nbThreads = new AtomicInteger(0); diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java index c5858bd30df9..19f98f1d8940 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java @@ -144,11 +144,6 @@ public CompletableFuture getMetaRegionLocation() { public CompletableFuture getClusterId() { return CompletableFuture.completedFuture(HConstants.CLUSTER_ID_DEFAULT); } - - @Override - public CompletableFuture getCurrentNrHRS() { - return CompletableFuture.completedFuture(1); - } } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java index a891f6600854..e4b74dfb8a6c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java @@ -787,6 +787,13 @@ public void compact(TableName tableName, boolean major) throws IOException { } } + /** + * @return Number of live region servers in the cluster currently. + */ + public int getNumLiveRegionServers() { + return this.hbaseCluster.getLiveRegionServers().size(); + } + /** * @return List of region server threads. Does not return the master even though it is also * a region server. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java index 52a564432e16..d43dbe060d01 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java @@ -215,7 +215,7 @@ public void testCreateTableWithRegions() throws IOException, InterruptedExceptio assertTrue(Bytes.equals(hri.getStartKey(), splitKeys[8])); assertTrue(hri.getEndKey() == null || hri.getEndKey().length == 0); - verifyRoundRobinDistribution(conn, l, expectedRegions); + verifyRoundRobinDistribution(l, expectedRegions); } // Now test using start/end with a number of regions @@ -272,7 +272,7 @@ public void testCreateTableWithRegions() throws IOException, InterruptedExceptio assertTrue(Bytes.equals(hri.getStartKey(), new byte[] { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 })); assertTrue(hri.getEndKey() == null || hri.getEndKey().length == 0); - verifyRoundRobinDistribution(conn, l, expectedRegions); + verifyRoundRobinDistribution(l, expectedRegions); } // Try once more with something that divides into something infinite @@ -293,7 +293,7 @@ public void testCreateTableWithRegions() throws IOException, InterruptedExceptio expectedRegions, regions.size()); System.err.println("Found " + regions.size() + " regions"); - verifyRoundRobinDistribution(conn, l, expectedRegions); + verifyRoundRobinDistribution(l, expectedRegions); } // Try an invalid case where there are duplicate split keys @@ -342,9 +342,9 @@ public void testCreateTableWithEmptyRowInTheSplitKeys() throws IOException { } } - private void verifyRoundRobinDistribution(ClusterConnection c, RegionLocator regionLocator, - int expectedRegions) throws IOException { - int numRS = c.getCurrentNrHRS(); + private void verifyRoundRobinDistribution(RegionLocator regionLocator, int expectedRegions) + throws IOException { + int numRS = TEST_UTIL.getMiniHBaseCluster().getNumLiveRegionServers(); List regions = regionLocator.getAllRegionLocations(); Map> server2Regions = new HashMap<>(); for (HRegionLocation loc : regions) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java index 01341dedb35d..42d0118ba657 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java @@ -22,8 +22,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -52,7 +50,7 @@ /** * Class to test asynchronous table admin operations. * @see TestAsyncTableAdminApi2 This test and it used to be joined it was taking longer than our - * ten minute timeout so they were split. + * ten minute timeout so they were split. * @see TestAsyncTableAdminApi3 Another split out from this class so each runs under ten minutes. */ @RunWith(Parameterized.class) @@ -268,9 +266,8 @@ public void testCreateTableWithRegions() throws Exception { } } - private void verifyRoundRobinDistribution(List regions, int expectedRegions) - throws IOException { - int numRS = ((ClusterConnection) TEST_UTIL.getConnection()).getCurrentNrHRS(); + private void verifyRoundRobinDistribution(List regions, int expectedRegions) { + int numRS = TEST_UTIL.getMiniHBaseCluster().getNumLiveRegionServers(); Map> server2Regions = new HashMap<>(); regions.stream().forEach((loc) -> { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java index 5a72daea2030..3e4ca94eca98 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java @@ -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 @@ -25,7 +25,6 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; - import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.stream.IntStream; @@ -84,11 +83,8 @@ public void test() throws InterruptedException, ExecutionException, IOException String expectedClusterId = TEST_UTIL.getHBaseCluster().getMaster().getClusterId(); assertEquals("Expected " + expectedClusterId + ", found=" + clusterId, expectedClusterId, clusterId); - assertEquals(TEST_UTIL.getHBaseCluster().getClusterMetrics().getLiveServerMetrics().size(), - REGISTRY.getCurrentNrHRS().get().intValue()); assertEquals(TEST_UTIL.getHBaseCluster().getMaster().getServerName(), REGISTRY.getMasterAddress().get()); - assertEquals(-1, REGISTRY.getMasterInfoPort().get().intValue()); RegionReplicaTestHelper .waitUntilAllMetaReplicasHavingRegionLocation(TEST_UTIL.getConfiguration(), REGISTRY, 3); RegionLocations locs = REGISTRY.getMetaRegionLocation().get();