HBASE-22009 Improve RSGroupInfoManagerImpl#getDefaultServers()
Signed-off-by: Xu Cang <xucang@apache.org>
This commit is contained in:
parent
cc55835d03
commit
637764ab7b
@ -596,17 +596,19 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
|
|||||||
|
|
||||||
// Called by ServerEventsListenerThread. Presume it has lock on this manager when it runs.
|
// Called by ServerEventsListenerThread. Presume it has lock on this manager when it runs.
|
||||||
private SortedSet<Address> getDefaultServers() throws IOException {
|
private SortedSet<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
|
||||||
SortedSet<Address> defaultServers = Sets.newTreeSet();
|
SortedSet<Address> defaultServers = Sets.newTreeSet();
|
||||||
for (ServerName serverName : getOnlineRS()) {
|
for (ServerName serverName : getOnlineRS()) {
|
||||||
Address server = Address.fromParts(serverName.getHostname(), serverName.getPort());
|
Address server = Address.fromParts(serverName.getHostname(), serverName.getPort());
|
||||||
boolean found = false;
|
if (!serversInOtherGroup.contains(server)) { // not in other groups
|
||||||
for (RSGroupInfo rsgi : listRSGroups()) {
|
|
||||||
if (!RSGroupInfo.DEFAULT_GROUP.equals(rsgi.getName()) && rsgi.containsServer(server)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
defaultServers.add(server);
|
defaultServers.add(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user