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