Package org.apache.hadoop.hbase.master
Interface LoadBalancer
- All Superinterfaces:
ConfigurationObserver
,Stoppable
- All Known Subinterfaces:
RSGroupableBalancer
- 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
setMasterServices(MasterServices)
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 2.4.0, will be removed in 3.0.0.static final String
Deprecated.since 2.4.0, will be removed in 3.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.static boolean
isMasterCanHostUserRegions
(org.apache.hadoop.conf.Configuration conf) Deprecated.since 2.4.0, will be removed in 3.0.0.static boolean
isSystemTablesOnlyOnMaster
(org.apache.hadoop.conf.Configuration conf) Deprecated.since 2.4.0, will be removed in 3.0.0.static boolean
isTablesOnMaster
(org.apache.hadoop.conf.Configuration conf) Deprecated.since 2.4.0, will be removed in 3.0.0.void
onConfigurationChange
(org.apache.hadoop.conf.Configuration conf) This method would be called by theConfigurationManager
object when theConfiguration
object is reloaded from disk.void
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
setMasterServices
(MasterServices masterServices) Set the master service.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
-
TABLES_ON_MASTER
Deprecated.since 2.4.0, will be removed in 3.0.0.Master can carry regions as of hbase-2.0.0. By default, it carries no tables. TODO: Add any | system as flags to indicate what it can do.- See Also:
-
SYSTEM_TABLES_ON_MASTER
Deprecated.since 2.4.0, will be removed in 3.0.0.Master carries system tables.- See Also:
-
BOGUS_SERVER_NAME
-
-
Method Details
-
updateClusterMetrics
Set the current cluster status. This allows a LoadBalancer to map host name to a server -
setMasterServices
Set the master service. -
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 HBaseIOException Perform a Round Robin assignment of regions.- Returns:
- Map of servername to regioninfos
- Throws:
HBaseIOException
-
retainAssignment
@NonNull Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions, List<ServerName> servers) throws HBaseIOExceptionAssign regions to the previously hosting region server- Returns:
- List of plans
- Throws:
HBaseIOException
-
randomAssignment
ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException Get a random region server from the list- Parameters:
regionInfo
- Region for which this selection is being done.- Throws:
HBaseIOException
-
initialize
Initialize the load balancer. Must be called after setters.- Throws:
HBaseIOException
-
regionOnline
Marks the region as online at balancer. -
regionOffline
Marks the region as offline at balancer. -
onConfigurationChange
Description copied from interface:ConfigurationObserver
This method would be called by theConfigurationManager
object when theConfiguration
object is reloaded from disk.- 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
-
isTablesOnMaster
Deprecated.since 2.4.0, will be removed in 3.0.0.- Returns:
- true if Master carries regions
- See Also:
-
isSystemTablesOnlyOnMaster
Deprecated.since 2.4.0, will be removed in 3.0.0.- See Also:
-
isMasterCanHostUserRegions
Deprecated.since 2.4.0, will be removed in 3.0.0.- See Also:
-