1
- From 13bfb4c7799553ecd33f42d9f1da7338c64fa911 Mon Sep 17 00:00:00 2001
1
+ From d8b2c245ad1ee6f79060875cc76049e97f7b459b Mon Sep 17 00:00:00 2001
2
2
From: Andrew Kenworthy <
[email protected] >
3
3
Date: Mon, 16 Jun 2025 14:44:32 +0200
4
4
Subject: Allow overriding ipc bind port and use alternative port from listener
5
5
6
6
---
7
- .../apache/hadoop/hbase/master/HMaster.java | 11 +++++--
8
- .../hbase/regionserver/HRegionServer.java | 32 +++++++++++--------
9
- .../hbase/regionserver/RSRpcServices.java | 4 +--
10
- 3 files changed, 29 insertions(+), 18 deletions(-)
7
+ .../org/apache/hadoop/hbase/HConstants.java | 29 ++++++++++--
8
+ .../apache/hadoop/hbase/master/HMaster.java | 20 +++++++--
9
+ .../hbase/regionserver/HRegionServer.java | 45 +++++++++++++------
10
+ .../hbase/regionserver/RSRpcServices.java | 8 +++-
11
+ 4 files changed, 80 insertions(+), 22 deletions(-)
11
12
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 12f8bc6df0..4d892755d2 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
+ @@ -194,18 +194,27 @@ public final class HConstants {
18
+ /** default host address */
19
+ public static final String DEFAULT_HOST = "0.0.0.0";
20
+
21
+ - /** Parameter name for port master listens on. */
22
+ + /** Parameter name for port master advertises as listening on. */
23
+ public static final String MASTER_PORT = "hbase.master.port";
24
+
25
+ + /** Parameter name for IPC address that master listens on. (Defaults to hostname.) */
26
+ + public static final String MASTER_IPC_ADDRESS = "hbase.master.ipc.address";
27
+ +
28
+ + /** Parameter name for IPC port that master listens on. (Defaults to MASTER_PORT.) */
29
+ + public static final String MASTER_IPC_PORT = "hbase.master.ipc.port";
30
+ +
31
+ /** default port that the master listens on */
32
+ public static final int DEFAULT_MASTER_PORT = 16000;
33
+
34
+ /** default port for master web api */
35
+ public static final int DEFAULT_MASTER_INFOPORT = 16010;
36
+
37
+ - /** Configuration key for master web API port */
38
+ + /** Configuration key for advertised master web API port */
39
+ public static final String MASTER_INFO_PORT = "hbase.master.info.port";
40
+
41
+ + /** Configuration key for bound master web API port. (Defaults to MASTER_INFO_PORT.) */
42
+ + public static final String MASTER_BOUND_INFO_PORT = "hbase.master.bound.info.port";
43
+ +
44
+ /** Configuration key for the list of master host:ports **/
45
+ public static final String MASTER_ADDRS_KEY = "hbase.masters";
46
+
47
+ @@ -313,18 +322,27 @@ public final class HConstants {
48
+ /** Default value for ZooKeeper session timeout */
49
+ public static final int DEFAULT_ZK_SESSION_TIMEOUT = 90 * 1000;
50
+
51
+ - /** Parameter name for port region server listens on. */
52
+ + /** Parameter name for port region server advertises as listening on. */
53
+ public static final String REGIONSERVER_PORT = "hbase.regionserver.port";
54
+
55
+ + /** Parameter name for IPC address that region server listens on. (Defaults to hostname.) */
56
+ + public static final String REGIONSERVER_IPC_ADDRESS = "hbase.regionserver.ipc.address";
57
+ +
58
+ + /** Parameter name for IPC port that region server listens on. (Defaults to REGIONSERVER_PORT.) */
59
+ + public static final String REGIONSERVER_IPC_PORT = "hbase.regionserver.ipc.port";
60
+ +
61
+ /** Default port region server listens on. */
62
+ public static final int DEFAULT_REGIONSERVER_PORT = 16020;
63
+
64
+ /** default port for region server web api */
65
+ public static final int DEFAULT_REGIONSERVER_INFOPORT = 16030;
66
+
67
+ - /** A configuration key for regionserver info port */
68
+ + /** Configuration key for advertised region server web API port */
69
+ public static final String REGIONSERVER_INFO_PORT = "hbase.regionserver.info.port";
70
+
71
+ + /** Configuration key for bound region server web API port. (Defaults to REGIONSERVER_INFO_PORT.) */
72
+ + public static final String REGIONSERVER_BOUND_INFO_PORT = "hbase.regionserver.bound.info.port";
73
+ +
74
+ /** A flag that enables automatic selection of regionserver info port */
75
+ public static final String REGIONSERVER_INFO_PORT_AUTO = REGIONSERVER_INFO_PORT + ".auto";
76
+
77
+ @@ -1397,6 +1415,9 @@ public final class HConstants {
78
+ /** Configuration key for setting RPC codec class name */
79
+ public static final String RPC_CODEC_CONF_KEY = "hbase.client.rpc.codec";
80
+
81
+ + /** Configuration key for setting that the RPC client should bind the client address. This forces outgoing RPC traffic to happen from the same network interface that the RPC server is bound on. */
82
+ + public static final String RPC_CLIENT_BIND_ADDRESS = "hbase.client.rpc.bind.address";
83
+ +
84
+ /** Configuration key for setting replication codec class name */
85
+ public static final String REPLICATION_CODEC_CONF_KEY = "hbase.replication.rpc.codec";
86
+
12
87
diff --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 9cafbb7cbf..8847ddaba0 100644
88
+ index 9cafbb7cbf..313124d1d0 100644
14
89
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
15
90
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
16
- @@ -17,6 +17,7 @@
91
+ @@ -17,6 +17,8 @@
17
92
*/
18
93
package org.apache.hadoop.hbase.master;
19
94
95
+ + import static org.apache.hadoop.hbase.HConstants.MASTER_BOUND_INFO_PORT;
20
96
+ import static org.apache.hadoop.hbase.HConstants.MASTER_PORT;
21
97
import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_COORDINATED_BY_ZK;
22
98
import static org.apache.hadoop.hbase.HConstants.HBASE_MASTER_LOGCLEANER_PLUGINS;
23
99
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK;
24
- @@ -570,6 +571,11 @@ public class HMaster extends HRegionServer implements MasterServices {
100
+ @@ -570,6 +572,18 @@ public class HMaster extends HRegionServer implements MasterServices {
25
101
return conf.get(MASTER_HOSTNAME_KEY);
26
102
}
27
103
28
104
+ @Override
29
105
+ protected int getUseThisPortInstead(Configuration conf) {
30
- + return conf.getInt(MASTER_PORT, this.rpcServices.getSocketAddress().getPort());
106
+ + int port = conf.getInt(MASTER_PORT, 0);
107
+ + return port != 0 ? port : this.rpcServices.getSocketAddress().getPort();
108
+ + }
109
+ +
110
+ + @Override
111
+ + protected int getUseThisInfoPortInstead(Configuration conf) {
112
+ + int port = conf.getInt(MASTER_BOUND_INFO_PORT, 0);
113
+ + return port != 0 ? port : this.infoServer != null ? this.infoServer.getPort() : -1;
31
114
+ }
32
115
+
33
116
private void registerConfigurationObservers() {
34
117
configurationManager.registerObserver(this.rpcServices);
35
118
configurationManager.registerObserver(this);
36
- @@ -597,8 +603,7 @@ public class HMaster extends HRegionServer implements MasterServices {
119
+ @@ -597,8 +611,8 @@ public class HMaster extends HRegionServer implements MasterServices {
37
120
registerConfigurationObservers();
38
121
Threads.setDaemonThreadRunning(new Thread(() -> TraceUtil.trace(() -> {
39
122
try {
40
123
- int infoPort = putUpJettyServer();
41
124
- startActiveMasterManager(infoPort);
125
+ + putUpJettyServer();
42
126
+ startActiveMasterManager(useThisInfoPortInstead);
43
127
} catch (Throwable t) {
44
128
// Make sure we log the exception.
45
129
String error = "Failed to become Active Master";
46
- @@ -3006,7 +3011 ,7 @@ public class HMaster extends HRegionServer implements MasterServices {
130
+ @@ -3006,7 +3020 ,7 @@ public class HMaster extends HRegionServer implements MasterServices {
47
131
}
48
132
case MASTER_INFO_PORT: {
49
133
if (infoServer != null) {
@@ -53,18 +137,20 @@ index 9cafbb7cbf..8847ddaba0 100644
53
137
break;
54
138
}
55
139
diff --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
56
- index 351b4fef19..5237f47fd4 100644
140
+ index 351b4fef19..68f56ab796 100644
57
141
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
58
142
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
59
- @@ -24,6 +24,7 @@ import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_WAL_MAX_SPL
143
+ @@ -24,6 +24,9 @@ import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_WAL_MAX_SPL
60
144
import static org.apache.hadoop.hbase.HConstants.DEFAULT_SLOW_LOG_SYS_TABLE_CHORE_DURATION;
61
145
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK;
62
146
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER;
147
+ + import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_BOUND_INFO_PORT;
63
148
+ import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_PORT;
149
+ + import static org.apache.hadoop.hbase.HConstants.RPC_CLIENT_BIND_ADDRESS;
64
150
import static org.apache.hadoop.hbase.master.waleventtracker.WALEventTrackerTableCreator.WAL_EVENT_TRACKER_ENABLED_DEFAULT;
65
151
import static org.apache.hadoop.hbase.master.waleventtracker.WALEventTrackerTableCreator.WAL_EVENT_TRACKER_ENABLED_KEY;
66
152
import static org.apache.hadoop.hbase.namequeues.NamedQueueServiceChore.NAMED_QUEUE_CHORE_DURATION_DEFAULT;
67
- @@ -505,6 +506 ,10 @@ public class HRegionServer extends Thread
153
+ @@ -505,6 +508 ,10 @@ public class HRegionServer extends Thread
68
154
*/
69
155
protected String useThisHostnameInstead;
70
156
@@ -75,16 +161,16 @@ index 351b4fef19..5237f47fd4 100644
75
161
/**
76
162
* @deprecated since 2.4.0 and will be removed in 4.0.0. Use
77
163
* {@link HRegionServer#UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY} instead.
78
- @@ -669,6 +674 ,8 @@ public class HRegionServer extends Thread
164
+ @@ -669,6 +676 ,8 @@ public class HRegionServer extends Thread
79
165
this.namedQueueRecorder = NamedQueueRecorder.getInstance(this.conf);
80
166
rpcServices = createRpcServices();
81
167
useThisHostnameInstead = getUseThisHostnameInstead(conf);
82
168
+ useThisPortInstead = getUseThisPortInstead(conf);
83
- + useThisInfoPortInstead = conf.getInt("hbase.info.port" , this.infoServer != null ? this.infoServer.getPort() : -1 );
169
+ + useThisInfoPortInstead = getUseThisInfoPortInstead(conf );
84
170
85
171
// if use-ip is enabled, we will use ip to expose Master/RS service for client,
86
172
// see HBASE-27304 for details.
87
- @@ -678,7 +685 ,7 @@ public class HRegionServer extends Thread
173
+ @@ -678,7 +687 ,7 @@ public class HRegionServer extends Thread
88
174
useIp ? rpcServices.isa.getAddress().getHostAddress() : rpcServices.isa.getHostName();
89
175
String hostName =
90
176
StringUtils.isBlank(useThisHostnameInstead) ? isaHostName : useThisHostnameInstead;
@@ -93,7 +179,7 @@ index 351b4fef19..5237f47fd4 100644
93
179
94
180
rpcControllerFactory = RpcControllerFactory.instantiate(this.conf);
95
181
rpcRetryingCallerFactory = RpcRetryingCallerFactory.instantiate(this.conf,
96
- @@ -715,7 +722 ,7 @@ public class HRegionServer extends Thread
182
+ @@ -715,7 +724 ,7 @@ public class HRegionServer extends Thread
97
183
98
184
// Some unit tests don't need a cluster, so no zookeeper at all
99
185
// Open connection to zookeeper and set primary watcher
@@ -102,27 +188,45 @@ index 351b4fef19..5237f47fd4 100644
102
188
canCreateBaseZNode());
103
189
// If no master in cluster, skip trying to track one or look for a cluster status.
104
190
if (!this.masterless) {
105
- @@ -776,6 +783,10 @@ public class HRegionServer extends Thread
191
+ @@ -776,6 +785,16 @@ public class HRegionServer extends Thread
106
192
}
107
193
}
108
194
109
195
+ protected int getUseThisPortInstead(Configuration conf) {
110
- + return conf.getInt(REGIONSERVER_PORT, this.rpcServices.isa.getPort());
196
+ + int port = conf.getInt(REGIONSERVER_PORT, 0);
197
+ + return port != 0 ? port : this.rpcServices.isa.getPort();
198
+ + }
199
+ +
200
+ + protected int getUseThisInfoPortInstead(Configuration conf) {
201
+ + int port = conf.getInt(REGIONSERVER_BOUND_INFO_PORT, 0);
202
+ + return port != 0 ? port : this.infoServer != null ? this.infoServer.getPort() : -1;
111
203
+ }
112
204
+
113
205
private void setupSignalHandlers() {
114
206
if (!SystemUtils.IS_OS_WINDOWS) {
115
207
HBasePlatformDependent.handle("HUP", (number, name) -> {
116
- @@ -958,7 +969 ,7 @@ public class HRegionServer extends Thread
208
+ @@ -958,7 +977 ,7 @@ public class HRegionServer extends Thread
117
209
}
118
210
// Setup RPC client for master communication
119
211
this.rpcClient = RpcClientFactory.createClient(conf, clusterId,
120
212
- new InetSocketAddress(this.rpcServices.isa.getAddress(), 0),
121
- + new InetSocketAddress(0 ),
213
+ + getInetSocketAddress(this.conf ),
122
214
clusterConnection.getConnectionMetrics(), Collections.emptyMap());
123
215
span.setStatus(StatusCode.OK);
124
216
} catch (Throwable t) {
125
- @@ -1528,11 +1539,7 @@ public class HRegionServer extends Thread
217
+ @@ -972,6 +991,11 @@ public class HRegionServer extends Thread
218
+ }
219
+ }
220
+
221
+ + private InetSocketAddress getInetSocketAddress(Configuration conf) {
222
+ + return conf.getBoolean(RPC_CLIENT_BIND_ADDRESS, true) ?
223
+ + new InetSocketAddress(this.rpcServices.isa.getAddress(), 0) : new InetSocketAddress(0);
224
+ + }
225
+ +
226
+ /**
227
+ * Bring up connection to zk ensemble and then wait until a master for this cluster and then after
228
+ * that, wait until cluster 'up' flag has been set. This is the order in which master does things.
229
+ @@ -1528,11 +1552,7 @@ public class HRegionServer extends Thread
126
230
127
231
serverLoad.setReportStartTime(reportStartTime);
128
232
serverLoad.setReportEndTime(reportEndTime);
@@ -135,7 +239,7 @@ index 351b4fef19..5237f47fd4 100644
135
239
MetricsUserAggregateSource userSource =
136
240
metricsRegionServer.getMetricsUserAggregate().getSource();
137
241
if (userSource != null) {
138
- @@ -1688,7 +1695 ,7 @@ public class HRegionServer extends Thread
242
+ @@ -1688,7 +1708 ,7 @@ public class HRegionServer extends Thread
139
243
if (key.equals(HConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER)) {
140
244
String hostnameFromMasterPOV = e.getValue();
141
245
this.serverName = ServerName.valueOf(hostnameFromMasterPOV,
@@ -144,7 +248,7 @@ index 351b4fef19..5237f47fd4 100644
144
248
String expectedHostName = rpcServices.getSocketAddress().getHostName();
145
249
// if Master use-ip is enabled, RegionServer use-ip will be enabled by default even if it
146
250
// is set to disable. so we will use the ip of the RegionServer to compare with the
147
- @@ -1814,7 +1821 ,7 @@ public class HRegionServer extends Thread
251
+ @@ -1814,7 +1834 ,7 @@ public class HRegionServer extends Thread
148
252
149
253
private void createMyEphemeralNode() throws KeeperException {
150
254
RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();
@@ -153,7 +257,7 @@ index 351b4fef19..5237f47fd4 100644
153
257
rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());
154
258
byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());
155
259
ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data);
156
- @@ -2481,7 +2488 ,7 @@ public class HRegionServer extends Thread
260
+ @@ -2481,7 +2501 ,7 @@ public class HRegionServer extends Thread
157
261
LOG.info("Retry starting http info server with port: " + port);
158
262
}
159
263
}
@@ -162,7 +266,7 @@ index 351b4fef19..5237f47fd4 100644
162
266
conf.setInt(HConstants.REGIONSERVER_INFO_PORT, port);
163
267
int masterInfoPort =
164
268
conf.getInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT);
165
- @@ -3075,12 +3082 ,11 @@ public class HRegionServer extends Thread
269
+ @@ -3075,12 +3095 ,11 @@ public class HRegionServer extends Thread
166
270
LOG.info("reportForDuty to master=" + masterServerName + " with isa=" + rpcServices.isa
167
271
+ ", startcode=" + this.startcode);
168
272
long now = EnvironmentEdgeManager.currentTime();
@@ -177,23 +281,34 @@ index 351b4fef19..5237f47fd4 100644
177
281
request.setServerCurrentTime(now);
178
282
result = rss.regionServerStartup(null, request.build());
179
283
diff --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
180
- index b77fcf338a..1f5c9dd21f 100644
284
+ index b77fcf338a..a86cd273ff 100644
181
285
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
182
286
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
183
- @@ -1270,14 +1270,14 @@ public class RSRpcServices implements HBaseRPCErrorHandler, AdminService.Blockin
287
+ @@ -280,6 +280,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.BulkLoadDescr
288
+ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.CompactionDescriptor;
289
+ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.FlushDescriptor;
290
+ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.RegionEventDescriptor;
291
+ + import static org.apache.hadoop.hbase.HConstants.MASTER_IPC_ADDRESS;
292
+ + import static org.apache.hadoop.hbase.HConstants.MASTER_IPC_PORT;
293
+ + import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_IPC_ADDRESS;
294
+ + import static org.apache.hadoop.hbase.HConstants.REGIONSERVER_IPC_PORT;
295
+
296
+ /**
297
+ * Implements the regionserver RPC services.
298
+ @@ -1270,14 +1274,14 @@ public class RSRpcServices implements HBaseRPCErrorHandler, AdminService.Blockin
184
299
int port = conf.getInt(HConstants.MASTER_PORT, HConstants.DEFAULT_MASTER_PORT);
185
300
// Creation of a HSA will force a resolve.
186
301
initialIsa = new InetSocketAddress(hostname, port);
187
302
- bindAddress = new InetSocketAddress(conf.get("hbase.master.ipc.address", hostname), port);
188
- + bindAddress = new InetSocketAddress(conf.get("hbase.master.ipc.address" , hostname), conf.getInt("hbase.master.ipc.port" , port));
303
+ + bindAddress = new InetSocketAddress(conf.get(MASTER_IPC_ADDRESS , hostname), conf.getInt(MASTER_IPC_PORT , port));
189
304
} else {
190
305
String hostname = DNS.getHostname(conf, DNS.ServerType.REGIONSERVER);
191
306
int port = conf.getInt(HConstants.REGIONSERVER_PORT, HConstants.DEFAULT_REGIONSERVER_PORT);
192
307
// Creation of a HSA will force a resolve.
193
308
initialIsa = new InetSocketAddress(hostname, port);
194
309
bindAddress =
195
310
- new InetSocketAddress(conf.get("hbase.regionserver.ipc.address", hostname), port);
196
- + new InetSocketAddress(conf.get("hbase.regionserver.ipc.address" , hostname), conf.getInt("hbase.regionserver.ipc.port" , port));
311
+ + new InetSocketAddress(conf.get(REGIONSERVER_IPC_ADDRESS , hostname), conf.getInt(REGIONSERVER_IPC_PORT , port));
197
312
}
198
313
if (initialIsa.getAddress() == null) {
199
314
throw new IllegalArgumentException("Failed resolve of " + initialIsa);
0 commit comments