From 2caaa14a97e71c1561a0105fbdb44f9ca828e721 Mon Sep 17 00:00:00 2001 From: Thiruvel Thirumoolan Date: Tue, 8 May 2018 14:59:02 -0700 Subject: [PATCH] HBASE-20546 Improve perf of RegionLocationFinder.mapHostNameToServerName --- .../master/balancer/RegionLocationFinder.java | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionLocationFinder.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionLocationFinder.java index 06ab3b5392..d5dfe8c8ac 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionLocationFinder.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionLocationFinder.java @@ -73,6 +73,9 @@ class RegionLocationFinder { // Do not scheduleFullRefresh at master startup private long lastFullRefresh = EnvironmentEdgeManager.currentTime(); + // This is used to lookup host and list of SNs running on that node. + private HashMap> hostToServerName = new HashMap<>(); + private CacheLoader loader = new CacheLoader() { @Override @@ -132,6 +135,14 @@ class RegionLocationFinder { public void setClusterStatus(ClusterStatus status) { long currentTime = EnvironmentEdgeManager.currentTime(); this.status = status; + // Create a mapping from hostname to ServerName for fast lookup during balance + for (ServerName sn : status.getServers()) { + String host = sn.getHostname(); + if (!hostToServerName.containsKey(host)) { + hostToServerName.put(host, new ArrayList()); + } + hostToServerName.get(host).add(sn); + } if (currentTime > lastFullRefresh + (CACHE_TIME / 2)) { // Only count the refresh if it includes user tables ( eg more than meta and namespace ). lastFullRefresh = scheduleFullRefresh()?currentTime:lastFullRefresh; @@ -251,18 +262,6 @@ class RegionLocationFinder { } List topServerNames = new ArrayList(); - Collection regionServers = status.getServers(); - - // create a mapping from hostname to ServerName for fast lookup - HashMap> hostToServerName = new HashMap>(); - for (ServerName sn : regionServers) { - String host = sn.getHostname(); - if (!hostToServerName.containsKey(host)) { - hostToServerName.put(host, new ArrayList()); - } - hostToServerName.get(host).add(sn); - } - for (String host : hosts) { if (!hostToServerName.containsKey(host)) { continue; -- 2.15.1 (Apple Git-101)