org.apache.hadoop.hbase.master.balancer
Class BaseLoadBalancer

java.lang.Object
  extended by org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
All Implemented Interfaces:
org.apache.hadoop.conf.Configurable, LoadBalancer
Direct Known Subclasses:
DefaultLoadBalancer, FavoredNodeLoadBalancer, StochasticLoadBalancer

public abstract class BaseLoadBalancer
extends Object
implements LoadBalancer

The base class for load balancers. It provides the the functions used to by AssignmentManager to assign regions in the edge cases. It doesn't provide an implementation of the actual balancing algorithm.


Nested Class Summary
protected static class BaseLoadBalancer.Cluster
          An efficient array based implementation similar to ClusterState for keeping the status of the cluster in terms of region assignment and distribution.
 
Field Summary
protected  MasterServices services
           
 
Constructor Summary
BaseLoadBalancer()
           
 
Method Summary
 org.apache.hadoop.conf.Configuration getConf()
           
 Map<HRegionInfo,ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers)
          Generates an immediate assignment plan to be used by a new master for regions in transition that do not have an already known destination.
protected  boolean needsBalance(ClusterLoadState cs)
           
 ServerName randomAssignment(HRegionInfo regionInfo, List<ServerName> servers)
          Used to assign a single region to a random server.
 Map<ServerName,List<HRegionInfo>> retainAssignment(Map<HRegionInfo,ServerName> regions, List<ServerName> servers)
          Generates a bulk assignment startup plan, attempting to reuse the existing assignment information from META, but adjusting for the specified list of available/online servers available for assignment.
 Map<ServerName,List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions, List<ServerName> servers)
          Generates a bulk assignment plan to be used on cluster startup using a simple round-robin assignment.
 void setClusterStatus(ClusterStatus st)
          Set the current cluster status.
 void setConf(org.apache.hadoop.conf.Configuration conf)
           
 void setMasterServices(MasterServices masterServices)
          Set the master service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
balanceCluster
 

Field Detail

services

protected MasterServices services
Constructor Detail

BaseLoadBalancer

public BaseLoadBalancer()
Method Detail

setConf

public void setConf(org.apache.hadoop.conf.Configuration conf)
Specified by:
setConf in interface org.apache.hadoop.conf.Configurable

getConf

public org.apache.hadoop.conf.Configuration getConf()
Specified by:
getConf in interface org.apache.hadoop.conf.Configurable

setClusterStatus

public void setClusterStatus(ClusterStatus st)
Description copied from interface: LoadBalancer
Set the current cluster status. This allows a LoadBalancer to map host name to a server

Specified by:
setClusterStatus in interface LoadBalancer

setMasterServices

public void setMasterServices(MasterServices masterServices)
Description copied from interface: LoadBalancer
Set the master service.

Specified by:
setMasterServices in interface LoadBalancer

needsBalance

protected boolean needsBalance(ClusterLoadState cs)

roundRobinAssignment

public Map<ServerName,List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions,
                                                              List<ServerName> servers)
Generates a bulk assignment plan to be used on cluster startup using a simple round-robin assignment.

Takes a list of all the regions and all the servers in the cluster and returns a map of each server to the regions that it should be assigned.

Currently implemented as a round-robin assignment. Same invariant as load balancing, all servers holding floor(avg) or ceiling(avg). TODO: Use block locations from HDFS to place regions with their blocks

Specified by:
roundRobinAssignment in interface LoadBalancer
Parameters:
regions - all regions
servers - all servers
Returns:
map of server to the regions it should take, or null if no assignment is possible (ie. no regions or no servers)

immediateAssignment

public Map<HRegionInfo,ServerName> immediateAssignment(List<HRegionInfo> regions,
                                                       List<ServerName> servers)
Generates an immediate assignment plan to be used by a new master for regions in transition that do not have an already known destination. Takes a list of regions that need immediate assignment and a list of all available servers. Returns a map of regions to the server they should be assigned to. This method will return quickly and does not do any intelligent balancing. The goal is to make a fast decision not the best decision possible. Currently this is random.

Specified by:
immediateAssignment in interface LoadBalancer
Parameters:
regions -
servers -
Returns:
map of regions to the server it should be assigned to

randomAssignment

public ServerName randomAssignment(HRegionInfo regionInfo,
                                   List<ServerName> servers)
Used to assign a single region to a random server.

Specified by:
randomAssignment in interface LoadBalancer
Parameters:
regionInfo - Region for which this selection is being done.
Returns:
Servername

retainAssignment

public Map<ServerName,List<HRegionInfo>> retainAssignment(Map<HRegionInfo,ServerName> regions,
                                                          List<ServerName> servers)
Generates a bulk assignment startup plan, attempting to reuse the existing assignment information from META, but adjusting for the specified list of available/online servers available for assignment.

Takes a map of all regions to their existing assignment from META. Also takes a list of online servers for regions to be assigned to. Attempts to retain all assignment, so in some instances initial assignment will not be completely balanced.

Any leftover regions without an existing server to be assigned to will be assigned randomly to available servers.

Specified by:
retainAssignment in interface LoadBalancer
Parameters:
regions - regions and existing assignment from meta
servers - available servers
Returns:
map of servers and regions to be assigned to them


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.