Class BaseLoadBalancer
java.lang.Object
org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
- All Implemented Interfaces:
- ConfigurationObserver,- LoadBalancer,- Stoppable
- Direct Known Subclasses:
- FavoredNodeLoadBalancer,- SimpleLoadBalancer,- StochasticLoadBalancer
The base class for load balancers. It provides the functions used to by 
AssignmentManager
 to assign regions in the edge cases. It doesn't provide an implementation of the actual balancing
 algorithm.
 
 Since 3.0.0, all the balancers will be wrapped inside a RSGroupBasedLoadBalancer, it will
 be in charge of the synchronization of balancing and configuration changing, so we do not need to
 synchronize by ourselves.- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected ClusterMetricsstatic final booleanstatic final booleanstatic final booleanprotected booleanprivate static final org.slf4j.Loggerprotected ServerNameprotected MetricsBalancerprotected static final intprotected ClusterInfoProviderprotected RackManagerprotected RegionHDFSBlockLocationFinderstatic final floatstatic final Stringprotected floatprivate booleanprotected booleanFields inherited from interface org.apache.hadoop.hbase.master.LoadBalancerBOGUS_SERVER_NAME, HBASE_RSGROUP_LOADBALANCER_CLASS, MOVE_THROTTLING, MOVE_THROTTLING_DEFAULT
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedThe constructor that uses the basic MetricsBalancerprotectedBaseLoadBalancer(MetricsBalancer metricsBalancer) This Constructor accepts an instance of MetricsBalancer, which will be used instead of creating a new one
- 
Method SummaryModifier and TypeMethodDescriptionfinal List<RegionPlan>balanceCluster(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) Perform the major balance operation for cluster, will invokebalanceTable(TableName, Map)to do actual balance.protected abstract List<RegionPlan>balanceTable(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) Perform the major balance operation for table, all sub classes should override this method.private BalancerClusterStatecreateCluster(List<ServerName> servers, Collection<RegionInfo> regions) private RegionHDFSBlockLocationFindercreateRegionLocationFinder(org.apache.hadoop.conf.Configuration conf) private List<ServerName>findIdleServers(List<ServerName> servers) protected final org.apache.hadoop.conf.ConfigurationgetConf()protected floatprivate Map<ServerName,List<RegionInfo>> getRegionAssignmentsByServer(Collection<RegionInfo> regions) protected final booleanvoidInitialize the load balancer.booleanReturns True ifStoppable.stop(String)has been closed.protected voidloadConf(org.apache.hadoop.conf.Configuration conf) voidonConfigurationChange(org.apache.hadoop.conf.Configuration conf) Notification that config has changedvoidIf balancer needs to do initialization after Master has started up, lets do that here.protected voidpreBalanceCluster(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) Called before actually executing balanceCluster.randomAssignment(RegionInfo regionInfo, List<ServerName> servers) Used to assign a single region to a random server.private ServerNamerandomAssignment(BalancerClusterState cluster, RegionInfo regionInfo, List<ServerName> servers) Used to assign a single region to a random server.voidregionOffline(RegionInfo regionInfo) Marks the region as offline at balancer.voidregionOnline(RegionInfo regionInfo, ServerName sn) Marks the region as online at balancer.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.roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) Generates a bulk assignment plan to be used on cluster startup using a simple round-robin assignment.private voidroundRobinAssignment(BalancerClusterState cluster, List<RegionInfo> regions, List<ServerName> servers, Map<ServerName, List<RegionInfo>> assignments) Round-robin a list of regions to a list of serversvoidsetClusterInfoProvider(ClusterInfoProvider provider) Set the cluster info provider.protected final booleanvoidStop this service.protected final Map<ServerName,List<RegionInfo>> toEnsumbleTableLoad(Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable) voidupdateBalancerStatus(boolean status) Updates the balancer status tag reported to JMXvoidSet the current cluster status.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.hbase.master.LoadBalancerthrottle, updateBalancerLoadInfo
- 
Field Details- 
LOG
- 
BALANCER_DECISION_BUFFER_ENABLED- See Also:
 
- 
DEFAULT_BALANCER_DECISION_BUFFER_ENABLED- See Also:
 
- 
BALANCER_REJECTION_BUFFER_ENABLED- See Also:
 
- 
DEFAULT_BALANCER_REJECTION_BUFFER_ENABLED- See Also:
 
- 
DEFAULT_HBASE_MASTER_LOADBALANCE_BYTABLE- See Also:
 
- 
REGIONS_SLOP_KEY- See Also:
 
- 
REGIONS_SLOP_DEFAULT- See Also:
 
- 
MIN_SERVER_BALANCE- See Also:
 
- 
stopped
- 
regionFinder
- 
useRegionFinder
- 
isByTable
- 
slop
- 
rackManager
- 
metricsBalancer
- 
clusterStatus
- 
masterServerName
- 
provider
 
- 
- 
Constructor Details- 
BaseLoadBalancerprotected BaseLoadBalancer()The constructor that uses the basic MetricsBalancer
- 
BaseLoadBalancerThis Constructor accepts an instance of MetricsBalancer, which will be used instead of creating a new one
 
