Class SimpleLoadBalancer
java.lang.Object
org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
org.apache.hadoop.hbase.master.balancer.SimpleLoadBalancer
- All Implemented Interfaces:
ConfigurationObserver
,LoadBalancer
,Stoppable
Makes decisions about the placement and movement of Regions across RegionServers.
Cluster-wide load balancing will occur only when there are no regions in transition and according
to a fixed period of a time using
BaseLoadBalancer.balanceCluster(Map)
.
On cluster startup, bulk assignment can be used to determine locations for all Regions in a
cluster.
This classes produces plans for the AssignmentManager
to execute.-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static final class
Stores additional per-server information about the regions added/removed during the run of the balancing algorithm. -
Field Summary
Modifier and TypeFieldDescriptionprivate float
private static final org.slf4j.Logger
private float
private RegionInfoComparator
private RegionPlan.RegionPlanComparator
private List<ServerAndLoad>
Fields inherited from class org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
BALANCER_DECISION_BUFFER_ENABLED, BALANCER_REJECTION_BUFFER_ENABLED, clusterStatus, DEFAULT_BALANCER_DECISION_BUFFER_ENABLED, DEFAULT_BALANCER_REJECTION_BUFFER_ENABLED, DEFAULT_HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable, masterServerName, metricsBalancer, MIN_SERVER_BALANCE, provider, rackManager, regionFinder, slop, useRegionFinder
Fields inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
BOGUS_SERVER_NAME, HBASE_RSGROUP_LOADBALANCER_CLASS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
addRegionPlan
(org.apache.hbase.thirdparty.com.google.common.collect.MinMaxPriorityQueue<RegionPlan> regionsToMove, boolean fetchFromTail, ServerName sn, List<RegionPlan> regionsToReturn) Add a region from the head or tail to the List of regions to return.private void
balanceOverall
(List<RegionPlan> regionsToReturn, Map<ServerName, SimpleLoadBalancer.BalanceInfo> serverBalanceInfo, boolean fetchFromTail, org.apache.hbase.thirdparty.com.google.common.collect.MinMaxPriorityQueue<RegionPlan> regionsToMove, int max, int min) If we need to balanceoverall, we need to add one more round to peel off one region from each max.protected List<RegionPlan>
balanceTable
(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) Generate a global load balancing plan according to the specified map of server information to the most loaded regions of each server.protected void
loadConf
(org.apache.hadoop.conf.Configuration conf) private boolean
void
onConfigurationChange
(org.apache.hadoop.conf.Configuration conf) Notification that config has changedprivate boolean
A checker function to decide when we want balance overall and certain table has been balanced, do we still need to re-distribute regions of this table to achieve the state of overall-balanceprotected void
preBalanceCluster
(Map<TableName, Map<ServerName, List<RegionInfo>>> loadOfAllTable) Called before actually executing balanceCluster.(package private) void
setClusterLoad
(Map<TableName, Map<ServerName, List<RegionInfo>>> clusterLoad) Pass RegionStates and allow balancer to set the current cluster load.private void
setLoad
(List<ServerAndLoad> slList, int i, int loadChange) Methods inherited from class org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
balanceCluster, getConf, getDefaultSlop, idleRegionServerExist, initialize, isStopped, postMasterStartupInitialize, randomAssignment, regionOffline, regionOnline, retainAssignment, roundRobinAssignment, setClusterInfoProvider, sloppyRegionServerExist, stop, toEnsumbleTableLoad, updateBalancerStatus, updateClusterMetrics
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
updateBalancerLoadInfo
-
Field Details
-
LOG
-
riComparator
-
rpComparator
-
avgLoadOverall
-
serverLoadList
-
overallSlop
-
-
Constructor Details
-
SimpleLoadBalancer
public SimpleLoadBalancer()
-
-
Method Details
-
setClusterLoad
Pass RegionStates and allow balancer to set the current cluster load. -
preBalanceCluster
Description copied from class:BaseLoadBalancer
Called before actually executing balanceCluster. The sub classes could override this method to do some initialization work.- Overrides:
preBalanceCluster
in classBaseLoadBalancer
-
loadConf
- Overrides:
loadConf
in classBaseLoadBalancer
-
onConfigurationChange
Description copied from interface:LoadBalancer
Notification that config has changed- Specified by:
onConfigurationChange
in interfaceConfigurationObserver
- Specified by:
onConfigurationChange
in interfaceLoadBalancer
- Overrides:
onConfigurationChange
in classBaseLoadBalancer
-
setLoad
-
overallNeedsBalance
A checker function to decide when we want balance overall and certain table has been balanced, do we still need to re-distribute regions of this table to achieve the state of overall-balance- Returns:
- true if this table should be balanced.
-
needsBalance
-
balanceTable
protected List<RegionPlan> balanceTable(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) Generate a global load balancing plan according to the specified map of server information to the most loaded regions of each server. The load balancing invariant is that all servers are within 1 region of the average number of regions per server. If the average is an integer number, all servers will be balanced to the average. Otherwise, all servers will have either floor(average) or ceiling(average) regions. HBASE-3609 Modeled regionsToMove using Guava's MinMaxPriorityQueue so that we can fetch from both ends of the queue. At the beginning, we check whether there was empty region server just discovered by Master. If so, we alternately choose new / old regions from head / tail of regionsToMove, respectively. This alternation avoids clustering young regions on the newly discovered region server. Otherwise, we choose new regions from head of regionsToMove. Another improvement from HBASE-3609 is that we assign regions from regionsToMove to underloaded servers in round-robin fashion. Previously one underloaded server would be filled before we move onto the next underloaded server, leading to clustering of young regions. Finally, we randomly shuffle underloaded servers so that they receive offloaded regions relatively evenly across calls to balanceCluster(). The algorithm is currently implemented as such:- Determine the two valid numbers of regions each server should have, MIN=floor(average) and MAX=ceiling(average).
- Iterate down the most loaded servers, shedding regions from each so each server hosts
exactly MAX regions. Stop once you reach a server that already has <= MAX
regions.
Order the regions to move from most recent to least.
- Iterate down the least loaded servers, assigning regions so each server has exactly MIN regions. Stop once you reach a server that already has >= MIN regions. Regions being assigned to underloaded servers are those that were shed in the previous step. It is possible that there were not enough regions shed to fill each underloaded server to MIN. If so we end up with a number of regions required to do so, neededRegions. It is also possible that we were able to fill each underloaded but ended up with regions that were unassigned from overloaded servers but that still do not have assignment. If neither of these conditions hold (no regions needed to fill the underloaded servers, no regions leftover from overloaded servers), we are done and return. Otherwise we handle these cases below.
- If neededRegions is non-zero (still have underloaded servers), we iterate the most loaded servers again, shedding a single server from each (this brings them from having MAX regions to having MIN regions).
- We now definitely have more regions that need assignment, either from the previous step or from the original shedding from overloaded servers. Iterate the least loaded servers filling each to MIN.
- If we still have more regions that need assignment, again iterate the least loaded servers, this time giving each one (filling them to MAX) until we run out.
- All servers will now either host MIN or MAX regions. In addition, any server hosting >= MAX regions is guaranteed to end up with MAX regions at the end of the balancing. This ensures the minimal number of regions possible are moved.
- Specified by:
balanceTable
in classBaseLoadBalancer
- Parameters:
loadOfOneTable
- Map of regionservers and their load/region information to a list of their most loaded regionstableName
- the table to be balanced- Returns:
- a list of regions to be moved, including source and destination, or null if cluster is already balanced
-
balanceOverall
private void balanceOverall(List<RegionPlan> regionsToReturn, Map<ServerName, SimpleLoadBalancer.BalanceInfo> serverBalanceInfo, boolean fetchFromTail, org.apache.hbase.thirdparty.com.google.common.collect.MinMaxPriorityQueue<RegionPlan> regionsToMove, int max, int min) If we need to balanceoverall, we need to add one more round to peel off one region from each max. Together with other regions left to be assigned, we distribute all regionToMove, to the RS that have less regions in whole cluster scope. -
addRegionPlan
private void addRegionPlan(org.apache.hbase.thirdparty.com.google.common.collect.MinMaxPriorityQueue<RegionPlan> regionsToMove, boolean fetchFromTail, ServerName sn, List<RegionPlan> regionsToReturn) Add a region from the head or tail to the List of regions to return.
-