From f674be7c57fcf97a9d8a4452a1fd7d5483f9d8c9 Mon Sep 17 00:00:00 2001
From: xiaozhang <issac.zhang@huolala.cn>
Date: Tue, 2 Aug 2022 14:03:16 +0800
Subject: [PATCH] HBASE-27237 The servername in the rsgroup table should be
 lowercase

---
 .../apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java  | 2 +-
 .../hadoop/hbase/rsgroup/RSGroupAdminServiceImpl.java      | 7 ++++---
 .../hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java       | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
index 35c361be562..8a4a97162a9 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
@@ -3416,7 +3416,7 @@ public final class ProtobufUtil {
     RSGroupInfo rsGroupInfo = new RSGroupInfo(proto.getName());
 
     Collection<Address> addresses = proto.getServersList().parallelStream()
-      .map(serverName -> Address.fromParts(serverName.getHostName(), serverName.getPort()))
+      .map(serverName -> Address.fromParts(serverName.getHostName().toLowerCase(Locale.ROOT), serverName.getPort()))
       .collect(Collectors.toList());
     rsGroupInfo.addAllServers(addresses);
 
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServiceImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServiceImpl.java
index 35824fd3633..7e5fefe58d3 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServiceImpl.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServiceImpl.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
@@ -162,7 +163,7 @@ class RSGroupAdminServiceImpl extends RSGroupAdminProtos.RSGroupAdminService {
     MoveServersResponse.Builder builder = MoveServersResponse.newBuilder();
     Set<Address> hostPorts = Sets.newHashSet();
     for (HBaseProtos.ServerName el : request.getServersList()) {
-      hostPorts.add(Address.fromParts(el.getHostName(), el.getPort()));
+      hostPorts.add(Address.fromParts(el.getHostName().toLowerCase(Locale.ROOT), el.getPort()));
     }
     LOG.info(master.getClientIdAuditPrefix() + " move servers " + hostPorts + " to rsgroup "
       + request.getTargetGroup());
@@ -357,7 +358,7 @@ class RSGroupAdminServiceImpl extends RSGroupAdminProtos.RSGroupAdminService {
     MoveServersAndTablesResponse.Builder builder = MoveServersAndTablesResponse.newBuilder();
     Set<Address> hostPorts = Sets.newHashSet();
     for (HBaseProtos.ServerName el : request.getServersList()) {
-      hostPorts.add(Address.fromParts(el.getHostName(), el.getPort()));
+      hostPorts.add(Address.fromParts(el.getHostName().toLowerCase(Locale.ROOT), el.getPort()));
     }
     Set<TableName> tables = new HashSet<>(request.getTableNameList().size());
     for (HBaseProtos.TableName tableName : request.getTableNameList()) {
@@ -388,7 +389,7 @@ class RSGroupAdminServiceImpl extends RSGroupAdminProtos.RSGroupAdminService {
     RemoveServersResponse.Builder builder = RemoveServersResponse.newBuilder();
     Set<Address> servers = Sets.newHashSet();
     for (HBaseProtos.ServerName el : request.getServersList()) {
-      servers.add(Address.fromParts(el.getHostName(), el.getPort()));
+      servers.add(Address.fromParts(el.getHostName().toLowerCase(Locale.ROOT), el.getPort()));
     }
     LOG.info(
       master.getClientIdAuditPrefix() + " remove decommissioned servers from rsgroup: " + servers);
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
index 3b7c30ddb01..f5b5026566e 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
@@ -761,7 +761,7 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
     // Get all online servers from Zookeeper and find out servers in default group
     SortedSet<Address> defaultServers = Sets.newTreeSet();
     for (ServerName serverName : masterServices.getServerManager().getOnlineServers().keySet()) {
-      Address server = Address.fromParts(serverName.getHostname(), serverName.getPort());
+      Address server = Address.fromParts(serverName.getHostnameLowerCase(), serverName.getPort());
       if (!serversInOtherGroup.contains(server)) { // not in other groups
         defaultServers.add(server);
       }