Package org.apache.hadoop.hbase.rsgroup
Class RSGroupBasedLoadBalancer
java.lang.Object
org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer
- All Implemented Interfaces:
ConfigurationObserver,LoadBalancer,Stoppable
GroupBasedLoadBalancer, used when Region Server Grouping is configured (HBase-6721) It does
region balance based on a table's group membership.
Most assignment methods contain two exclusive code paths: Online - when the group table is online
and Offline - when it is unavailable.
During Offline, assignments are assigned based on cached information in zookeeper. If unavailable
(ie bootstrap) then regions are assigned randomly.
Once the GROUP table has been assigned, the balancer switches to Online and will then start
providing appropriate assignments for user tables.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSet this key totrueto allow region fallback.private booleanprivate FavoredNodesManagerprivate LoadBalancerprivate static final org.slf4j.Loggerprivate MasterServicesprivate ClusterInfoProviderprivate RSGroupInfoManagerFields inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
BOGUS_SERVER_NAME, HBASE_RSGROUP_LOADBALANCER_CLASS, MOVE_THROTTLING, MOVE_THROTTLING_DEFAULT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbalanceCluster(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) Balance by RSGroup.private Pair<Map<TableName,Map<ServerName, List<RegionInfo>>>, List<RegionPlan>> correctAssignments(Map<TableName, Map<ServerName, List<RegionInfo>>> existingAssignments) private List<ServerName>filterOfflineServers(RSGroupInfo RSGroupInfo, List<ServerName> onlineServers) private List<ServerName>filterServers(Set<Address> servers, List<ServerName> onlineServers) Filter servers based on the online servers.private List<Pair<List<RegionInfo>,List<ServerName>>> generateGroupAssignments(List<RegionInfo> regions, List<ServerName> servers) private List<ServerName>getFallBackCandidates(List<ServerName> servers) voidInitialize the load balancer.booleanbooleanisOnline()booleanReturns True ifStoppable.stop(String)has been closed.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.randomAssignment(RegionInfo region, List<ServerName> servers) Get a random region server from the listvoidregionOffline(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) Assign regions to the previously hosting region serverroundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) Perform a Round Robin assignment of regions.voidsetClusterInfoProvider(ClusterInfoProvider provider) Set the cluster info provider.voidsetMasterServices(MasterServices masterServices) voidStop this service.voidupdateBalancerLoadInfo(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) In some scenarios, Balancer needs to update internal status or information according to the current tables loadvoidupdateBalancerStatus(boolean status) voidSet 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
throttle
-
Field Details
-
LOG
-
masterServices
-
provider
-
favoredNodesManager
-
rsGroupInfoManager
-
internalBalancer
-
FALLBACK_GROUP_ENABLE_KEY
Set this key totrueto allow region fallback. Fallback to the default rsgroup first, then fallback to any group if no online servers in default rsgroup. Please keep balancer switch on at the same time, which is relied on to correct misplaced regions- See Also:
-
fallbackEnabled
-
-
Constructor Details
-
RSGroupBasedLoadBalancer
Used by reflection inLoadBalancerFactory.
-
-
Method Details
-
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
-
updateBalancerLoadInfo
Description copied from interface:LoadBalancerIn some scenarios, Balancer needs to update internal status or information according to the current tables load- Specified by:
updateBalancerLoadInfoin interfaceLoadBalancer- Parameters:
loadOfAllTable- region load of servers for all table
-
setMasterServices
-
balanceCluster
public List<RegionPlan> balanceCluster(Map<TableName, Map<ServerName, throws IOExceptionList<RegionInfo>>> loadOfAllTable) Balance by RSGroup.- 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
- Throws:
IOException
-
roundRobinAssignment
@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws IOException Description copied from interface:LoadBalancerPerform a Round Robin assignment of regions.- Specified by:
roundRobinAssignmentin interfaceLoadBalancer- Returns:
- Map of servername to regioninfos
- Throws:
IOException
-
retainAssignment
@NonNull public Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions, List<ServerName> servers) throws HBaseIOExceptionDescription copied from interface:LoadBalancerAssign regions to the previously hosting region server- Specified by:
retainAssignmentin interfaceLoadBalancer- Returns:
- List of plans
- Throws:
HBaseIOException
-
randomAssignment
Description copied from interface:LoadBalancerGet a random region server from the list- Specified by:
randomAssignmentin interfaceLoadBalancer- Parameters:
region- Region for which this selection is being done.- Throws:
IOException
-
generateGroupAssignments
private List<Pair<List<RegionInfo>,List<ServerName>>> generateGroupAssignments(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException - Throws:
HBaseIOException
-
filterOfflineServers
private List<ServerName> filterOfflineServers(RSGroupInfo RSGroupInfo, List<ServerName> onlineServers) -
filterServers
Filter servers based on the online servers. servers is actually a TreeSet (seeRSGroupInfo), having its contains()'s time complexity as O(logn), which is good enough. TODO: consider using HashSet to pursue O(1) for contains() throughout the calling chain if needed.- Parameters:
servers- the serversonlineServers- List of servers which are online.- Returns:
- the list
-
correctAssignments
private Pair<Map<TableName,Map<ServerName, correctAssignmentsList<RegionInfo>>>, List<RegionPlan>> (Map<TableName, Map<ServerName, throws IOExceptionList<RegionInfo>>> existingAssignments) - Throws:
IOException
-
initialize
Description copied from interface:LoadBalancerInitialize the load balancer. Must be called after setters.- Specified by:
initializein interfaceLoadBalancer- Throws:
IOException
-
isOnline
-
isFallbackEnabled
-
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
-
onConfigurationChange
Description copied from interface:LoadBalancerNotification that config has changed- Specified by:
onConfigurationChangein interfaceConfigurationObserver- Specified by:
onConfigurationChangein interfaceLoadBalancer
-
stop
Description copied from interface:StoppableStop this service. Implementers should favor logging errors over throwing RuntimeExceptions. -
isStopped
Description copied from interface:StoppableReturns True ifStoppable.stop(String)has been closed. -
getInternalBalancer
-
getFavoredNodesManager
-
postMasterStartupInitialize
Description copied from interface:LoadBalancerIf balancer needs to do initialization after Master has started up, lets do that here.- Specified by:
postMasterStartupInitializein interfaceLoadBalancer
-
updateBalancerStatus
- Specified by:
updateBalancerStatusin interfaceLoadBalancer
-
getFallBackCandidates
-
setClusterInfoProvider
Description copied from interface:LoadBalancerSet the cluster info provider. Usually it is just a wrapper of master.- Specified by:
setClusterInfoProviderin interfaceLoadBalancer
-