From 1be8cd2c63a61d7c2071595eb31036552afa2405 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Wed, 21 Aug 2013 21:42:03 +0000 Subject: [PATCH] HBASE-9263 Add initialize method to load balancer interface git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1516310 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/master/HMaster.java | 20 ++++++++++++------- .../hadoop/hbase/master/LoadBalancer.java | 9 ++++++++- .../master/balancer/BaseLoadBalancer.java | 16 +++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index ec878299c16..92a9f0fe9fc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -836,10 +836,16 @@ MasterServices, Server { Set previouslyFailedMetaRSs = getPreviouselyFailedMetaServersFromZK(); this.initializationBeforeMetaAssignment = true; + + //initialize load balancer + this.balancer.setClusterStatus(getClusterStatus()); + this.balancer.setMasterServices(this); + this.balancer.initialize(); + // Make sure meta assigned before proceeding. status.setStatus("Assigning Meta Region"); assignMeta(status); - // check if master is shutting down because above assignMeta could return even META isn't + // check if master is shutting down because above assignMeta could return even META isn't // assigned when master is shutting down if(this.stopped) return; @@ -877,11 +883,11 @@ MasterServices, Server { org.apache.hadoop.hbase.catalog.MetaMigrationConvertingToPB .updateMetaIfNecessary(this); - this.balancer.setMasterServices(this); // Fix up assignment manager status status.setStatus("Starting assignment manager"); this.assignmentManager.joinCluster(); + //set cluster status again after user regions are assigned this.balancer.setClusterStatus(getClusterStatus()); if (!masterRecovery) { @@ -974,7 +980,7 @@ MasterServices, Server { boolean beingExpired = false; status.setStatus("Assigning META region"); - + assignmentManager.getRegionStates().createRegionState(HRegionInfo.FIRST_META_REGIONINFO); boolean rit = this.assignmentManager .processRegionInTransitionAndBlockUntilAssigned(HRegionInfo.FIRST_META_REGIONINFO); @@ -1217,11 +1223,11 @@ MasterServices, Server { public ActiveMasterManager getActiveMasterManager() { return this.activeMasterManager; } - + public MasterAddressTracker getMasterAddressManager() { return this.masterAddressManager; } - + /* * Start up all services. If any of these threads gets an unhandled exception * then they just die with a logged message. This should be fine because @@ -1785,14 +1791,14 @@ MasterServices, Server { if (getNamespaceDescriptor(namespace) == null) { throw new ConstraintException("Namespace " + namespace + " does not exist"); } - + HRegionInfo[] newRegions = getHRegionInfos(hTableDescriptor, splitKeys); checkInitialized(); checkCompression(hTableDescriptor); if (cpHost != null) { cpHost.preCreateTable(hTableDescriptor, newRegions); } - + this.executorService.submit(new CreateTableHandler(this, this.fileSystemManager, hTableDescriptor, conf, newRegions, this).prepare()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java index c843b492f2b..56dd9713715 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.ClusterStatus; import org.apache.hadoop.hbase.HBaseIOException; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.Stoppable; /** * Makes decisions about the placement and movement of Regions across @@ -45,7 +46,7 @@ import org.apache.hadoop.hbase.ServerName; *

This classes produces plans for the {@link AssignmentManager} to execute. */ @InterfaceAudience.Public -public interface LoadBalancer extends Configurable { +public interface LoadBalancer extends Configurable, Stoppable { /** * Set the current cluster status. This allows a LoadBalancer to map host name to a server @@ -110,4 +111,10 @@ public interface LoadBalancer extends Configurable { ServerName randomAssignment( HRegionInfo regionInfo, List servers ) throws HBaseIOException; + + /** + * Initialize the load balancer. Must be called after setters. + * @throws HBaseIOException + */ + void initialize() throws HBaseIOException; } 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 0b50627b09e..22cbe87e130 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 @@ -33,6 +33,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.HBaseIOException; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.RegionLoad; import org.apache.hadoop.hbase.ServerName; @@ -51,6 +52,7 @@ import com.google.common.collect.Sets; * */ public abstract class BaseLoadBalancer implements LoadBalancer { + private volatile boolean stopped = false; /** * An efficient array based implementation similar to ClusterState for keeping @@ -566,4 +568,18 @@ public abstract class BaseLoadBalancer implements LoadBalancer { return assignments; } + @Override + public void initialize() throws HBaseIOException{ + } + + @Override + public boolean isStopped() { + return stopped; + } + + @Override + public void stop(String why) { + LOG.info("Load Balancer stop requested: "+why); + stopped = true; + } }