Skip to content

Commit

Permalink
HBASE-26173 Return only a sub set of region servers as bootstrap nodes (
Browse files Browse the repository at this point in the history
#3599)

Signed-off-by: Bharath Vissapragada <bharathv@apache.org>
  • Loading branch information
Apache9 authored Aug 24, 2021
1 parent d781113 commit 2ce2f93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -320,6 +321,10 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
*/
private static final boolean DEFAULT_REJECT_BATCH_ROWS_OVER_THRESHOLD = false;

public static final String CLIENT_BOOTSTRAP_NODE_LIMIT = "hbase.client.bootstrap.node.limit";

public static final int DEFAULT_CLIENT_BOOTSTRAP_NODE_LIMIT = 10;

// Request counter. (Includes requests that are not serviced by regions.)
// Count only once for requests with multiple actions like multi/caching-scan/replayBatch
final LongAdder requestCount = new LongAdder();
Expand Down Expand Up @@ -4124,8 +4129,12 @@ public GetMetaRegionLocationsResponse getMetaRegionLocations(RpcController contr
@Override
public final GetBootstrapNodesResponse getBootstrapNodes(RpcController controller,
GetBootstrapNodesRequest request) throws ServiceException {
List<ServerName> bootstrapNodes = new ArrayList<>(regionServer.getRegionServers());
Collections.shuffle(bootstrapNodes, ThreadLocalRandom.current());
int maxNodeCount = regionServer.getConfiguration().getInt(CLIENT_BOOTSTRAP_NODE_LIMIT,
DEFAULT_CLIENT_BOOTSTRAP_NODE_LIMIT);
GetBootstrapNodesResponse.Builder builder = GetBootstrapNodesResponse.newBuilder();
regionServer.getRegionServers().stream().map(ProtobufUtil::toServerName)
bootstrapNodes.stream().limit(maxNodeCount).map(ProtobufUtil::toServerName)
.forEach(builder::addServerName);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.regionserver.RSRpcServices;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.After;
Expand Down Expand Up @@ -78,6 +79,15 @@ public void tearDown() throws IOException {
Closeables.close(registry, true);
}

private void setMaxNodeCount(int count) {
UTIL.getMiniHBaseCluster().getMasterThreads().stream()
.map(t -> t.getMaster().getConfiguration())
.forEach(conf -> conf.setInt(RSRpcServices.CLIENT_BOOTSTRAP_NODE_LIMIT, count));
UTIL.getMiniHBaseCluster().getRegionServerThreads().stream()
.map(t -> t.getRegionServer().getConfiguration())
.forEach(conf -> conf.setInt(RSRpcServices.CLIENT_BOOTSTRAP_NODE_LIMIT, count));
}

@Test
public void testRegistryRPCs() throws Exception {
HMaster activeMaster = UTIL.getHBaseCluster().getMaster();
Expand All @@ -99,5 +109,9 @@ public void testRegistryRPCs() throws Exception {
Collections.sort(metaLocations);
Collections.sort(actualMetaLocations);
assertEquals(actualMetaLocations, metaLocations);

// test that the node count config works
setMaxNodeCount(1);
UTIL.waitFor(10000, () -> registry.getParsedServers().size() == 1);
}
}

0 comments on commit 2ce2f93

Please sign in to comment.