Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
RSGroupInfoManagerImpl.java
private SortedSet<Address> getDefaultServers() throws IOException { SortedSet<Address> defaultServers = Sets.newTreeSet(); for (ServerName serverName : getOnlineRS()) { Address server = Address.fromParts(serverName.getHostname(), serverName.getPort()); boolean found = false; for (RSGroupInfo rsgi : listRSGroups()) { if (!RSGroupInfo.DEFAULT_GROUP.equals(rsgi.getName()) && rsgi.containsServer(server)) { found = true; break; } } if (!found) { defaultServers.add(server); } } return defaultServers; }
That is a logic of 2 nested loops. And for each server, listRSGroups() allocates a new LinkedList and calls Map#values(), both of which are very heavy operations.
Maybe the inner loop could be moved out, that is
- Build a list of servers of other groups than default group
- Iterate each online servers and check if it is in the list above. If it is not, then it belongs to default group.