From 674e5f4c06e967a72c457031e256439b4e158e15 Mon Sep 17 00:00:00 2001 From: haxiaolin Date: Mon, 10 Oct 2022 17:37:48 +0800 Subject: [PATCH] HBASE-27333 Abort RS when the hostname is different from master seen --- .../hbase/regionserver/HRegionServer.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 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 5240df5c62a1..4f6873541cb2 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 @@ -1375,30 +1375,27 @@ protected void handleReportForDutyResponse(final RegionServerStartupResponse c) String hostnameFromMasterPOV = e.getValue(); this.serverName = ServerName.valueOf(hostnameFromMasterPOV, rpcServices.getSocketAddress().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); - } + 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.getSocketAddress().getHostName() + ", but now=" + hostnameFromMasterPOV; + + (StringUtils.isBlank(useThisHostnameInstead) + ? rpcServices.getSocketAddress().getHostName() + : this.useThisHostnameInstead) + + ", but now=" + hostnameFromMasterPOV; LOG.error(msg); + throw new IOException(msg); } continue; }