HBASE-19917 Improve RSGroupBasedLoadBalancer#filterServers() to be more efficient
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
30a7e4a35c
commit
c2e3d52080
|
@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.rsgroup;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -29,6 +28,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.ClusterMetrics;
|
||||
import org.apache.hadoop.hbase.HBaseIOException;
|
||||
|
@ -288,16 +288,20 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer {
|
|||
* List of servers which are online.
|
||||
* @return the list
|
||||
*/
|
||||
private List<ServerName> filterServers(Collection<Address> servers,
|
||||
Collection<ServerName> onlineServers) {
|
||||
ArrayList<ServerName> finalList = new ArrayList<ServerName>();
|
||||
for (Address server : servers) {
|
||||
for(ServerName curr: onlineServers) {
|
||||
if(curr.getAddress().equals(server)) {
|
||||
finalList.add(curr);
|
||||
}
|
||||
private List<ServerName> filterServers(Set<Address> servers,
|
||||
List<ServerName> onlineServers) {
|
||||
/**
|
||||
* servers is actually a TreeSet (see {@link org.apache.hadoop.hbase.rsgroup.RSGroupInfo}),
|
||||
* having its contains()'s time complexity as O(logn), which is good enough.
|
||||
* TODO: consider using HashSet to pursue O(1) for contains() throughout the calling chain
|
||||
* if needed. */
|
||||
ArrayList<ServerName> finalList = new ArrayList<>();
|
||||
for (ServerName onlineServer : onlineServers) {
|
||||
if (servers.contains(onlineServer.getAddress())) {
|
||||
finalList.add(onlineServer);
|
||||
}
|
||||
}
|
||||
|
||||
return finalList;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue