diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java index d30157dd50c..4ee349a59da 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java @@ -137,8 +137,8 @@ public class ServerManager { new ConcurrentSkipListMap>(Bytes.BYTES_COMPARATOR); /** Map of registered servers to their current load */ - private final ConcurrentHashMap onlineServers = - new ConcurrentHashMap(); + private final ConcurrentNavigableMap onlineServers = + new ConcurrentSkipListMap(); /** * 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; }