@InterfaceAudience.Private 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 | Field and Description |
|---|---|
static String |
BALANCER_DECISION_BUFFER_ENABLED |
static String |
BALANCER_REJECTION_BUFFER_ENABLED |
protected ClusterMetrics |
clusterStatus |
static boolean |
DEFAULT_BALANCER_DECISION_BUFFER_ENABLED |
static boolean |
DEFAULT_BALANCER_REJECTION_BUFFER_ENABLED |
static boolean |
DEFAULT_HBASE_MASTER_LOADBALANCE_BYTABLE |
private static Predicate<ServerMetrics> |
IDLE_SERVER_PREDICATOR |
protected boolean |
isByTable |
private static org.slf4j.Logger |
LOG |
protected ServerName |
masterServerName |
protected MetricsBalancer |
metricsBalancer |
protected static int |
MIN_SERVER_BALANCE |
protected boolean |
onlySystemTablesOnMaster
Deprecated.
since 2.4.0, will be removed in 3.0.0.
|
protected RackManager |
rackManager |
protected RegionLocationFinder |
regionFinder |
protected MasterServices |
services |
protected float |
slop |
private boolean |
stopped |
protected boolean |
useRegionFinder |
BOGUS_SERVER_NAME, SYSTEM_TABLES_ON_MASTER, TABLES_ON_MASTER| Modifier | Constructor and Description |
|---|---|
protected |
BaseLoadBalancer()
The constructor that uses the basic MetricsBalancer
|
protected |
BaseLoadBalancer(MetricsBalancer metricsBalancer)
This Constructor accepts an instance of MetricsBalancer, which will be used instead of creating
a new one
|
| Modifier and Type | Method and Description |
|---|---|
protected Map<ServerName,List<RegionInfo>> |
assignMasterSystemRegions(Collection<RegionInfo> regions,
List<ServerName> servers)
Deprecated.
since 2.4.0, will be removed in 3.0.0.
|
List<RegionPlan> |
balanceCluster(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable)
Perform the major balance operation for cluster, will invoke
balanceTable(TableName, Map) to do actual balance. |
protected List<RegionPlan> |
balanceMasterRegions(Map<ServerName,List<RegionInfo>> clusterMap)
Deprecated.
since 2.4.0, will be removed in 3.0.0.
|
protected abstract List<RegionPlan> |
balanceTable(TableName tableName,
Map<ServerName,List<RegionInfo>> loadOfOneTable)
Perform the major balance operation for table, all sub classes should override this method.
|
private BalancerClusterState |
createCluster(List<ServerName> servers,
Collection<RegionInfo> regions) |
private RegionLocationFinder |
createRegionLocationFinder(org.apache.hadoop.conf.Configuration conf) |
private List<ServerName> |
findIdleServers(List<ServerName> servers) |
protected org.apache.hadoop.conf.Configuration |
getConf() |
protected float |
getDefaultSlop() |
private Map<ServerName,List<RegionInfo>> |
getRegionAssignmentsByServer(Collection<RegionInfo> regions) |
protected boolean |
idleRegionServerExist(BalancerClusterState c) |
void |
initialize()
Initialize the load balancer.
|
boolean |
isStopped()
Returns True if
Stoppable.stop(String) has been closed. |
protected void |
loadConf(org.apache.hadoop.conf.Configuration conf) |
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. |
void |
postMasterStartupInitialize()
If balancer needs to do initialization after Master has started up, lets do that here.
|
protected void |
preBalanceCluster(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable)
Called before actually executing balanceCluster.
|
private ServerName |
randomAssignment(BalancerClusterState cluster,
RegionInfo regionInfo,
List<ServerName> servers)
Used to assign a single region to a random server.
|
ServerName |
randomAssignment(RegionInfo regionInfo,
List<ServerName> servers)
Used to assign a single region to a random server.
|
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)
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(BalancerClusterState cluster,
List<RegionInfo> regions,
List<ServerName> servers,
Map<ServerName,List<RegionInfo>> assignments)
Round robin a list of regions to a list of servers
|
Map<ServerName,List<RegionInfo>> |
roundRobinAssignment(List<RegionInfo> regions,
List<ServerName> servers)
Generates a bulk assignment plan to be used on cluster startup using a simple round-robin
assignment.
|
void |
setMasterServices(MasterServices masterServices)
Set the master service.
|
boolean |
shouldBeOnMaster(RegionInfo region)
Deprecated.
since 2.4.0, will be removed in 3.0.0.
|
protected boolean |
sloppyRegionServerExist(ClusterLoadState cs) |
void |
stop(String why)
Stop this service.
|
protected Map<ServerName,List<RegionInfo>> |
toEnsumbleTableLoad(Map<TableName,Map<ServerName,List<RegionInfo>>> LoadOfAllTable) |
void |
updateBalancerStatus(boolean status)
Updates the balancer status tag reported to JMX
|
void |
updateClusterMetrics(ClusterMetrics st)
Set the current cluster status.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisMasterCanHostUserRegions, isSystemTablesOnlyOnMaster, isTablesOnMaster, updateBalancerLoadInfoprivate static final org.slf4j.Logger LOG
public static final String BALANCER_DECISION_BUFFER_ENABLED
public static final boolean DEFAULT_BALANCER_DECISION_BUFFER_ENABLED
public static final String BALANCER_REJECTION_BUFFER_ENABLED
public static final boolean DEFAULT_BALANCER_REJECTION_BUFFER_ENABLED
public static final boolean DEFAULT_HBASE_MASTER_LOADBALANCE_BYTABLE
protected static final int MIN_SERVER_BALANCE
private volatile boolean stopped
private static final Predicate<ServerMetrics> IDLE_SERVER_PREDICATOR
protected volatile RegionLocationFinder regionFinder
protected boolean useRegionFinder
protected boolean isByTable
protected float slop
protected volatile RackManager rackManager
protected MetricsBalancer metricsBalancer
protected ClusterMetrics clusterStatus
protected ServerName masterServerName
protected MasterServices services
@Deprecated protected boolean onlySystemTablesOnMaster
protected BaseLoadBalancer()
protected BaseLoadBalancer(MetricsBalancer metricsBalancer)
protected final org.apache.hadoop.conf.Configuration getConf()
@Deprecated public boolean shouldBeOnMaster(RegionInfo region)
@Deprecated protected List<RegionPlan> balanceMasterRegions(Map<ServerName,List<RegionInfo>> clusterMap)
@Deprecated @NonNull protected Map<ServerName,List<RegionInfo>> assignMasterSystemRegions(Collection<RegionInfo> regions, List<ServerName> servers)
public void updateClusterMetrics(ClusterMetrics st)
LoadBalancerupdateClusterMetrics in interface LoadBalancerpublic void setMasterServices(MasterServices masterServices)
LoadBalancersetMasterServices in interface LoadBalancerpublic void postMasterStartupInitialize()
LoadBalancerpostMasterStartupInitialize in interface LoadBalancerprotected final boolean idleRegionServerExist(BalancerClusterState c)
protected final boolean sloppyRegionServerExist(ClusterLoadState cs)
@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException
roundRobinAssignment in interface LoadBalancerregions - all regionsservers - all serversHBaseIOExceptionprivate BalancerClusterState createCluster(List<ServerName> servers, Collection<RegionInfo> regions) throws HBaseIOException
HBaseIOExceptionprivate List<ServerName> findIdleServers(List<ServerName> servers)
public ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException
randomAssignment in interface LoadBalancerregionInfo - Region for which this selection is being done. nnHBaseIOException@NonNull public Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo,ServerName> regions, List<ServerName> servers) throws HBaseIOException
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 LoadBalancerregions - regions and existing assignment from metaservers - available serversHBaseIOExceptionprotected float getDefaultSlop()
private RegionLocationFinder createRegionLocationFinder(org.apache.hadoop.conf.Configuration conf)
protected void loadConf(org.apache.hadoop.conf.Configuration conf)
public void initialize()
LoadBalancerinitialize in interface LoadBalancerpublic void regionOnline(RegionInfo regionInfo, ServerName sn)
LoadBalancerregionOnline in interface LoadBalancerpublic void regionOffline(RegionInfo regionInfo)
LoadBalancerregionOffline in interface LoadBalancerpublic boolean isStopped()
StoppableStoppable.stop(String) has been closed.public void stop(String why)
Stoppablepublic void updateBalancerStatus(boolean status)
updateBalancerStatus in interface LoadBalancerprivate ServerName randomAssignment(BalancerClusterState cluster, RegionInfo regionInfo, List<ServerName> servers)
private void roundRobinAssignment(BalancerClusterState cluster, List<RegionInfo> regions, List<ServerName> servers, Map<ServerName,List<RegionInfo>> assignments)
private Map<ServerName,List<RegionInfo>> getRegionAssignmentsByServer(Collection<RegionInfo> regions)
protected final Map<ServerName,List<RegionInfo>> toEnsumbleTableLoad(Map<TableName,Map<ServerName,List<RegionInfo>>> LoadOfAllTable)
protected abstract List<RegionPlan> balanceTable(TableName tableName, Map<ServerName,List<RegionInfo>> loadOfOneTable)
balanceCluster(Map). If
HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE is enabled, we will call this method
multiple times, one table a time, where we will only pass in the regions for a single table
each time. If not, we will pass in all the regions at once, and the tableName will be
HConstants.ENSEMBLE_TABLE_NAME.tableName - the table to be balancedloadOfOneTable - region load of servers for the specific one tableprotected void preBalanceCluster(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable)
public final List<RegionPlan> balanceCluster(Map<TableName,Map<ServerName,List<RegionInfo>>> loadOfAllTable)
balanceTable(TableName, Map) to do actual balance.
THIs method is marked as final which means you should not override this method. See the javadoc
for balanceTable(TableName, Map) for more details.balanceCluster in interface LoadBalancerloadOfAllTable - region load of servers for all tablebalanceTable(TableName, Map)public void onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
ConfigurationObserverConfigurationManager object when the
Configuration object is reloaded from disk.onConfigurationChange in interface ConfigurationObserveronConfigurationChange in interface LoadBalancerCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.