@InterfaceAudience.Private public abstract class BaseLoadBalancer extends Object implements LoadBalancer
AssignmentManager to assign regions
 in the edge cases. It doesn't provide an implementation of the
 actual balancing algorithm.| Modifier and Type | Class and Description | 
|---|---|
| protected static class  | BaseLoadBalancer.ClusterAn efficient array based implementation similar to ClusterState for keeping
 the status of the cluster in terms of region assignment and distribution. | 
| private static class  | BaseLoadBalancer.DefaultRackManager | 
| Modifier and Type | Field and Description | 
|---|---|
| static String | BALANCER_DECISION_BUFFER_ENABLED | 
| protected ClusterMetrics | clusterStatus | 
| protected org.apache.hadoop.conf.Configuration | config | 
| static boolean | DEFAULT_BALANCER_DECISION_BUFFER_ENABLED | 
| private static List<RegionInfo> | EMPTY_REGION_LIST | 
| (package private) static Predicate<ServerMetrics> | IDLE_SERVER_PREDICATOR | 
| protected boolean | isByTable | 
| private static org.slf4j.Logger | LOG | 
| protected boolean | maintenanceMode | 
| protected ServerName | masterServerName | 
| protected MetricsBalancer | metricsBalancer | 
| protected static int | MIN_SERVER_BALANCE | 
| protected NamedQueueRecorder | namedQueueRecorderUse to add balancer decision history to ring-buffer | 
| protected boolean | onlySystemTablesOnMasterDeprecated. 
 since 2.4.0, will be removed in 3.0.0. | 
| protected float | overallSlop | 
| protected RackManager | rackManager | 
| private static Random | RANDOM | 
| protected RegionLocationFinder | regionFinder | 
| protected MasterServices | services | 
| protected float | slop | 
| private boolean | stopped | 
| protected boolean | useRegionFinder | 
BOGUS_SERVER_NAME, SYSTEM_TABLES_ON_MASTER, TABLES_ON_MASTER| Modifier | Constructor and Description | 
|---|---|
| protected  | BaseLoadBalancer()The constructor that uses the basic MetricsBalancer | 
| protected  | BaseLoadBalancer(MetricsBalancer metricsBalancer)This Constructor accepts an instance of MetricsBalancer,
 which will be used instead of creating a new one | 
| Modifier and Type | Method and Description | 
|---|---|
| protected boolean | areSomeRegionReplicasColocated(BaseLoadBalancer.Cluster c)Subclasses should implement this to return true if the cluster has nodes that hosts
 multiple replicas for the same region, or, if there are multiple racks and the same
 rack hosts replicas of the same region | 
| protected Map<ServerName,List<RegionInfo>> | assignMasterSystemRegions(Collection<RegionInfo> regions,
                         List<ServerName> servers)Deprecated. 
 since 2.4.0, will be removed in 3.0.0. | 
| List<RegionPlan> | balanceCluster(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable)Perform the major balance operation for cluster, will invoke  LoadBalancer.balanceTable(org.apache.hadoop.hbase.TableName, java.util.Map<org.apache.hadoop.hbase.ServerName, java.util.List<org.apache.hadoop.hbase.client.RegionInfo>>)to do
 actual balance. | 
| protected List<RegionPlan> | balanceMasterRegions(Map<ServerName,List<RegionInfo>> clusterMap)Deprecated. 
 since 2.4.0, will be removed in 3.0.0. | 
| abstract List<RegionPlan> | balanceTable(TableName tableName,
            Map<ServerName,List<RegionInfo>> loadOfOneTable)Perform the major balance operation for table, all class implement of  LoadBalancershould override this method | 
| protected BaseLoadBalancer.Cluster | createCluster(List<ServerName> servers,
             Collection<RegionInfo> regions) | 
| private void | createRegionFinder() | 
| private List<ServerName> | findIdleServers(List<ServerName> servers) | 
| org.apache.hadoop.conf.Configuration | getConf() | 
| protected Map<ServerName,List<RegionInfo>> | getRegionAssignmentsByServer(Collection<RegionInfo> regions) | 
| protected boolean | idleRegionServerExist(BaseLoadBalancer.Cluster c) | 
| void | initialize()Initialize the load balancer. | 
| boolean | isStopped() | 
| protected boolean | needsBalance(TableName tableName,
            BaseLoadBalancer.Cluster c) | 
