@InterfaceAudience.Private public class RSGroupBasedLoadBalancer extends Object implements LoadBalancer
Modifier and Type | Field and Description |
---|---|
static String |
FALLBACK_GROUP_ENABLE_KEY
Set this key to
true to allow region fallback. |
private boolean |
fallbackEnabled |
private FavoredNodesManager |
favoredNodesManager |
private LoadBalancer |
internalBalancer |
private static org.slf4j.Logger |
LOG |
private MasterServices |
masterServices |
private ClusterInfoProvider |
provider |
private RSGroupInfoManager |
rsGroupInfoManager |
BOGUS_SERVER_NAME, HBASE_RSGROUP_LOADBALANCER_CLASS
Constructor and Description |
---|
RSGroupBasedLoadBalancer()
Used by reflection in
LoadBalancerFactory . |
Modifier and Type | Method and Description |
---|---|
List<RegionPlan> |
balanceCluster(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) |
FavoredNodesManager |
getFavoredNodesManager() |
LoadBalancer |
getInternalBalancer() |
void |
initialize()
Initialize the load balancer.
|
boolean |
isFallbackEnabled() |
boolean |
isOnline() |
boolean |
isStopped()
Returns True if
Stoppable.stop(String) has been closed. |
void |
onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
Notification that config has changed
|
void |
postMasterStartupInitialize()
If balancer needs to do initialization after Master has started up, lets do that here.
|
ServerName |
randomAssignment(RegionInfo region,
List<ServerName> servers)
Get a random region server from the list
|
void |
regionOffline(RegionInfo regionInfo)
Marks the region as offline at balancer.
|
void |
regionOnline(RegionInfo regionInfo,
ServerName sn)
Marks the region as online at balancer.
|
Map<ServerName,List<RegionInfo>> |
retainAssignment(Map<RegionInfo,ServerName> regions,
List<ServerName> servers)
Assign regions to the previously hosting region server
|
Map<ServerName,List<RegionInfo>> |
roundRobinAssignment(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(String why)
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 load
|
void |
updateBalancerStatus(boolean status) |
void |
updateClusterMetrics(ClusterMetrics sm)
Set the current cluster status.
|
private static final org.slf4j.Logger LOG
private MasterServices masterServices
private ClusterInfoProvider provider
private FavoredNodesManager favoredNodesManager
private volatile RSGroupInfoManager rsGroupInfoManager
private volatile LoadBalancer internalBalancer
public static final String FALLBACK_GROUP_ENABLE_KEY
true
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 regionsprivate volatile boolean fallbackEnabled
@InterfaceAudience.Private public RSGroupBasedLoadBalancer()
LoadBalancerFactory
.public void updateClusterMetrics(ClusterMetrics sm)
LoadBalancer
updateClusterMetrics
in interface LoadBalancer
public void updateBalancerLoadInfo(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable)
LoadBalancer
updateBalancerLoadInfo
in interface LoadBalancer
loadOfAllTable
- region load of servers for all tablepublic void setMasterServices(MasterServices masterServices)
public List<RegionPlan> balanceCluster(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable) throws IOException
balanceCluster
in interface LoadBalancer
loadOfAllTable
- region load of servers for all tableIOException
@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws IOException
LoadBalancer
roundRobinAssignment
in interface LoadBalancer
IOException
@NonNull public Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo,ServerName> regions, List<ServerName> servers) throws HBaseIOException
LoadBalancer
retainAssignment
in interface LoadBalancer
HBaseIOException
public ServerName randomAssignment(RegionInfo region, List<ServerName> servers) throws IOException
LoadBalancer
randomAssignment
in interface LoadBalancer
region
- Region for which this selection is being done.IOException
private List<Pair<List<RegionInfo>,List<ServerName>>> generateGroupAssignments(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException
HBaseIOException
private List<ServerName> filterOfflineServers(RSGroupInfo RSGroupInfo, List<ServerName> onlineServers)
private List<ServerName> filterServers(Set<Address> servers, List<ServerName> onlineServers)
RSGroupInfo
), 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.servers
- the serversonlineServers
- List of servers which are online.private Pair<Map<TableName,Map<ServerName,List<RegionInfo>>>,List<RegionPlan>> correctAssignments(Map<TableName,Map<ServerName,List<RegionInfo>>> existingAssignments) throws IOException
IOException
public void initialize() throws IOException
LoadBalancer
initialize
in interface LoadBalancer
IOException
public boolean isOnline()
public boolean isFallbackEnabled()
public void regionOnline(RegionInfo regionInfo, ServerName sn)
LoadBalancer
regionOnline
in interface LoadBalancer
public void regionOffline(RegionInfo regionInfo)
LoadBalancer
regionOffline
in interface LoadBalancer
public void onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
LoadBalancer
onConfigurationChange
in interface ConfigurationObserver
onConfigurationChange
in interface LoadBalancer
public void stop(String why)
Stoppable
public boolean isStopped()
Stoppable
Stoppable.stop(String)
has been closed.public LoadBalancer getInternalBalancer()
public FavoredNodesManager getFavoredNodesManager()
public void postMasterStartupInitialize()
LoadBalancer
postMasterStartupInitialize
in interface LoadBalancer
public void updateBalancerStatus(boolean status)
updateBalancerStatus
in interface LoadBalancer
private List<ServerName> getFallBackCandidates(List<ServerName> servers)
public void setClusterInfoProvider(ClusterInfoProvider provider)
LoadBalancer
setClusterInfoProvider
in interface LoadBalancer
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.