HBASE-22009 Improve RSGroupInfoManagerImpl#getDefaultServers()

Signed-off-by: Xu Cang <xucang@apache.org>
This commit is contained in:
Xiang Li 2019-03-20 07:38:24 +00:00 committed by Xu Cang
parent 1366f5cb6a
commit b9feefbff6
No known key found for this signature in database
GPG Key ID: 8E6C8FEDCA866394
1 changed files with 13 additions and 12 deletions

View File

@ -479,19 +479,20 @@ public class RSGroupInfoManagerImpl implements RSGroupInfoManager, ServerListene
} }
private List<Address> getDefaultServers() throws IOException { private List<Address> getDefaultServers() throws IOException {
List<Address> defaultServers = new LinkedList<Address>(); // Build a list of servers in other groups than default group, from rsGroupMap
for(ServerName server : getOnlineRS()) { Set<Address> serverAddressesInOtherGroups = new HashSet<>();
Address address = Address.fromParts(server.getHostname(), server.getPort()); for (RSGroupInfo group : listRSGroups() /* get from rsGroupMap */) {
boolean found = false; if (!RSGroupInfo.DEFAULT_GROUP.equals(group.getName())) { // not default group
for(RSGroupInfo info : rsGroupMap.values()) { serverAddressesInOtherGroups.addAll(group.getServers());
if(!RSGroupInfo.DEFAULT_GROUP.equals(info.getName()) &&
info.containsServer(address)) {
found = true;
break;
}
} }
if(!found) { }
defaultServers.add(address);
// Get all online servers from Zookeeper and find out servers in default group
List<Address> defaultServers = new LinkedList<Address>();
for (ServerName serverName : getOnlineRS()) {
Address serverAddress = Address.fromParts(serverName.getHostname(), serverName.getPort());
if (!serverAddressesInOtherGroups.contains(serverAddress)) { // not in other groups
defaultServers.add(serverAddress);
} }
} }
return defaultServers; return defaultServers;