- 
- 
Method Details- 
getConf
- 
updateClusterMetricsDescription copied from interface:LoadBalancerSet the current cluster status. This allows a LoadBalancer to map host name to a server- Specified by:
- updateClusterMetricsin interface- LoadBalancer
 
- 
setClusterInfoProviderDescription copied from interface:LoadBalancerSet the cluster info provider. Usually it is just a wrapper of master.- Specified by:
- setClusterInfoProviderin interface- LoadBalancer
 
- 
postMasterStartupInitializeDescription copied from interface:LoadBalancerIf balancer needs to do initialization after Master has started up, lets do that here.- Specified by:
- postMasterStartupInitializein interface- LoadBalancer
 
- 
idleRegionServerExist
- 
sloppyRegionServerExist
- 
roundRobinAssignment@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException 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:
- roundRobinAssignmentin interface- LoadBalancer
- Parameters:
- regions- all regions
- servers- all servers
- Returns:
- map of server to the regions it should take, or emptyMap if no assignment is possible (ie. no servers)
- Throws:
- HBaseIOException
 
- 
createClusterprivate BalancerClusterState createCluster(List<ServerName> servers, Collection<RegionInfo> regions) throws HBaseIOException - Throws:
- HBaseIOException
 
- 
findIdleServers
- 
randomAssignmentpublic ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException Used to assign a single region to a random server.- Specified by:
- randomAssignmentin interface- LoadBalancer
- Parameters:
- regionInfo- Region for which this selection is being done.
- Throws:
- HBaseIOException
 
- 
retainAssignment@NonNull public Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions, List<ServerName> servers) throws HBaseIOExceptionGenerates 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:
- retainAssignmentin interface- LoadBalancer
- Parameters:
- regions- regions and existing assignment from meta
- servers- available servers
- Returns:
- map of servers and regions to be assigned to them, or emptyMap if no assignment is possible (ie. no servers)
- Throws:
- HBaseIOException
 
- 
getDefaultSlop
- 
createRegionLocationFinderprivate RegionHDFSBlockLocationFinder createRegionLocationFinder(org.apache.hadoop.conf.Configuration conf) 
- 
loadConf
- 
initializeDescription copied from interface:LoadBalancerInitialize the load balancer. Must be called after setters.- Specified by:
- initializein interface- LoadBalancer
 
- 
regionOnlineDescription copied from interface:LoadBalancerMarks the region as online at balancer.- Specified by:
- regionOnlinein interface- LoadBalancer
 
- 
regionOfflineDescription copied from interface:LoadBalancerMarks the region as offline at balancer.- Specified by:
- regionOfflinein interface- LoadBalancer
 
- 
isStoppedDescription copied from interface:StoppableReturns True ifStoppable.stop(String)has been closed.
- 
stopDescription copied from interface:StoppableStop this service. Implementers should favor logging errors over throwing RuntimeExceptions.
- 
updateBalancerStatusUpdates the balancer status tag reported to JMX- Specified by:
- updateBalancerStatusin interface- LoadBalancer
 
- 
randomAssignmentprivate ServerName randomAssignment(BalancerClusterState cluster, RegionInfo regionInfo, List<ServerName> servers) Used to assign a single region to a random server.
- 
roundRobinAssignmentprivate void roundRobinAssignment(BalancerClusterState cluster, List<RegionInfo> regions, List<ServerName> servers, Map<ServerName, List<RegionInfo>> assignments) Round-robin a list of regions to a list of servers
- 
getRegionAssignmentsByServerprivate Map<ServerName,List<RegionInfo>> getRegionAssignmentsByServer(Collection<RegionInfo> regions) 
- 
toEnsumbleTableLoadprotected final Map<ServerName,List<RegionInfo>> toEnsumbleTableLoad(Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable) 
- 
balanceTableprotected abstract List<RegionPlan> balanceTable(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) Perform the major balance operation for table, all sub classes should override this method. Will be invoked bybalanceCluster(Map). IfHConstants.HBASE_MASTER_LOADBALANCE_BYTABLEis enabled, we will call this method multiple times, one table a time, where we will only pass in the regions for a single table each time. If not, we will pass in all the regions at once, and thetableNamewill beHConstants.ENSEMBLE_TABLE_NAME.- Parameters:
- tableName- the table to be balanced
- loadOfOneTable- region load of servers for the specific one table
- Returns:
- List of plans
 
- 
preBalanceClusterCalled before actually executing balanceCluster. The sub classes could override this method to do some initialization work.
- 
balanceClusterpublic final List<RegionPlan> balanceCluster(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) Perform the major balance operation for cluster, will invokebalanceTable(TableName, Map)to do actual balance. THIs method is marked as final which means you should not override this method. See the javadoc forbalanceTable(TableName, Map)for more details.- Specified by:
- balanceClusterin interface- LoadBalancer
- Parameters:
- loadOfAllTable- region load of servers for all table
- Returns:
- a list of regions to be moved, including source and destination, or null if cluster is already balanced
- See Also:
 
- 
onConfigurationChangeDescription copied from interface:LoadBalancerNotification that config has changed- Specified by:
- onConfigurationChangein interface- ConfigurationObserver
- Specified by:
- onConfigurationChangein interface- LoadBalancer
 
 
-