You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ha...@apache.org on 2023/03/29 03:42:44 UTC

[hbase] branch branch-2 updated: HBASE-27333 Abort RS when the hostname is different from master seen (#4732) (#5148)

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

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


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 45e34519971 HBASE-27333 Abort RS when the hostname is different from master seen (#4732) (#5148)
45e34519971 is described below

commit 45e34519971e9dea6b0e60eb7f3c9d143271d8ff
Author: Xiaolin Ha <ha...@apache.org>
AuthorDate: Wed Mar 29 11:42:32 2023 +0800

    HBASE-27333 Abort RS when the hostname is different from master seen (#4732) (#5148)
    
    Signed-off-by: Andrew Purtell <ap...@apache.org>
---
 .../hadoop/hbase/regionserver/HRegionServer.java   | 35 ++++++++++------------
 1 file changed, 16 insertions(+), 19 deletions(-)

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 aa8fdebde3b..a7ee222787f 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
@@ -1667,32 +1667,29 @@ public class HRegionServer extends Thread
         // The hostname the master sees us as.
         if (key.equals(HConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER)) {
           String hostnameFromMasterPOV = e.getValue();
-          this.serverName =
-            ServerName.valueOf(hostnameFromMasterPOV, rpcServices.isa.getPort(), this.startcode);
-          if (
-            !StringUtils.isBlank(useThisHostnameInstead)
-              && !hostnameFromMasterPOV.equals(useThisHostnameInstead)
-          ) {
-            String msg = "Master passed us a different hostname to use; was="
-              + this.useThisHostnameInstead + ", but now=" + hostnameFromMasterPOV;
-            LOG.error(msg);
-            throw new IOException(msg);
-          }
+          this.serverName = ServerName.valueOf(hostnameFromMasterPOV,
+            rpcServices.getSocketAddress().getPort(), this.startcode);
+          String expectedHostName = rpcServices.getSocketAddress().getHostName();
           // if Master use-ip is enabled, RegionServer use-ip will be enabled by default even if it
           // is set to disable. so we will use the ip of the RegionServer to compare with the
           // hostname passed by the Master, see HBASE-27304 for details.
-          InetSocketAddress isa = rpcServices.getSocketAddress();
-          // here getActiveMaster() is definitely not null.
-          String isaHostName = InetAddresses.isInetAddress(getActiveMaster().get().getHostname())
-            ? isa.getAddress().getHostAddress()
-            : isa.getHostName();
           if (
-            StringUtils.isBlank(useThisHostnameInstead)
-              && !hostnameFromMasterPOV.equals(isaHostName)
+            StringUtils.isBlank(useThisHostnameInstead) && getActiveMaster().isPresent()
+              && InetAddresses.isInetAddress(getActiveMaster().get().getHostname())
           ) {
+            expectedHostName = rpcServices.getSocketAddress().getAddress().getHostAddress();
+          }
+          boolean isHostnameConsist = StringUtils.isBlank(useThisHostnameInstead)
+            ? hostnameFromMasterPOV.equals(expectedHostName)
+            : hostnameFromMasterPOV.equals(useThisHostnameInstead);
+          if (!isHostnameConsist) {
             String msg = "Master passed us a different hostname to use; was="
-              + rpcServices.isa.getHostName() + ", but now=" + hostnameFromMasterPOV;
+              + (StringUtils.isBlank(useThisHostnameInstead)
+                ? rpcServices.getSocketAddress().getHostName()
+                : this.useThisHostnameInstead)
+              + ", but now=" + hostnameFromMasterPOV;
             LOG.error(msg);
+            throw new IOException(msg);
           }
           continue;
         }