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 64804a0497
commit 66fb697f81
1 changed files with 10 additions and 4 deletions

View File

@ -135,8 +135,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
@ -439,8 +439,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;
}