Skip to content

Commit cd625c5

Browse files
committed
HBASE-23259: Populate master address end points in cluster/rs configs (#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> (cherry picked from commit 834ccb4)
1 parent eee337f commit cd625c5

3 files changed

Lines changed: 63 additions & 7 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
@@ -175,6 +175,11 @@ public enum OperationStatusCode {
175175
/** Configuration key for master web API port */
176176
public static final String MASTER_INFO_PORT = "hbase.master.info.port";
177177

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

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ public LocalHBaseCluster(final Configuration conf, final int noMasters,
161161
for (int i = 0; i < noMasters; i++) {
162162
addMaster(new Configuration(conf), i);
163163
}
164+
165+
// Populate the master address host ports in the config. This is needed if a master based
166+
// registry is configured for client metadata services (HBASE-18095)
167+
List<String> masterHostPorts = new ArrayList<>();
168+
for (JVMClusterUtil.MasterThread masterThread: getMasters()) {
169+
masterHostPorts.add(masterThread.getMaster().getServerName().getAddress().toString());
170+
}
171+
conf.set(HConstants.MASTER_ADDRS_KEY, String.join(",", masterHostPorts));
172+
164173
// Start the HRegionServers.
165174
this.regionServerClass =
166175
(Class<? extends HRegionServer>)conf.getClass(HConstants.REGION_SERVER_IMPL,
@@ -214,7 +223,7 @@ public JVMClusterUtil.MasterThread addMaster() throws IOException {
214223
}
215224

216225
public JVMClusterUtil.MasterThread addMaster(Configuration c, final int index)
217-
throws IOException {
226+
throws IOException {
218227
// Create each master with its own Configuration instance so each has
219228
// its HConnection instance rather than share (see HBASE_INSTANCES down in
220229
// the guts of HConnectionManager.

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

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/**
2-
*
1+
/*
32
* Licensed to the Apache Software Foundation (ASF) under one
43
* or more contributor license agreements. See the NOTICE file
54
* distributed with this work for additional information
@@ -18,21 +17,19 @@
1817
*/
1918
package org.apache.hadoop.hbase;
2019

21-
2220
import static org.junit.Assert.assertEquals;
2321
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotEquals;
2423
import static org.junit.Assert.assertTrue;
25-
2624
import java.io.File;
2725
import java.io.IOException;
2826
import java.util.HashMap;
2927
import java.util.List;
3028
import java.util.Map;
3129
import java.util.Map.Entry;
32-
import java.util.Random;
33-
3430
import org.apache.commons.logging.Log;
3531
import org.apache.commons.logging.LogFactory;
32+
import org.apache.hadoop.conf.Configuration;
3633
import org.apache.hadoop.fs.FileSystem;
3734
import org.apache.hadoop.fs.FileUtil;
3835
import org.apache.hadoop.fs.Path;
@@ -420,5 +417,50 @@ public void testMiniZooKeeperWithMultipleClientPorts() throws Exception {
420417

421418
hbt.shutdownMiniMapReduceCluster();
422419
}
420+
421+
@Test
422+
public void testOverridingOfDefaultPorts() throws Exception {
423+
// confirm that default port properties being overridden to random
424+
Configuration defaultConfig = HBaseConfiguration.create();
425+
defaultConfig.setInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT);
426+
defaultConfig.setInt(HConstants.REGIONSERVER_INFO_PORT,
427+
HConstants.DEFAULT_REGIONSERVER_INFOPORT);
428+
HBaseTestingUtility htu = new HBaseTestingUtility(defaultConfig);
429+
try {
430+
MiniHBaseCluster defaultCluster = htu.startMiniCluster();
431+
final String masterHostPort =
432+
defaultCluster.getMaster().getServerName().getAddress().toString();
433+
assertNotEquals(HConstants.DEFAULT_MASTER_INFOPORT,
434+
defaultCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
435+
assertNotEquals(HConstants.DEFAULT_REGIONSERVER_INFOPORT,
436+
defaultCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
437+
assertEquals(masterHostPort,
438+
defaultCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
439+
} finally {
440+
htu.shutdownMiniCluster();
441+
}
442+
443+
// confirm that nonDefault (custom) port settings are NOT overridden
444+
Configuration altConfig = HBaseConfiguration.create();
445+
final int nonDefaultMasterInfoPort = 3333;
446+
final int nonDefaultRegionServerPort = 4444;
447+
altConfig.setInt(HConstants.MASTER_INFO_PORT, nonDefaultMasterInfoPort);
448+
altConfig.setInt(HConstants.REGIONSERVER_INFO_PORT, nonDefaultRegionServerPort);
449+
altConfig.setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
450+
htu = new HBaseTestingUtility(altConfig);
451+
try {
452+
MiniHBaseCluster customCluster = htu.startMiniCluster();
453+
final String masterHostPort =
454+
customCluster.getMaster().getServerName().getAddress().toString();
455+
assertEquals(nonDefaultMasterInfoPort,
456+
customCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
457+
assertEquals(nonDefaultRegionServerPort,
458+
customCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
459+
assertEquals(masterHostPort,
460+
customCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
461+
} finally {
462+
htu.shutdownMiniCluster();
463+
}
464+
}
423465
}
424466

0 commit comments

Comments
 (0)