From d0a54352e8a4f27adaaa62447d1eef61e45922a7 Mon Sep 17 00:00:00 2001 From: Zach York Date: Thu, 22 Jun 2017 14:12:49 -0700 Subject: [PATCH] HBASE-18478 Allow users to remove RegionFinder from LoadBalancer calculations if no locality possible This provides significant cluster start time reduction for FileSystems which do not surface locality (S3). Signed-off-by: Andrew Purtell --- .../master/balancer/BaseLoadBalancer.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java index 162ba92d49b..ca73ff7ea28 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java @@ -39,6 +39,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterStatus; +import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseIOException; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HDFSBlocksDistribution; @@ -75,7 +76,8 @@ public abstract class BaseLoadBalancer implements LoadBalancer { static final Predicate IDLE_SERVER_PREDICATOR = load -> load.getNumberOfRegions() == 0; - protected final RegionLocationFinder regionFinder = new RegionLocationFinder(); + protected RegionLocationFinder regionFinder; + protected boolean useRegionFinder; private static class DefaultRackManager extends RackManager { @Override @@ -89,6 +91,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer { */ protected BaseLoadBalancer() { metricsBalancer = new MetricsBalancer(); + createRegionFinder(); } /** @@ -97,6 +100,14 @@ public abstract class BaseLoadBalancer implements LoadBalancer { */ protected BaseLoadBalancer(MetricsBalancer metricsBalancer) { this.metricsBalancer = (metricsBalancer != null) ? metricsBalancer : new MetricsBalancer(); + createRegionFinder(); + } + + private void createRegionFinder() { + useRegionFinder = config.getBoolean("hbase.master.balancer.uselocality", true); + if (useRegionFinder) { + regionFinder = new RegionLocationFinder(); + } } /** @@ -990,7 +1001,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer { protected float slop; // overallSlop to control simpleLoadBalancer's cluster level threshold protected float overallSlop; - protected Configuration config; + protected Configuration config = HBaseConfiguration.create(); protected RackManager rackManager; private static final Random RANDOM = new Random(System.currentTimeMillis()); private static final Log LOG = LogFactory.getLog(BaseLoadBalancer.class); @@ -1019,7 +1030,9 @@ public abstract class BaseLoadBalancer implements LoadBalancer { this.tablesOnMaster = true; } this.rackManager = new RackManager(getConf()); - regionFinder.setConf(conf); + if (useRegionFinder) { + regionFinder.setConf(conf); + } // Print out base configs. Don't print overallSlop since it for simple balancer exclusively. LOG.info("slop=" + this.slop + ", tablesOnMaster=" + this.tablesOnMaster + ", systemTablesOnMaster=" + this.onlySystemTablesOnMaster); @@ -1117,7 +1130,9 @@ public abstract class BaseLoadBalancer implements LoadBalancer { @Override public synchronized void setClusterStatus(ClusterStatus st) { this.clusterStatus = st; - regionFinder.setClusterStatus(st); + if (useRegionFinder) { + regionFinder.setClusterStatus(st); + } } @Override @@ -1129,7 +1144,9 @@ public abstract class BaseLoadBalancer implements LoadBalancer { public void setMasterServices(MasterServices masterServices) { masterServerName = masterServices.getServerName(); this.services = masterServices; - this.regionFinder.setServices(masterServices); + if (useRegionFinder) { + this.regionFinder.setServices(masterServices); + } } public void setRackManager(RackManager rackManager) { @@ -1271,7 +1288,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer { protected Cluster createCluster(List servers, Collection regions, boolean forceRefresh) { - if (forceRefresh) { + if (forceRefresh && useRegionFinder) { regionFinder.refreshAndWait(regions); } // Get the snapshot of the current assignments for the regions in question, and then create