HBASE-22009 Improve RSGroupInfoManagerImpl#getDefaultServers()

Signed-off-by: Xu Cang <xucang@apache.org>
This commit is contained in:
Xiang Li 2019-03-18 11:34:44 -07:00 committed by Xu Cang
parent 301bbe1b8e
commit 73f138c302
No known key found for this signature in database
GPG Key ID: 8E6C8FEDCA866394
1 changed files with 9 additions and 9 deletions

View File

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