Package org.apache.hadoop.hbase.master
Interface LoadBalancer
- All Superinterfaces:
ConfigurationObserver
,Stoppable
- All Known Implementing Classes:
BaseLoadBalancer
,CacheAwareLoadBalancer
,FavoredNodeLoadBalancer
,FavoredStochasticBalancer
,MaintenanceLoadBalancer
,RSGroupBasedLoadBalancer
,SimpleLoadBalancer
,StochasticLoadBalancer
Makes decisions about the placement and movement of Regions across RegionServers.
Cluster-wide load balancing will occur only when there are no regions in transition and according
to a fixed period of a time using
balanceCluster(Map)
.
On cluster startup, bulk assignment can be used to determine locations for all Regions in a
cluster.
This class produces plans for the AssignmentManager
to execute.
About locking:
- We will first call
setClusterInfoProvider(ClusterInfoProvider)
and theninitialize()
to initialize the balancer, and before callinginitialize()
, we will never call any methods of this balancer. So these two methods do not need to be synchronized. - The
balanceCluster(Map)
method will use theClusterMetrics
which is set byupdateClusterMetrics(ClusterMetrics)
, and also lots of configurations, which could be changed byonConfigurationChange(Configuration)
, so the easier way is to make these three methods synchronized. And since there will be only one balancing thread, this will not impact performance too much. - The
roundRobinAssignment(List, List)
,retainAssignment(Map, List)
andrandomAssignment(RegionInfo, List)
could be called from multiple threads concurrently, so these three methods should not be synchronized, the implementation classes need to make sure that they are thread safe.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ServerName
static final String
Deprecated.since 3.0.0, will be removed in 4.0.0. -
Method Summary
Modifier and TypeMethodDescriptionbalanceCluster
(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) Perform the major balance operation for cluster.void
Initialize the load balancer.void
onConfigurationChange
(org.apache.hadoop.conf.Configuration conf) Notification that config has changedvoid
If balancer needs to do initialization after Master has started up, lets do that here.randomAssignment
(RegionInfo regionInfo, List<ServerName> servers) Get a random region server from the listvoid
regionOffline
(RegionInfo regionInfo) Marks the region as offline at balancer.void
regionOnline
(RegionInfo regionInfo, ServerName sn) Marks the region as online at balancer.retainAssignment
(Map<RegionInfo, ServerName> regions, List<ServerName> servers) Assign regions to the previously hosting region serverroundRobinAssignment
(List<RegionInfo> regions, List<ServerName> servers) Perform a Round Robin assignment of regions.void
setClusterInfoProvider
(ClusterInfoProvider provider) Set the cluster info provider.default void
updateBalancerLoadInfo
(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) In some scenarios, Balancer needs to update internal status or information according to the current tables loadvoid
updateBalancerStatus
(boolean status) void
updateClusterMetrics
(ClusterMetrics metrics) Set the current cluster status.
-
Field Details
-
BOGUS_SERVER_NAME
-
HBASE_RSGROUP_LOADBALANCER_CLASS
Deprecated.since 3.0.0, will be removed in 4.0.0. In the new implementation, as the base load balancer will always be the rs group based one, you should just useHConstants.HBASE_MASTER_LOADBALANCER_CLASS
to config the per group load balancer.Config for pluggable load balancers.- See Also:
-
-
Method Details
-
updateClusterMetrics
Set the current cluster status. This allows a LoadBalancer to map host name to a server -
setClusterInfoProvider
Set the cluster info provider. Usually it is just a wrapper of master. -
balanceCluster
List<RegionPlan> balanceCluster(Map<TableName, Map<ServerName, throws IOExceptionList<RegionInfo>>> loadOfAllTable) Perform the major balance operation for cluster.- 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
- Throws:
IOException
-
roundRobinAssignment
@NonNull Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws IOException Perform a Round Robin assignment of regions.- Returns:
- Map of servername to regioninfos
- Throws:
IOException
-
retainAssignment
@NonNull Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions, List<ServerName> servers) throws IOExceptionAssign regions to the previously hosting region server- Returns:
- List of plans
- Throws:
IOException
-
randomAssignment
Get a random region server from the list- Parameters:
regionInfo
- Region for which this selection is being done.- Throws:
IOException
-
initialize
Initialize the load balancer. Must be called after setters.- Throws:
IOException
-
regionOnline
Marks the region as online at balancer. -
regionOffline
Marks the region as offline at balancer. -
onConfigurationChange
Notification that config has changed- Specified by:
onConfigurationChange
in interfaceConfigurationObserver
-
postMasterStartupInitialize
void postMasterStartupInitialize()If balancer needs to do initialization after Master has started up, lets do that here. -
updateBalancerStatus
-
updateBalancerLoadInfo
In some scenarios, Balancer needs to update internal status or information according to the current tables load- Parameters:
loadOfAllTable
- region load of servers for all table
-