Skip to content

Commit 1907b9b

Browse files
bharathvndimiduk
authored andcommitted
HBASE-23259: Populate master address end points in cluster/rs configs (apache#807)
All the clients need to know the master RPC end points while using master based registry for creating cluster connections. This patch amends the test cluster utility to populate these configs in the base configuration object used to spin up the cluster. The config key added here ("hbase.master.addrs") is used in the subsequent patches for HBASE-18095. Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
1 parent 7e088da commit 1907b9b

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ public enum OperationStatusCode {
176176
/** Configuration key for master web API port */
177177
public static final String MASTER_INFO_PORT = "hbase.master.info.port";
178178

179+
/** Configuration key for the list of master host:ports **/
180+
public static final String MASTER_ADDRS_KEY = "hbase.master.addrs";
181+
182+
public static final String MASTER_ADDRS_DEFAULT = "localhost:" + DEFAULT_MASTER_PORT;
183+
179184
/** Parameter name for the master type being backup (waits for primary to go inactive). */
180185
public static final String MASTER_TYPE_BACKUP = "hbase.master.backup";
181186

hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ public LocalHBaseCluster(final Configuration conf, final int noMasters,
173173
for (int i = 0; i < noMasters; i++) {
174174
addMaster(new Configuration(conf), i);
175175
}
176+
177+
// Populate the master address host ports in the config. This is needed if a master based
178+
// registry is configured for client metadata services (HBASE-18095)
179+
List<String> masterHostPorts = new ArrayList<>();
180+
getMasters().forEach(masterThread ->
181+
masterHostPorts.add(masterThread.getMaster().getServerName().getAddress().toString()));
182+
conf.set(HConstants.MASTER_ADDRS_KEY, String.join(",", masterHostPorts));
183+
176184
// Start the HRegionServers.
177185
this.regionServerClass =
178186
(Class<? extends HRegionServer>)conf.getClass(HConstants.REGION_SERVER_IMPL,
@@ -220,7 +228,7 @@ public JVMClusterUtil.MasterThread addMaster() throws IOException {
220228
}
221229

222230
public JVMClusterUtil.MasterThread addMaster(Configuration c, final int index)
223-
throws IOException {
231+
throws IOException {
224232
// Create each master with its own Configuration instance so each has
225233
// its Connection instance rather than share (see HBASE_INSTANCES down in
226234
// the guts of ConnectionManager.

hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java

Lines changed: 10 additions & 2 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
@@ -447,10 +447,14 @@ public void testOverridingOfDefaultPorts() throws Exception {
447447
HBaseTestingUtility htu = new HBaseTestingUtility(defaultConfig);
448448
try {
449449
MiniHBaseCluster defaultCluster = htu.startMiniCluster();
450+
final String masterHostPort =
451+
defaultCluster.getMaster().getServerName().getAddress().toString();
450452
assertNotEquals(HConstants.DEFAULT_MASTER_INFOPORT,
451453
defaultCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
452454
assertNotEquals(HConstants.DEFAULT_REGIONSERVER_INFOPORT,
453455
defaultCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
456+
assertEquals(masterHostPort,
457+
defaultCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
454458
} finally {
455459
htu.shutdownMiniCluster();
456460
}
@@ -464,10 +468,14 @@ public void testOverridingOfDefaultPorts() throws Exception {
464468
htu = new HBaseTestingUtility(altConfig);
465469
try {
466470
MiniHBaseCluster customCluster = htu.startMiniCluster();
471+
final String masterHostPort =
472+
customCluster.getMaster().getServerName().getAddress().toString();
467473
assertEquals(nonDefaultMasterInfoPort,
468-
customCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
474+
customCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
469475
assertEquals(nonDefaultRegionServerPort,
470476
customCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
477+
assertEquals(masterHostPort,
478+
customCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
471479
} finally {
472480
htu.shutdownMiniCluster();
473481
}

0 commit comments

Comments
 (0)