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
Modifier and TypeFieldDescriptionstatic final String
Set this key totrue
to allow region fallback.private boolean
private FavoredNodesManager
private LoadBalancer
private static final org.slf4j.Logger
private MasterServices
private ClusterInfoProvider
private RSGroupInfoManager
Fields inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
BOGUS_SERVER_NAME, HBASE_RSGROUP_LOADBALANCER_CLASS
-
Constructor Summary
-
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) void
Initialize the load balancer.boolean
boolean
isOnline()
boolean
Returns True ifStoppable.stop(String)
has been closed.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 region, 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.void
setMasterServices
(MasterServices masterServices) void
Stop this service.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
Set the current cluster status.
-
Field Details
-
LOG
-
masterServices
-
provider
-
favoredNodesManager
-
rsGroupInfoManager
-
internalBalancer
-
FALLBACK_GROUP_ENABLE_KEY
Set this key totrue
to 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:LoadBalancer
Set the current cluster status. This allows a LoadBalancer to map host name to a server- Specified by:
updateClusterMetrics
in interfaceLoadBalancer
-
updateBalancerLoadInfo
Description copied from interface:LoadBalancer
In some scenarios, Balancer needs to update internal status or information according to the current tables load- Specified by:
updateBalancerLoadInfo
in 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:
balanceCluster
in 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:LoadBalancer
Perform a Round Robin assignment of regions.- Specified by:
roundRobinAssignment
in 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:LoadBalancer
Assign regions to the previously hosting region server- Specified by:
retainAssignment
in interfaceLoadBalancer
- Returns:
- List of plans
- Throws:
HBaseIOException
-
randomAssignment
Description copied from interface:LoadBalancer
Get a random region server from the list- Specified by:
randomAssignment
in 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:LoadBalancer
Initialize the load balancer. Must be called after setters.- Specified by:
initialize
in interfaceLoadBalancer
- Throws:
IOException
-
isOnline
-
isFallbackEnabled
-
regionOnline
Description copied from interface:LoadBalancer
Marks the region as online at balancer.- Specified by:
regionOnline
in interfaceLoadBalancer
-
regionOffline
Description copied from interface:LoadBalancer
Marks the region as offline at balancer.- Specified by:
regionOffline
in interfaceLoadBalancer
-
onConfigurationChange
Description copied from interface:LoadBalancer
Notification that config has changed- Specified by:
onConfigurationChange
in interfaceConfigurationObserver
- Specified by:
onConfigurationChange
in interfaceLoadBalancer
-
stop
Description copied from interface:Stoppable
Stop this service. Implementers should favor logging errors over throwing RuntimeExceptions. -
isStopped
Description copied from interface:Stoppable
Returns True ifStoppable.stop(String)
has been closed. -
getInternalBalancer
-
getFavoredNodesManager
-
postMasterStartupInitialize
Description copied from interface:LoadBalancer
If balancer needs to do initialization after Master has started up, lets do that here.- Specified by:
postMasterStartupInitialize
in interfaceLoadBalancer
-
updateBalancerStatus
- Specified by:
updateBalancerStatus
in interfaceLoadBalancer
-
getFallBackCandidates
-
setClusterInfoProvider
Description copied from interface:LoadBalancer
Set the cluster info provider. Usually it is just a wrapper of master.- Specified by:
setClusterInfoProvider
in interfaceLoadBalancer
-