public abstract class BaseLoadBalancer extends Object implements LoadBalancer
AssignmentManager
to assign regions
in the edge cases. It doesn't provide an implementation of the actual
balancing algorithm.Modifier and Type | Class and Description |
---|---|
protected static class |
BaseLoadBalancer.Cluster
An efficient array based implementation similar to ClusterState for keeping
the status of the cluster in terms of region assignment and distribution.
|
private static class |
BaseLoadBalancer.DefaultRackManager |
Modifier and Type | Field and Description |
---|---|
protected ClusterStatus |
clusterStatus |
protected org.apache.hadoop.conf.Configuration |
config |
private static List<HRegionInfo> |
EMPTY_REGION_LIST |
private static org.apache.commons.logging.Log |
LOG |
protected ServerName |
masterServerName |
protected MetricsBalancer |
metricsBalancer |
private static int |
MIN_SERVER_BALANCE |
protected RackManager |
rackManager |
private static Random |
RANDOM |
protected RegionLocationFinder |
regionFinder |
protected MasterServices |
services |
protected float |
slop |
private boolean |
stopped |
static String |
TABLES_ON_MASTER |
protected Set<String> |
tablesOnMaster |
Constructor and Description |
---|
BaseLoadBalancer() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
areSomeRegionReplicasColocated(BaseLoadBalancer.Cluster c)
Subclasses should implement this to return true if the cluster has nodes that hosts
multiple replicas for the same region, or, if there are multiple racks and the same
rack hosts replicas of the same region
|
protected Map<ServerName,List<HRegionInfo>> |
assignMasterRegions(Collection<HRegionInfo> regions,
List<ServerName> servers)
Assign the regions that should be on master regionserver.
|
protected List<RegionPlan> |
balanceMasterRegions(Map<ServerName,List<HRegionInfo>> clusterMap)
Balance the regions that should be on master regionserver.
|
protected BaseLoadBalancer.Cluster |
createCluster(List<ServerName> servers,
Collection<HRegionInfo> regions) |
org.apache.hadoop.conf.Configuration |
getConf() |
protected Map<ServerName,List<HRegionInfo>> |
getRegionAssignmentsByServer(Collection<HRegionInfo> regions) |
protected static String[] |
getTablesOnMaster(org.apache.hadoop.conf.Configuration conf) |
Map<HRegionInfo,ServerName> |
immediateAssignment(List<HRegionInfo> regions,
List<ServerName> servers)
Generates an immediate assignment plan to be used by a new master for
regions in transition that do not have an already known destination.
|
void |
initialize()
Initialize the load balancer.
|
boolean |
isStopped() |
protected boolean |
needsBalance(BaseLoadBalancer.Cluster c) |
void |
onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
This method would be called by the
ConfigurationManager
object when the Configuration object is reloaded from disk. |
private ServerName |
randomAssignment(BaseLoadBalancer.Cluster cluster,
HRegionInfo regionInfo,
List<ServerName> servers)
Used to assign a single region to a random server.
|
ServerName |
randomAssignment(HRegionInfo regionInfo,
List<ServerName> servers)
Used to assign a single region to a random server.
|
void |
regionOffline(HRegionInfo regionInfo)
Marks the region as offline at balancer.
|
void |
regionOnline(HRegionInfo regionInfo,
ServerName sn)
Marks the region as online at balancer.
|
Map<ServerName,List<HRegionInfo>> |
retainAssignment(Map<HRegionInfo,ServerName> regions,
List<ServerName> servers)
Generates a bulk assignment startup plan, attempting to reuse the existing
assignment information from META, but adjusting for the specified list of
available/online servers available for assignment.
|
private void |
roundRobinAssignment(BaseLoadBalancer.Cluster cluster,
List<HRegionInfo> regions,
List<HRegionInfo> unassignedRegions,
List<ServerName> servers,
Map<ServerName,List<HRegionInfo>> assignments)
Round robin a list of regions to a list of servers
|
Map<ServerName,List<HRegionInfo>> |
roundRobinAssignment(List<HRegionInfo> regions,
List<ServerName> servers)
Generates a bulk assignment plan to be used on cluster startup using a
simple round-robin assignment.
|
void |
setClusterStatus(ClusterStatus st)
Set the current cluster status.
|
void |
setConf(org.apache.hadoop.conf.Configuration conf) |
void |
setMasterServices(MasterServices masterServices)
Set the master service.
|
void |
setRackManager(RackManager rackManager) |
protected void |
setSlop(org.apache.hadoop.conf.Configuration conf) |
boolean |
shouldBeOnMaster(HRegionInfo region)
Check if a region belongs to some small system table.
|
void |
stop(String why)
Stop this service.
|
static boolean |
tablesOnMaster(org.apache.hadoop.conf.Configuration conf)
Check if configured to put any tables on the active master
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
balanceCluster
private static final int MIN_SERVER_BALANCE
private volatile boolean stopped
private static final List<HRegionInfo> EMPTY_REGION_LIST
protected final RegionLocationFinder regionFinder
protected float slop
protected org.apache.hadoop.conf.Configuration config
protected RackManager rackManager
private static final Random RANDOM
private static final org.apache.commons.logging.Log LOG
public static final String TABLES_ON_MASTER
protected final MetricsBalancer metricsBalancer
protected ClusterStatus clusterStatus
protected ServerName masterServerName
protected MasterServices services
protected static String[] getTablesOnMaster(org.apache.hadoop.conf.Configuration conf)
public static boolean tablesOnMaster(org.apache.hadoop.conf.Configuration conf)
public void setConf(org.apache.hadoop.conf.Configuration conf)
setConf
in interface org.apache.hadoop.conf.Configurable
protected void setSlop(org.apache.hadoop.conf.Configuration conf)
public boolean shouldBeOnMaster(HRegionInfo region)
protected List<RegionPlan> balanceMasterRegions(Map<ServerName,List<HRegionInfo>> clusterMap)
protected Map<ServerName,List<HRegionInfo>> assignMasterRegions(Collection<HRegionInfo> regions, List<ServerName> servers)
public org.apache.hadoop.conf.Configuration getConf()
getConf
in interface org.apache.hadoop.conf.Configurable
public void setClusterStatus(ClusterStatus st)
LoadBalancer
setClusterStatus
in interface LoadBalancer
public void setMasterServices(MasterServices masterServices)
LoadBalancer
setMasterServices
in interface LoadBalancer
public void setRackManager(RackManager rackManager)
protected boolean needsBalance(BaseLoadBalancer.Cluster c)
protected boolean areSomeRegionReplicasColocated(BaseLoadBalancer.Cluster c)
c
- Cluster informationpublic Map<ServerName,List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions, List<ServerName> servers)
Takes a list of all the regions and all the servers in the cluster and returns a map of each server to the regions that it should be assigned.
Currently implemented as a round-robin assignment. Same invariant as load balancing, all servers holding floor(avg) or ceiling(avg). TODO: Use block locations from HDFS to place regions with their blocks
roundRobinAssignment
in interface LoadBalancer
regions
- all regionsservers
- all serversprotected BaseLoadBalancer.Cluster createCluster(List<ServerName> servers, Collection<HRegionInfo> regions)
public Map<HRegionInfo,ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers)
immediateAssignment
in interface LoadBalancer
regions
- servers
- public ServerName randomAssignment(HRegionInfo regionInfo, List<ServerName> servers)
randomAssignment
in interface LoadBalancer
regionInfo
- Region for which this selection is being done.public Map<ServerName,List<HRegionInfo>> retainAssignment(Map<HRegionInfo,ServerName> regions, List<ServerName> servers)
Takes a map of all regions to their existing assignment from META. Also takes a list of online servers for regions to be assigned to. Attempts to retain all assignment, so in some instances initial assignment will not be completely balanced.
Any leftover regions without an existing server to be assigned to will be assigned randomly to available servers.
retainAssignment
in interface LoadBalancer
regions
- regions and existing assignment from metaservers
- available serverspublic void initialize() throws HBaseIOException
LoadBalancer
initialize
in interface LoadBalancer
HBaseIOException
public void regionOnline(HRegionInfo regionInfo, ServerName sn)
LoadBalancer
regionOnline
in interface LoadBalancer
public void regionOffline(HRegionInfo regionInfo)
LoadBalancer
regionOffline
in interface LoadBalancer
public boolean isStopped()
isStopped
in interface Stoppable
Stoppable.stop(String)
has been closed.private ServerName randomAssignment(BaseLoadBalancer.Cluster cluster, HRegionInfo regionInfo, List<ServerName> servers)
private void roundRobinAssignment(BaseLoadBalancer.Cluster cluster, List<HRegionInfo> regions, List<HRegionInfo> unassignedRegions, List<ServerName> servers, Map<ServerName,List<HRegionInfo>> assignments)
protected Map<ServerName,List<HRegionInfo>> getRegionAssignmentsByServer(Collection<HRegionInfo> regions)
public void onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
ConfigurationObserver
ConfigurationManager
object when the Configuration
object is reloaded from disk.onConfigurationChange
in interface ConfigurationObserver
onConfigurationChange
in interface LoadBalancer
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.