1- From f2360ad266a17eb342eb826ae9dad08d3293b580 Mon Sep 17 00:00:00 2001
1+ From 7014c24f4441278dd366c888fc0c05ce53fe9c06 Mon Sep 17 00:00:00 2001
22From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= <
[email protected] >
33Date: Fri, 30 May 2025 14:26:26 +0200
44Subject: Allow overriding ipc bind port and use alternative port from listener
55
66---
7- .../apache/hadoop/hbase/master/HMaster.java | 11 ++++++--
8- .../hbase/regionserver/HRegionServer.java | 28 +++++++++++++------
9- .../hbase/regionserver/RSRpcServices.java | 4 +--
10- 3 files changed, 30 insertions(+), 13 deletions(-)
7+ .../org/apache/hadoop/hbase/HConstants.java | 21 ++++++++++
8+ .../apache/hadoop/hbase/master/HMaster.java | 20 +++++++--
9+ .../hbase/regionserver/HRegionServer.java | 41 +++++++++++++++----
10+ .../hbase/regionserver/RSRpcServices.java | 8 +++-
11+ 4 files changed, 76 insertions(+), 14 deletions(-)
1112
13+ diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
14+ index 3b2a58827f..1ba1feefcb 100644
15+ --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
16+ +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
17+ @@ -197,6 +197,12 @@ public final class HConstants {
18+ /** Parameter name for port master listens on. */
19+ public static final String MASTER_PORT = "hbase.master.port";
20+
21+ + /** Parameter name for master IPC address */
22+ + public static final String MASTER_IPC_ADDRESS = "hbase.master.ipc.address";
23+ +
24+ + /** Parameter name for master IPC port */
25+ + public static final String MASTER_IPC_PORT = "hbase.master.ipc.port";
26+ +
27+ /** default port that the master listens on */
28+ public static final int DEFAULT_MASTER_PORT = 16000;
29+
30+ @@ -206,6 +212,9 @@ public final class HConstants {
31+ /** Configuration key for master web API port */
32+ public static final String MASTER_INFO_PORT = "hbase.master.info.port";
33+
34+ + /** Configuration key for bound master web API port */
35+ + public static final String MASTER_BOUND_INFO_PORT = "hbase.master.bound.info.port";
36+ +
37+ /** Configuration key for the list of master host:ports **/
38+ public static final String MASTER_ADDRS_KEY = "hbase.masters";
39+
40+ @@ -316,6 +325,12 @@ public final class HConstants {
41+ /** Parameter name for port region server listens on. */
42+ public static final String REGIONSERVER_PORT = "hbase.regionserver.port";
43+
44+ + /** Parameter name for master IPC address */
45+ + public static final String REGIONSERVER_IPC_ADDRESS = "hbase.regionserver.ipc.address";
46+ +
47+ + /** Parameter name for master IPC port */
48+ + public static final String REGIONSERVER_IPC_PORT = "hbase.regionserver.ipc.port";
49+ +
50+ /** Default port region server listens on. */
51+ public static final int DEFAULT_REGIONSERVER_PORT = 16020;
52+
53+ @@ -325,6 +340,9 @@ public final class HConstants {
54+ /** A configuration key for regionserver info port */
55+ public static final String REGIONSERVER_INFO_PORT = "hbase.regionserver.info.port";
56+
57+ + /** A configuration key for bound regionserver hbase info port */
58+ + public static final String REGIONSERVER_BOUND_INFO_PORT = "hbase.regionserver.bound.info.port";
59+ +
60+ /** A flag that enables automatic selection of regionserver info port */
61+ public static final String REGIONSERVER_INFO_PORT_AUTO = REGIONSERVER_INFO_PORT + ".auto";
62+
63+ @@ -1392,6 +1410,9 @@ public final class HConstants {
64+ /** Configuration key for setting RPC codec class name */
65+ public static final String RPC_CODEC_CONF_KEY = "hbase.client.rpc.codec";
66+
67+ + /** Configuration key for setting that the RPC client should specify the host */
68+ + public static final String RPC_CLIENT_SPECIFY_HOST = "hbase.rpc.client.specify.host";
69+ +
70+ /** Configuration key for setting replication codec class name */
71+ public static final String REPLICATION_CODEC_CONF_KEY = "hbase.replication.rpc.codec";
72+
1273diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
13- index 3fe5abac27..6d40db77ae 100644
74+ index 3fe5abac27..2f323518da 100644
1475--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
1576+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
16- @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.master;
77+ @@ -20,6 +20,8 @@ package org.apache.hadoop.hbase.master;
1778 import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_COORDINATED_BY_ZK;
1879 import static org.apache.hadoop.hbase.HConstants.HBASE_MASTER_LOGCLEANER_PLUGINS;
1980 import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK;
81+ + import static org.apache.hadoop.hbase.HConstants.MASTER_BOUND_INFO_PORT;
2082+ import static org.apache.hadoop.hbase.HConstants.MASTER_PORT;
2183 import static org.apache.hadoop.hbase.master.cleaner.HFileCleaner.CUSTOM_POOL_SIZE;
2284 import static org.apache.hadoop.hbase.util.DNS.MASTER_HOSTNAME_KEY;
2385
24- @@ -559,6 +560,11 @@ public class HMaster extends HRegionServer implements MasterServices {
86+ @@ -559,6 +561,18 @@ public class HMaster extends HRegionServer implements MasterServices {
2587 return conf.get(MASTER_HOSTNAME_KEY);
2688 }
2789
@@ -30,21 +92,28 @@ index 3fe5abac27..6d40db77ae 100644
3092+ int port = conf.getInt(MASTER_PORT, 0);
3193+ return port != 0 ? port : this.rpcServices.getSocketAddress().getPort();
3294+ }
95+ +
96+ + @Override
97+ + protected int getUseThisInfoPortInstead(Configuration conf) {
98+ + int port = conf.getInt(MASTER_BOUND_INFO_PORT, 0);
99+ + return port != 0 ? port : this.infoServer != null ? this.infoServer.getPort() : -1;
100+ + }
33101+
34102 private void registerConfigurationObservers() {
35103 configurationManager.registerObserver(this.rpcServices);
36104 configurationManager.registerObserver(this);
37- @@ -586,8 +592,7 @@ public class HMaster extends HRegionServer implements MasterServices {
105+ @@ -586,8 +600,8 @@ public class HMaster extends HRegionServer implements MasterServices {
38106 registerConfigurationObservers();
39107 Threads.setDaemonThreadRunning(new Thread(() -> TraceUtil.trace(() -> {
40108 try {
41- - putUpJettyServer();
109+ - int infoPort = putUpJettyServer();
42110- startActiveMasterManager(infoPort);
111+ + putUpJettyServer();
43112+ startActiveMasterManager(useThisInfoPortInstead);
44113 } catch (Throwable t) {
45114 // Make sure we log the exception.
46115 String error = "Failed to become Active Master";
47- @@ -2991,7 +2996 ,7 @@ public class HMaster extends HRegionServer implements MasterServices {
116+ @@ -2991,7 +3005 ,7 @@ public class HMaster extends HRegionServer implements MasterServices {
48117 }
49118 case MASTER_INFO_PORT: {
50119 if (infoServer != null) {
@@ -54,18 +123,20 @@ index 3fe5abac27..6d40db77ae 100644
54123 break;
55124 }
56125diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
57- index 27bcef2f06..80949070fd 100644
126+ index 27bcef2f06..ff8b3b05f6 100644
58127--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
59128+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
60- @@ -24,6 +24,7 @@ import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_WAL_MAX_SPL
129+ @@ -24,6 +24,9 @@ import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_WAL_MAX_SPL
61130 import static org.apache.hadoop.hbase.HConstants.DEFAULT_SLOW_LOG_SYS_TABLE_CHORE_DURATION;
62131 import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK;
63132 import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER;
133+ + import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_BOUND_INFO_PORT;
64134+ import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_PORT;
135+ + import static org.apache.hadoop.hbase.HConstants.RPC_CLIENT_SPECIFY_HOST;
65136 import static org.apache.hadoop.hbase.master.waleventtracker.WALEventTrackerTableCreator.WAL_EVENT_TRACKER_ENABLED_DEFAULT;
66137 import static org.apache.hadoop.hbase.master.waleventtracker.WALEventTrackerTableCreator.WAL_EVENT_TRACKER_ENABLED_KEY;
67138 import static org.apache.hadoop.hbase.namequeues.NamedQueueServiceChore.NAMED_QUEUE_CHORE_DURATION_DEFAULT;
68- @@ -505,6 +506 ,10 @@ public class HRegionServer extends Thread
139+ @@ -505,6 +508 ,10 @@ public class HRegionServer extends Thread
69140 */
70141 protected String useThisHostnameInstead;
71142
@@ -76,16 +147,16 @@ index 27bcef2f06..80949070fd 100644
76147 /**
77148 * @deprecated since 2.4.0 and will be removed in 4.0.0. Use
78149 * {@link HRegionServer#UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY} instead.
79- @@ -669,6 +674 ,8 @@ public class HRegionServer extends Thread
150+ @@ -669,6 +676 ,8 @@ public class HRegionServer extends Thread
80151 this.namedQueueRecorder = NamedQueueRecorder.getInstance(this.conf);
81152 rpcServices = createRpcServices();
82153 useThisHostnameInstead = getUseThisHostnameInstead(conf);
83154+ useThisPortInstead = getUseThisPortInstead(conf);
84- + useThisInfoPortInstead = conf.getInt("hbase.info.port" , this.infoServer != null ? this.infoServer.getPort() : -1);
155+ + useThisInfoPortInstead = getUseThisInfoPortInstead(conf); // conf.getInt("hbase.info.port" , this.infoServer != null ? this.infoServer.getPort() : -1);
85156
86157 // if use-ip is enabled, we will use ip to expose Master/RS service for client,
87158 // see HBASE-27304 for details.
88- @@ -678,7 +685 ,7 @@ public class HRegionServer extends Thread
159+ @@ -678,7 +687 ,7 @@ public class HRegionServer extends Thread
89160 useIp ? rpcServices.isa.getAddress().getHostAddress() : rpcServices.isa.getHostName();
90161 String hostName =
91162 StringUtils.isBlank(useThisHostnameInstead) ? isaHostName : useThisHostnameInstead;
@@ -94,7 +165,7 @@ index 27bcef2f06..80949070fd 100644
94165
95166 rpcControllerFactory = RpcControllerFactory.instantiate(this.conf);
96167 rpcRetryingCallerFactory = RpcRetryingCallerFactory.instantiate(this.conf,
97- @@ -715,7 +722 ,7 @@ public class HRegionServer extends Thread
168+ @@ -715,7 +724 ,7 @@ public class HRegionServer extends Thread
98169
99170 // Some unit tests don't need a cluster, so no zookeeper at all
100171 // Open connection to zookeeper and set primary watcher
@@ -103,36 +174,54 @@ index 27bcef2f06..80949070fd 100644
103174 canCreateBaseZNode());
104175 // If no master in cluster, skip trying to track one or look for a cluster status.
105176 if (!this.masterless) {
106- @@ -776,6 +783,10 @@ public class HRegionServer extends Thread
177+ @@ -776,6 +785,16 @@ public class HRegionServer extends Thread
107178 }
108179 }
109180
110181+ protected int getUseThisPortInstead(Configuration conf) {
111- + return conf.getInt(REGIONSERVER_PORT, this.rpcServices.isa.getPort());
182+ + int port = conf.getInt(REGIONSERVER_PORT, 0);
183+ + return port != 0 ? port : this.rpcServices.isa.getPort();
184+ + }
185+ +
186+ + protected int getUseThisInfoPortInstead(Configuration conf) {
187+ + int port = conf.getInt(REGIONSERVER_BOUND_INFO_PORT, 0);
188+ + return port != 0 ? port : this.infoServer != null ? this.infoServer.getPort() : -1;
112189+ }
113190+
114191 private void setupSignalHandlers() {
115192 if (!SystemUtils.IS_OS_WINDOWS) {
116193 HBasePlatformDependent.handle("HUP", (number, name) -> {
117- @@ -958,7 +969,7 @@ public class HRegionServer extends Thread
194+ @@ -957,8 +976,7 @@ public class HRegionServer extends Thread
195+ bootstrapNodeManager = new BootstrapNodeManager(clusterConnection, masterAddressTracker);
118196 }
119197 // Setup RPC client for master communication
120- this.rpcClient = RpcClientFactory.createClient(conf, clusterId,
198+ - this.rpcClient = RpcClientFactory.createClient(conf, clusterId,
121199- new InetSocketAddress(this.rpcServices.isa.getAddress(), 0),
122- + new InetSocketAddress(0 ),
200+ + this.rpcClient = RpcClientFactory.createClient(conf, clusterId, getInetSocketAddress(this.conf ),
123201 clusterConnection.getConnectionMetrics(), Collections.emptyMap());
124202 span.setStatus(StatusCode.OK);
125203 } catch (Throwable t) {
126- @@ -1533,6 +1544,8 @@ public class HRegionServer extends Thread
204+ @@ -972,6 +990,11 @@ public class HRegionServer extends Thread
205+ }
206+ }
207+
208+ + private InetSocketAddress getInetSocketAddress(Configuration conf) {
209+ + return conf.getBoolean(RPC_CLIENT_SPECIFY_HOST, false) ?
210+ + new InetSocketAddress(this.rpcServices.isa.getAddress(), 0) : new InetSocketAddress(0);
211+ + }
212+ +
213+ /**
214+ * Bring up connection to zk ensemble and then wait until a master for this cluster and then after
215+ * that, wait until cluster 'up' flag has been set. This is the order in which master does things.
216+ @@ -1533,6 +1556,7 @@ public class HRegionServer extends Thread
127217 } else {
128218 serverLoad.setInfoServerPort(-1);
129219 }
130- + // serverLoad.setInfoServerPort(Integer.parseInt(System.getenv("HBASE_INFO_PORT")));
131220+ serverLoad.setInfoServerPort(useThisInfoPortInstead);
132221 MetricsUserAggregateSource userSource =
133222 metricsRegionServer.getMetricsUserAggregate().getSource();
134223 if (userSource != null) {
135- @@ -1688,7 +1701 ,7 @@ public class HRegionServer extends Thread
224+ @@ -1688,7 +1712 ,7 @@ public class HRegionServer extends Thread
136225 if (key.equals(HConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER)) {
137226 String hostnameFromMasterPOV = e.getValue();
138227 this.serverName = ServerName.valueOf(hostnameFromMasterPOV,
@@ -141,7 +230,7 @@ index 27bcef2f06..80949070fd 100644
141230 String expectedHostName = rpcServices.getSocketAddress().getHostName();
142231 // if Master use-ip is enabled, RegionServer use-ip will be enabled by default even if it
143232 // is set to disable. so we will use the ip of the RegionServer to compare with the
144- @@ -1814,7 +1827 ,7 @@ public class HRegionServer extends Thread
233+ @@ -1814,7 +1838 ,7 @@ public class HRegionServer extends Thread
145234
146235 private void createMyEphemeralNode() throws KeeperException {
147236 RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();
@@ -150,7 +239,7 @@ index 27bcef2f06..80949070fd 100644
150239 rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());
151240 byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());
152241 ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data);
153- @@ -2479,7 +2492 ,7 @@ public class HRegionServer extends Thread
242+ @@ -2479,7 +2503 ,7 @@ public class HRegionServer extends Thread
154243 LOG.info("Retry starting http info server with port: " + port);
155244 }
156245 }
@@ -159,7 +248,7 @@ index 27bcef2f06..80949070fd 100644
159248 conf.setInt(HConstants.REGIONSERVER_INFO_PORT, port);
160249 int masterInfoPort =
161250 conf.getInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT);
162- @@ -3073,12 +3086 ,11 @@ public class HRegionServer extends Thread
251+ @@ -3073,12 +3097 ,11 @@ public class HRegionServer extends Thread
163252 LOG.info("reportForDuty to master=" + masterServerName + " with isa=" + rpcServices.isa
164253 + ", startcode=" + this.startcode);
165254 long now = EnvironmentEdgeManager.currentTime();
@@ -174,23 +263,34 @@ index 27bcef2f06..80949070fd 100644
174263 request.setServerCurrentTime(now);
175264 result = rss.regionServerStartup(null, request.build());
176265diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
177- index b77fcf338a..1f5c9dd21f 100644
266+ index b77fcf338a..a86cd273ff 100644
178267--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
179268+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
180- @@ -1270,14 +1270,14 @@ public class RSRpcServices implements HBaseRPCErrorHandler, AdminService.Blockin
269+ @@ -280,6 +280,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.BulkLoadDescr
270+ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.CompactionDescriptor;
271+ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor;
272+ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.RegionEventDescriptor;
273+ + import static org.apache.hadoop.hbase.HConstants.MASTER_IPC_ADDRESS;
274+ + import static org.apache.hadoop.hbase.HConstants.MASTER_IPC_PORT;
275+ + import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_IPC_ADDRESS;
276+ + import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_IPC_PORT;
277+
278+ /**
279+ * Implements the regionserver RPC services.
280+ @@ -1270,14 +1274,14 @@ public class RSRpcServices implements HBaseRPCErrorHandler, AdminService.Blockin
181281 int port = conf.getInt(HConstants.MASTER_PORT, HConstants.DEFAULT_MASTER_PORT);
182282 // Creation of a HSA will force a resolve.
183283 initialIsa = new InetSocketAddress(hostname, port);
184284- bindAddress = new InetSocketAddress(conf.get("hbase.master.ipc.address", hostname), port);
185- + bindAddress = new InetSocketAddress(conf.get("hbase.master.ipc.address" , hostname), conf.getInt("hbase.master.ipc.port" , port));
285+ + bindAddress = new InetSocketAddress(conf.get(MASTER_IPC_ADDRESS , hostname), conf.getInt(MASTER_IPC_PORT , port));
186286 } else {
187287 String hostname = DNS.getHostname(conf, DNS.ServerType.REGIONSERVER);
188288 int port = conf.getInt(HConstants.REGIONSERVER_PORT, HConstants.DEFAULT_REGIONSERVER_PORT);
189289 // Creation of a HSA will force a resolve.
190290 initialIsa = new InetSocketAddress(hostname, port);
191291 bindAddress =
192292- new InetSocketAddress(conf.get("hbase.regionserver.ipc.address", hostname), port);
193- + new InetSocketAddress(conf.get("hbase.regionserver.ipc.address" , hostname), conf.getInt("hbase.regionserver.ipc.port" , port));
293+ + new InetSocketAddress(conf.get(REGIONSERVER_IPC_ADDRESS , hostname), conf.getInt(REGIONSERVER_IPC_PORT , port));
194294 }
195295 if (initialIsa.getAddress() == null) {
196296 throw new IllegalArgumentException("Failed resolve of " + initialIsa);
0 commit comments