Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
* <p>
* Internal use only.
*/
@InterfaceAudience.Private
Expand All @@ -45,21 +42,11 @@ interface AsyncRegistry extends Closeable {
*/
CompletableFuture<String> getClusterId();

/**
* Get the number of 'running' regionservers.
*/
CompletableFuture<Integer> getCurrentNrHRS();

/**
* Get the address of HMaster.
*/
CompletableFuture<ServerName> getMasterAddress();

/**
* Get the info port of HMaster.
*/
CompletableFuture<Integer> getMasterInfoPort();

/**
* Closes this instance and releases any system resources associated with it
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -210,11 +207,6 @@ public CompletableFuture<RegionLocations> getMetaRegionLocation() {
return future;
}

@Override
public CompletableFuture<Integer> 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;
Expand All @@ -237,12 +229,6 @@ public CompletableFuture<ServerName> getMasterAddress() {
});
}

@Override
public CompletableFuture<Integer> getMasterInfoPort() {
return getAndConvert(znodePaths.masterAddressZNode, ZKAsyncRegistry::getMasterProto)
.thenApply(proto -> proto != null ? proto.getInfoPort() : 0);
}

@Override
public void close() {
zk.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -43,21 +42,11 @@ public CompletableFuture<String> getClusterId() {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Integer> getCurrentNrHRS() {
return CompletableFuture.completedFuture(0);
}

@Override
public CompletableFuture<ServerName> getMasterAddress() {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Integer> getMasterInfoPort() {
return CompletableFuture.completedFuture(0);
}

@Override
public void close() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,6 @@ public TestRegistry(Configuration conf) {
public CompletableFuture<String> getClusterId() {
return CompletableFuture.completedFuture("testClusterId");
}

@Override
public CompletableFuture<Integer> getCurrentNrHRS() {
return CompletableFuture.completedFuture(1);
}
}

final AtomicInteger nbThreads = new AtomicInteger(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ public CompletableFuture<RegionLocations> getMetaRegionLocation() {
public CompletableFuture<String> getClusterId() {
return CompletableFuture.completedFuture(HConstants.CLUSTER_ID_DEFAULT);
}

@Override
public CompletableFuture<Integer> getCurrentNrHRS() {
return CompletableFuture.completedFuture(1);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<HRegionLocation> regions = regionLocator.getAllRegionLocations();
Map<ServerName, List<RegionInfo>> server2Regions = new HashMap<>();
for (HRegionLocation loc : regions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -268,9 +266,8 @@ public void testCreateTableWithRegions() throws Exception {
}
}

private void verifyRoundRobinDistribution(List<HRegionLocation> regions, int expectedRegions)
throws IOException {
int numRS = ((ClusterConnection) TEST_UTIL.getConnection()).getCurrentNrHRS();
private void verifyRoundRobinDistribution(List<HRegionLocation> regions, int expectedRegions) {
int numRS = TEST_UTIL.getMiniHBaseCluster().getNumLiveRegionServers();

Map<ServerName, List<RegionInfo>> server2Regions = new HashMap<>();
regions.stream().forEach((loc) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down