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.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected ClusterMetricsstatic final booleanstatic final booleanstatic final booleanprivate static final Predicate<ServerMetrics>protected booleanprivate static final org.slf4j.Loggerprotected ServerNameprotected MetricsBalancerprotected static final intprotected booleanDeprecated.since 2.4.0, will be removed in 3.0.0.protected RackManagerprotected RegionLocationFinderprotected MasterServicesprotected floatprivate booleanprotected booleanFields inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
BOGUS_SERVER_NAME, SYSTEM_TABLES_ON_MASTER, TABLES_ON_MASTER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedThe 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 Summary
Modifier and TypeMethodDescriptionprotected Map<ServerName,List<RegionInfo>> assignMasterSystemRegions(Collection<RegionInfo> regions, List<ServerName> servers) Deprecated.since 2.4.0, will be removed in 3.0.0.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.protected List<RegionPlan>balanceMasterRegions(Map<ServerName, List<RegionInfo>> clusterMap) Deprecated.since 2.4.0, will be removed in 3.0.0.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 RegionLocationFindercreateRegionLocationFinder(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) This method would be called by theConfigurationManagerobject when theConfigurationobject is reloaded from disk.voidIf 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 serversvoidsetMasterServices(MasterServices masterServices) Set the master service.booleanshouldBeOnMaster(RegionInfo region) Deprecated.since 2.4.0, will be removed in 3.0.0.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.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
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:
-
MIN_SERVER_BALANCE
- See Also:
-
stopped
-
IDLE_SERVER_PREDICATOR
-
regionFinder
-
useRegionFinder
-
isByTable
-
slop
-
rackManager
-
metricsBalancer
-
clusterStatus
-
masterServerName
-
services
-
onlySystemTablesOnMaster
Deprecated.since 2.4.0, will be removed in 3.0.0.- See Also:
-
-
Constructor Details
-
BaseLoadBalancer
protected BaseLoadBalancer()The constructor that uses the basic MetricsBalancer -
BaseLoadBalancer
This Constructor accepts an instance of MetricsBalancer, which will be used instead of creating a new one
-
-
Method Details
-
getConf
-
shouldBeOnMaster
Deprecated.since 2.4.0, will be removed in 3.0.0.Check if a region belongs to some system table. If so, the primary replica may be expected to be put on the master regionserver.- See Also:
-
balanceMasterRegions
@Deprecated protected List<RegionPlan> balanceMasterRegions(Map<ServerName, List<RegionInfo>> clusterMap) Deprecated.since 2.4.0, will be removed in 3.0.0.Balance the regions that should be on master regionserver.- See Also:
-
assignMasterSystemRegions
@Deprecated @NonNull protected Map<ServerName,List<RegionInfo>> assignMasterSystemRegions(Collection<RegionInfo> regions, List<ServerName> servers) Deprecated.since 2.4.0, will be removed in 3.0.0.If master is configured to carry system tables only, in here is where we figure what to assign it.- See Also:
-
updateClusterMetrics
Description copied from interface:LoadBalancerSet the current cluster status. This allows a LoadBalancer to map host name to a server- Specified by:
updateClusterMetricsin interfaceLoadBalancer
-
setMasterServices
Description copied from interface:LoadBalancerSet the master service.- Specified by:
setMasterServicesin interfaceLoadBalancer
-
postMasterStartupInitialize
Description copied from interface:LoadBalancerIf balancer needs to do initialization after Master has started up, lets do that here.- Specified by:
postMasterStartupInitializein interfaceLoadBalancer
-
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 interfaceLoadBalancer- Parameters:
regions- all regionsservers- all servers- Returns:
- map of server to the regions it should take, or emptyMap if no assignment is possible (ie. no servers)
- Throws:
HBaseIOException
-
createCluster
private BalancerClusterState createCluster(List<ServerName> servers, Collection<RegionInfo> regions) throws HBaseIOException - Throws:
HBaseIOException
-
findIdleServers
-
randomAssignment
public ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException Used to assign a single region to a random server.- Specified by:
randomAssignmentin interfaceLoadBalancer- 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 interfaceLoadBalancer- Parameters:
regions- regions and existing assignment from metaservers- 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
-
createRegionLocationFinder
-
loadConf
-
initialize
Description copied from interface:LoadBalancerInitialize the load balancer. Must be called after setters.- Specified by:
initializein interfaceLoadBalancer
-
regionOnline
Description copied from interface:LoadBalancerMarks the region as online at balancer.- Specified by:
regionOnlinein interfaceLoadBalancer
-
regionOffline
Description copied from interface:LoadBalancerMarks the region as offline at balancer.- Specified by:
regionOfflinein interfaceLoadBalancer
-
isStopped
Description copied from interface:StoppableReturns True ifStoppable.stop(String)has been closed. -
stop
Description copied from interface:StoppableStop this service. Implementers should favor logging errors over throwing RuntimeExceptions. -
updateBalancerStatus
Updates the balancer status tag reported to JMX- Specified by:
updateBalancerStatusin interfaceLoadBalancer
-
randomAssignment
private ServerName randomAssignment(BalancerClusterState cluster, RegionInfo regionInfo, List<ServerName> servers) Used to assign a single region to a random server. -
roundRobinAssignment
private 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 -
getRegionAssignmentsByServer
private Map<ServerName,List<RegionInfo>> getRegionAssignmentsByServer(Collection<RegionInfo> regions) -
toEnsumbleTableLoad
protected final Map<ServerName,List<RegionInfo>> toEnsumbleTableLoad(Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable) -
balanceTable
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. 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 balancedloadOfOneTable- region load of servers for the specific one table- Returns:
- List of plans
-
preBalanceCluster
Called before actually executing balanceCluster. The sub classes could override this method to do some initialization work. -
balanceCluster
public 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 interfaceLoadBalancer- 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:
-
onConfigurationChange
Description copied from interface:ConfigurationObserverThis method would be called by theConfigurationManagerobject when theConfigurationobject is reloaded from disk.- Specified by:
onConfigurationChangein interfaceConfigurationObserver- Specified by:
onConfigurationChangein interfaceLoadBalancer
-