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
This commit is contained in:
Michael Stack 2013-08-21 21:42:03 +00:00
parent ed864807e3
commit 1be8cd2c63
3 changed files with 37 additions and 8 deletions

View File

@ -836,10 +836,16 @@ MasterServices, Server {
Set<ServerName> previouslyFailedMetaRSs = getPreviouselyFailedMetaServersFromZK(); Set<ServerName> previouslyFailedMetaRSs = getPreviouselyFailedMetaServersFromZK();
this.initializationBeforeMetaAssignment = true; this.initializationBeforeMetaAssignment = true;
//initialize load balancer
this.balancer.setClusterStatus(getClusterStatus());
this.balancer.setMasterServices(this);
this.balancer.initialize();
// Make sure meta assigned before proceeding. // Make sure meta assigned before proceeding.
status.setStatus("Assigning Meta Region"); status.setStatus("Assigning Meta Region");
assignMeta(status); 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 // assigned when master is shutting down
if(this.stopped) return; if(this.stopped) return;
@ -877,11 +883,11 @@ MasterServices, Server {
org.apache.hadoop.hbase.catalog.MetaMigrationConvertingToPB org.apache.hadoop.hbase.catalog.MetaMigrationConvertingToPB
.updateMetaIfNecessary(this); .updateMetaIfNecessary(this);
this.balancer.setMasterServices(this);
// Fix up assignment manager status // Fix up assignment manager status
status.setStatus("Starting assignment manager"); status.setStatus("Starting assignment manager");
this.assignmentManager.joinCluster(); this.assignmentManager.joinCluster();
//set cluster status again after user regions are assigned
this.balancer.setClusterStatus(getClusterStatus()); this.balancer.setClusterStatus(getClusterStatus());
if (!masterRecovery) { if (!masterRecovery) {
@ -974,7 +980,7 @@ MasterServices, Server {
boolean beingExpired = false; boolean beingExpired = false;
status.setStatus("Assigning META region"); status.setStatus("Assigning META region");
assignmentManager.getRegionStates().createRegionState(HRegionInfo.FIRST_META_REGIONINFO); assignmentManager.getRegionStates().createRegionState(HRegionInfo.FIRST_META_REGIONINFO);
boolean rit = this.assignmentManager boolean rit = this.assignmentManager
.processRegionInTransitionAndBlockUntilAssigned(HRegionInfo.FIRST_META_REGIONINFO); .processRegionInTransitionAndBlockUntilAssigned(HRegionInfo.FIRST_META_REGIONINFO);
@ -1217,11 +1223,11 @@ MasterServices, Server {
public ActiveMasterManager getActiveMasterManager() { public ActiveMasterManager getActiveMasterManager() {
return this.activeMasterManager; return this.activeMasterManager;
} }
public MasterAddressTracker getMasterAddressManager() { public MasterAddressTracker getMasterAddressManager() {
return this.masterAddressManager; return this.masterAddressManager;
} }
/* /*
* Start up all services. If any of these threads gets an unhandled exception * 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 * then they just die with a logged message. This should be fine because
@ -1785,14 +1791,14 @@ MasterServices, Server {
if (getNamespaceDescriptor(namespace) == null) { if (getNamespaceDescriptor(namespace) == null) {
throw new ConstraintException("Namespace " + namespace + " does not exist"); throw new ConstraintException("Namespace " + namespace + " does not exist");
} }
HRegionInfo[] newRegions = getHRegionInfos(hTableDescriptor, splitKeys); HRegionInfo[] newRegions = getHRegionInfos(hTableDescriptor, splitKeys);
checkInitialized(); checkInitialized();
checkCompression(hTableDescriptor); checkCompression(hTableDescriptor);
if (cpHost != null) { if (cpHost != null) {
cpHost.preCreateTable(hTableDescriptor, newRegions); cpHost.preCreateTable(hTableDescriptor, newRegions);
} }
this.executorService.submit(new CreateTableHandler(this, this.executorService.submit(new CreateTableHandler(this,
this.fileSystemManager, hTableDescriptor, conf, this.fileSystemManager, hTableDescriptor, conf,
newRegions, this).prepare()); newRegions, this).prepare());

View File

@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HBaseIOException; import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.Stoppable;
/** /**
* Makes decisions about the placement and movement of Regions across * Makes decisions about the placement and movement of Regions across
@ -45,7 +46,7 @@ import org.apache.hadoop.hbase.ServerName;
* <p>This classes produces plans for the {@link AssignmentManager} to execute. * <p>This classes produces plans for the {@link AssignmentManager} to execute.
*/ */
@InterfaceAudience.Public @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 * 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( ServerName randomAssignment(
HRegionInfo regionInfo, List<ServerName> servers HRegionInfo regionInfo, List<ServerName> servers
) throws HBaseIOException; ) throws HBaseIOException;
/**
* Initialize the load balancer. Must be called after setters.
* @throws HBaseIOException
*/
void initialize() throws HBaseIOException;
} }

View File

@ -33,6 +33,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterStatus; import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.RegionLoad; import org.apache.hadoop.hbase.RegionLoad;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
@ -51,6 +52,7 @@ import com.google.common.collect.Sets;
* *
*/ */
public abstract class BaseLoadBalancer implements LoadBalancer { public abstract class BaseLoadBalancer implements LoadBalancer {
private volatile boolean stopped = false;
/** /**
* An efficient array based implementation similar to ClusterState for keeping * An efficient array based implementation similar to ClusterState for keeping
@ -566,4 +568,18 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
return assignments; 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;
}
} }