HBASE-16275 Change ServerManager#onlineServers from ConcurrentHashMap to ConcurrentSkipListMap (Huaxiang Sun)

This commit is contained in:
Matteo Bertozzi 2016-07-28 11:13:58 -07:00
parent 968e464aed
commit 7983d2f45b
1 changed files with 10 additions and 4 deletions

View File

@ -137,8 +137,8 @@ public class ServerManager {
new ConcurrentSkipListMap<byte[], ConcurrentNavigableMap<byte[], Long>>(Bytes.BYTES_COMPARATOR);
/** Map of registered servers to their current load */
private final ConcurrentHashMap<ServerName, ServerLoad> onlineServers =
new ConcurrentHashMap<ServerName, ServerLoad>();
private final ConcurrentNavigableMap<ServerName, ServerLoad> onlineServers =
new ConcurrentSkipListMap<ServerName, ServerLoad>();
/**
* Map of admin interfaces per registered regionserver; these interfaces we use to control
@ -449,8 +449,14 @@ public class ServerManager {
*/
private ServerName findServerWithSameHostnamePortWithLock(
final ServerName serverName) {
for (ServerName sn: this.onlineServers.keySet()) {
if (ServerName.isSameHostnameAndPort(serverName, sn)) return sn;
ServerName end = ServerName.valueOf(serverName.getHostname(), serverName.getPort(),
Long.MAX_VALUE);
ServerName r = onlineServers.lowerKey(end);
if (r != null) {
if (ServerName.isSameHostnameAndPort(r, serverName)) {
return r;
}
}
return null;
}