| void | onConfigurationChange(org.apache.hadoop.conf.Configuration conf)This method would be called by the  ConfigurationManagerobject when theConfigurationobject is reloaded from disk. | 
| void | postMasterStartupInitialize()If balancer needs to do initialization after Master has started up, lets do that here. | 
| private ServerName | randomAssignment(BaseLoadBalancer.Cluster cluster,
                RegionInfo regionInfo,
                List<ServerName> servers)Used to assign a single region to a random server. | 
| ServerName | randomAssignment(RegionInfo regionInfo,
                List<ServerName> servers)Used to assign a single region to a random server. | 
| void | regionOffline(RegionInfo regionInfo)Marks the region as offline at balancer. | 
| void | regionOnline(RegionInfo regionInfo,
            ServerName sn)Marks the region as online at balancer. | 
| Map<ServerName,List<RegionInfo>> | retainAssignment(Map<RegionInfo,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. | 
| private void | roundRobinAssignment(BaseLoadBalancer.Cluster cluster,
                    List<RegionInfo> regions,
                    List<ServerName> servers,
                    Map<ServerName,List<RegionInfo>> assignments)Round robin a list of regions to a list of servers | 
| Map<ServerName,List<RegionInfo>> | roundRobinAssignment(List<RegionInfo> regions,
                    List<ServerName> servers)Generates a bulk assignment plan to be used on cluster startup using a
 simple round-robin assignment. | 
| void | setClusterMetrics(ClusterMetrics st)Set the current cluster status. | 
| void | setConf(org.apache.hadoop.conf.Configuration conf) | 
| void | setMasterServices(MasterServices masterServices)Set the master service. | 
| void | setRackManager(RackManager rackManager) | 
| protected void | setSlop(org.apache.hadoop.conf.Configuration conf) | 
| boolean | shouldBeOnMaster(RegionInfo region)Deprecated. 
 since 2.4.0, will be removed in 3.0.0. | 
| void | stop(String why)Stop this service. | 
| private Map<ServerName,List<RegionInfo>> | toEnsumbleTableLoad(Map<TableName,Map<ServerName,List<RegionInfo>>> LoadOfAllTable) | 
| void | updateBalancerStatus(boolean status)Updates the balancer status tag reported to JMX | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisMasterCanHostUserRegions, isSystemTablesOnlyOnMaster, isTablesOnMasterpublic static final String BALANCER_DECISION_BUFFER_ENABLED
public static final boolean DEFAULT_BALANCER_DECISION_BUFFER_ENABLED
protected static final int MIN_SERVER_BALANCE
private volatile boolean stopped
private static final List<RegionInfo> EMPTY_REGION_LIST
static final Predicate<ServerMetrics> IDLE_SERVER_PREDICATOR
protected RegionLocationFinder regionFinder
protected boolean useRegionFinder
protected boolean isByTable
protected NamedQueueRecorder namedQueueRecorder
protected float slop
protected float overallSlop
protected org.apache.hadoop.conf.Configuration config
protected RackManager rackManager
private static final org.slf4j.Logger LOG
protected MetricsBalancer metricsBalancer
protected ClusterMetrics clusterStatus
protected ServerName masterServerName
protected MasterServices services
@Deprecated protected boolean onlySystemTablesOnMaster
protected boolean maintenanceMode
protected BaseLoadBalancer()
protected BaseLoadBalancer(MetricsBalancer metricsBalancer)
private void createRegionFinder()
public void setConf(org.apache.hadoop.conf.Configuration conf)
setConf in interface org.apache.hadoop.conf.Configurableprotected void setSlop(org.apache.hadoop.conf.Configuration conf)
@Deprecated public boolean shouldBeOnMaster(RegionInfo region)
@Deprecated protected List<RegionPlan> balanceMasterRegions(Map<ServerName,List<RegionInfo>> clusterMap)
@Deprecated @NonNull protected Map<ServerName,List<RegionInfo>> assignMasterSystemRegions(Collection<RegionInfo> regions, List<ServerName> servers)
public org.apache.hadoop.conf.Configuration getConf()
getConf in interface org.apache.hadoop.conf.Configurablepublic void setClusterMetrics(ClusterMetrics st)
LoadBalancersetClusterMetrics in interface LoadBalancerpublic void setMasterServices(MasterServices masterServices)
LoadBalancersetMasterServices in interface LoadBalancerpublic void postMasterStartupInitialize()
LoadBalancerpostMasterStartupInitialize in interface LoadBalancerpublic void setRackManager(RackManager rackManager)
protected boolean needsBalance(TableName tableName, BaseLoadBalancer.Cluster c)
protected boolean areSomeRegionReplicasColocated(BaseLoadBalancer.Cluster c)
c - Cluster informationprotected final boolean idleRegionServerExist(BaseLoadBalancer.Cluster c)
@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException
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
roundRobinAssignment in interface LoadBalancerregions - all regionsservers - all serversHBaseIOExceptionprotected BaseLoadBalancer.Cluster createCluster(List<ServerName> servers, Collection<RegionInfo> regions) throws HBaseIOException
HBaseIOExceptionprivate List<ServerName> findIdleServers(List<ServerName> servers)
public ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException
randomAssignment in interface LoadBalancerregionInfo - Region for which this selection is being done.HBaseIOException@NonNull public Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo,ServerName> regions, List<ServerName> servers) throws HBaseIOException
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.
retainAssignment in interface LoadBalancerregions - regions and existing assignment from metaservers - available serversHBaseIOExceptionpublic void initialize() throws HBaseIOException
LoadBalancerinitialize in interface LoadBalancerHBaseIOExceptionpublic void regionOnline(RegionInfo regionInfo, ServerName sn)
LoadBalancerregionOnline in interface LoadBalancerpublic void regionOffline(RegionInfo regionInfo)
LoadBalancerregionOffline in interface LoadBalancerpublic boolean isStopped()
isStopped in interface StoppableStoppable.stop(String) has been closed.public void stop(String why)
Stoppablepublic void updateBalancerStatus(boolean status)
updateBalancerStatus in interface LoadBalancerprivate ServerName randomAssignment(BaseLoadBalancer.Cluster cluster, RegionInfo regionInfo, List<ServerName> servers)
private void roundRobinAssignment(BaseLoadBalancer.Cluster cluster, List<RegionInfo> regions, List<ServerName> servers, Map<ServerName,List<RegionInfo>> assignments)
protected Map<ServerName,List<RegionInfo>> getRegionAssignmentsByServer(Collection<RegionInfo> regions)
private Map<ServerName,List<RegionInfo>> toEnsumbleTableLoad(Map<TableName,Map<ServerName,List<RegionInfo>>> LoadOfAllTable)
public abstract List<RegionPlan> balanceTable(TableName tableName, Map<ServerName,List<RegionInfo>> loadOfOneTable)
LoadBalancerLoadBalancer
 should override this methodbalanceTable in interface LoadBalancertableName - the table to be balancedloadOfOneTable - region load of servers for the specific one tablepublic List<RegionPlan> balanceCluster(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable)
LoadBalancerLoadBalancer.balanceTable(org.apache.hadoop.hbase.TableName, java.util.Map<org.apache.hadoop.hbase.ServerName, java.util.List<org.apache.hadoop.hbase.client.RegionInfo>>) to do
 actual balance. Normally not need override this method, except SimpleLoadBalancer and
 RSGroupBasedLoadBalancer.balanceCluster in interface LoadBalancerloadOfAllTable - region load of servers for all tablepublic void onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
ConfigurationObserverConfigurationManager
 object when the Configuration object is reloaded from disk.onConfigurationChange in interface ConfigurationObserveronConfigurationChange in interface LoadBalancerCopyright © 2007–2021 The Apache Software Foundation. All rights reserved.