This is an automated email from the ASF dual-hosted git repository.
junegunn pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.5 by this push:
new a5ee5ce133a HBASE-30101 Move login() before RpcServer construction
(#8122) (#8175)
a5ee5ce133a is described below
commit a5ee5ce133aaa83ee50c01e023c91d3d4a41bc0c
Author: Junegunn Choi <[email protected]>
AuthorDate: Fri May 1 19:52:47 2026 +0900
HBASE-30101 Move login() before RpcServer construction (#8122) (#8175)
The RpcServer constructor calls userProvider.getCurrentUserName()
(HBASE-28321) which triggers UserGroupInformation.getCurrentUser().
If the server has not logged in yet, UGI bootstraps from the ticket
cache and spawns a TGT renewer for whichever principal happens to be
there, regardless of the principal the server is configured to use.
Resolve the hostname up front via DNS.getHostname(...) and run the
ZK client and server logins before createRpcServices(), so that UGI
is already bound to the keytab principal by the time the RpcServer
constructor runs.
HRegionServer.getUseThisHostnameInstead() previously fell back to
rpcServices.getSocketAddress().getHostName() when the reverse-DNS
disable flag was set; that branch now uses DNS.getHostname directly
so it no longer depends on rpcServices being constructed.
Signed-off-by: Duo Zhang <[email protected]>
---
.../org/apache/hadoop/hbase/master/HMaster.java | 6 ++++
.../hadoop/hbase/regionserver/HRegionServer.java | 36 +++++++++++++++-------
2 files changed, 31 insertions(+), 11 deletions(-)
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
index 9214dd90d49..e80937e8b1e 100644
--- 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
@@ -225,6 +225,7 @@ import org.apache.hadoop.hbase.trace.TraceUtil;
import org.apache.hadoop.hbase.util.Addressing;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CoprocessorConfigurationUtil;
+import org.apache.hadoop.hbase.util.DNS;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.FSTableDescriptors;
import org.apache.hadoop.hbase.util.HBaseFsck;
@@ -560,6 +561,11 @@ public class HMaster extends HRegionServer implements
MasterServices {
return conf.get(MASTER_HOSTNAME_KEY);
}
+ @Override
+ protected DNS.ServerType getDNSServerType() {
+ return DNS.ServerType.MASTER;
+ }
+
private void registerConfigurationObservers() {
configurationManager.registerObserver(this.rpcServices);
configurationManager.registerObserver(this);
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
index 20f604df130..1342fa690bf 100644
---
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
@@ -174,6 +174,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.CompressionTest;
import org.apache.hadoop.hbase.util.CoprocessorConfigurationUtil;
+import org.apache.hadoop.hbase.util.DNS;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.FSTableDescriptors;
import org.apache.hadoop.hbase.util.FSUtils;
@@ -640,22 +641,23 @@ public class HRegionServer extends Thread
this.stopped = false;
initNamedQueueRecorder(conf);
- rpcServices = createRpcServices();
useThisHostnameInstead = getUseThisHostnameInstead(conf);
- String hostName = StringUtils.isBlank(useThisHostnameInstead)
- ? this.rpcServices.isa.getHostName()
- : this.useThisHostnameInstead;
- serverName = ServerName.valueOf(hostName,
this.rpcServices.isa.getPort(), this.startcode);
-
- rpcControllerFactory = RpcControllerFactory.instantiate(this.conf);
- rpcRetryingCallerFactory =
RpcRetryingCallerFactory.instantiate(this.conf,
- clusterConnection == null ? null :
clusterConnection.getConnectionMetrics());
-
+ // Resolve the hostname up-front and log in before creating the
RpcServer. The RpcServer
+ // constructor reads UserGroupInformation.getCurrentUser()
(HBASE-28321); if the server
+ // has not logged in yet, UGI bootstraps from the ticket cache and
spawns a TGT renewer
+ // for whichever principal happens to be there.
+ String hostName = resolveHostName(conf, useThisHostnameInstead);
// login the zookeeper client principal (if using security)
ZKAuthentication.loginClient(this.conf, HConstants.ZK_CLIENT_KEYTAB_FILE,
HConstants.ZK_CLIENT_KERBEROS_PRINCIPAL, hostName);
// login the server principal (if using secure Hadoop)
login(userProvider, hostName);
+ rpcServices = createRpcServices();
+ serverName = ServerName.valueOf(hostName,
this.rpcServices.isa.getPort(), this.startcode);
+
+ rpcControllerFactory = RpcControllerFactory.instantiate(this.conf);
+ rpcRetryingCallerFactory =
RpcRetryingCallerFactory.instantiate(this.conf,
+ clusterConnection == null ? null :
clusterConnection.getConnectionMetrics());
// init superusers and add the server principal (if using security)
// or process owner as default super user.
Superusers.initialize(conf);
@@ -760,7 +762,7 @@ public class HRegionServer extends Thread
+ UNSAFE_RS_HOSTNAME_KEY + " is used";
throw new IOException(msg);
} else {
- return rpcServices.isa.getHostName();
+ return DNS.getHostname(conf, DNS.ServerType.REGIONSERVER);
}
} else {
return hostname;
@@ -815,6 +817,18 @@ public class HRegionServer extends Thread
!canUpdateTableDescriptor(), cacheTableDescriptor());
}
+ protected DNS.ServerType getDNSServerType() {
+ return DNS.ServerType.REGIONSERVER;
+ }
+
+ private String resolveHostName(Configuration conf, String
useThisHostnameInstead)
+ throws IOException {
+ if (!StringUtils.isBlank(useThisHostnameInstead)) {
+ return useThisHostnameInstead;
+ }
+ return DNS.getHostname(conf, getDNSServerType());
+ }
+
protected void login(UserProvider user, String host) throws IOException {
user.login(SecurityConstants.REGIONSERVER_KRB_KEYTAB_FILE,
SecurityConstants.REGIONSERVER_KRB_PRINCIPAL, host);