This is an automated email from the ASF dual-hosted git repository.

junegunn pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-3 by this push:
     new 154704d2c65 HBASE-30101 Move login() before RpcServer construction 
(#8122) (#8172)
154704d2c65 is described below

commit 154704d2c65b8a23e6dc230fb00eb154091a244b
Author: Junegunn Choi <[email protected]>
AuthorDate: Fri May 1 19:52:04 2026 +0900

    HBASE-30101 Move login() before RpcServer construction (#8122) (#8172)
    
    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/HBaseServerBase.java   | 36 ++++++++++++++--------
 .../org/apache/hadoop/hbase/master/HMaster.java    |  6 ++++
 .../hadoop/hbase/regionserver/HRegionServer.java   |  8 ++++-
 3 files changed, 37 insertions(+), 13 deletions(-)

diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java
index bf9640196f6..5beeceadf06 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java
@@ -69,6 +69,7 @@ import org.apache.hadoop.hbase.trace.TraceUtil;
 import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
 import org.apache.hadoop.hbase.util.Addressing;
 import org.apache.hadoop.hbase.util.CommonFSUtils;
+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.NettyEventLoopGroupConfig;
@@ -254,24 +255,20 @@ public abstract class HBaseServerBase<R extends 
HBaseRpcServicesBase<?>> extends
       this.msgInterval = conf.getInt("hbase.regionserver.msginterval", 3 * 
1000);
       this.sleeper = new Sleeper(this.msgInterval, this);
       this.namedQueueRecorder = createNamedQueueRecord();
-      this.rpcServices = createRpcServices();
       useThisHostnameInstead = getUseThisHostnameInstead(conf);
-      InetSocketAddress addr = rpcServices.getSocketAddress();
-
-      // if use-ip is enabled, we will use ip to expose Master/RS service for 
client,
-      // see HBASE-27304 for details.
-      boolean useIp = 
conf.getBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY,
-        HConstants.HBASE_SERVER_USEIP_ENABLED_DEFAULT);
-      String isaHostName =
-        useIp ? addr.getAddress().getHostAddress() : 
addr.getAddress().getHostName();
-      String hostName =
-        StringUtils.isBlank(useThisHostnameInstead) ? isaHostName : 
useThisHostnameInstead;
-      serverName = ServerName.valueOf(hostName, addr.getPort(), 
this.startcode);
+      // 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);
+      this.rpcServices = createRpcServices();
+      InetSocketAddress addr = rpcServices.getSocketAddress();
+      serverName = ServerName.valueOf(hostName, addr.getPort(), 
this.startcode);
       // init superusers and add the server principal (if using security)
       // or process owner as default super user.
       Superusers.initialize(conf);
@@ -663,6 +660,21 @@ public abstract class HBaseServerBase<R extends 
HBaseRpcServicesBase<?>> extends
 
   protected abstract void login(UserProvider user, String host) throws 
IOException;
 
+  protected abstract DNS.ServerType getDNSServerType();
+
+  private String resolveHostName(Configuration conf, String 
useThisHostnameInstead)
+    throws IOException {
+    if (!StringUtils.isBlank(useThisHostnameInstead)) {
+      return useThisHostnameInstead;
+    }
+    // if use-ip is enabled, we will use ip to expose Master/RS service for 
client,
+    // see HBASE-27304 for details.
+    boolean useIp = conf.getBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY,
+      HConstants.HBASE_SERVER_USEIP_ENABLED_DEFAULT);
+    InetAddress addr = InetAddress.getByName(DNS.getHostname(conf, 
getDNSServerType()));
+    return useIp ? addr.getHostAddress() : addr.getHostName();
+  }
+
   protected abstract NamedQueueRecorder createNamedQueueRecord();
 
   protected abstract void configureInfoServer(InfoServer infoServer);
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 16fc353a1c8..2a78ea867aa 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
@@ -253,6 +253,7 @@ import org.apache.hadoop.hbase.util.Addressing;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.CommonFSUtils;
 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.FutureUtils;
@@ -608,6 +609,11 @@ public class HMaster extends 
HBaseServerBase<MasterRpcServices> implements Maste
     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 5358a118328..672607fe5bc 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
@@ -159,6 +159,7 @@ import org.apache.hadoop.hbase.trace.TraceUtil;
 import org.apache.hadoop.hbase.util.Bytes;
 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.FSUtils;
 import org.apache.hadoop.hbase.util.FutureUtils;
@@ -574,13 +575,18 @@ public class HRegionServer extends 
HBaseServerBase<RSRpcServices>
           + UNSAFE_RS_HOSTNAME_KEY + " is used";
         throw new IOException(msg);
       } else {
-        return rpcServices.getSocketAddress().getHostName();
+        return DNS.getHostname(conf, DNS.ServerType.REGIONSERVER);
       }
     } else {
       return hostname;
     }
   }
 
+  @Override
+  protected DNS.ServerType getDNSServerType() {
+    return DNS.ServerType.REGIONSERVER;
+  }
+
   @Override
   protected void login(UserProvider user, String host) throws IOException {
     user.login(SecurityConstants.REGIONSERVER_KRB_KEYTAB_FILE,

Reply via email to