Class FavoredStochasticBalancer
java.lang.Object
org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer
org.apache.hadoop.hbase.master.balancer.FavoredStochasticBalancer
- All Implemented Interfaces:
ConfigurationObserver
,FavoredNodesPromoter
,LoadBalancer
,Stoppable
@Private
public class FavoredStochasticBalancer
extends StochasticLoadBalancer
implements FavoredNodesPromoter
An implementation of the
LoadBalancer
that assigns favored
nodes for each region. There is a Primary RegionServer that hosts the region, and then there is
Secondary and Tertiary RegionServers. Currently, the favored nodes information is used in
creating HDFS files - the Primary RegionServer passes the primary, secondary, tertiary node
addresses as hints to the DistributedFileSystem API for creating files on the filesystem. These
nodes are treated as hints by the HDFS to place the blocks of the file. This alleviates the
problem to do with reading from remote nodes (since we can make the Secondary RegionServer as the
new Primary RegionServer) after a region is recovered. This should help provide consistent read
latencies for the regions even when their primary region servers die. This provides two
CandidateGenerator
-
Nested Class Summary
Modifier and TypeClassDescription(package private) class
private class
Pick favored nodes with the highest locality for a region with lowest locality.Nested classes/interfaces inherited from class org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer
StochasticLoadBalancer.GeneratorType
-
Field Summary
Modifier and TypeFieldDescriptionprivate FavoredNodesManager
private static final org.slf4j.Logger
Fields inherited from class org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer
candidateGenerators, COST_FUNCTIONS_COST_FUNCTIONS_KEY, costFunctions, DEFAULT_KEEP_REGION_LOADS, DEFAULT_MAX_RUNNING_TIME, DEFAULT_MAX_STEPS, DEFAULT_MIN_COST_NEED_BALANCE, DEFAULT_RUN_MAX_STEPS, DEFAULT_STEPS_PER_REGION, KEEP_REGION_LOADS, loads, MAX_RUNNING_TIME_KEY, MAX_STEPS_KEY, MIN_COST_NEED_BALANCE_KEY, OVERALL_COST_FUNCTION_NAME, regionCacheRatioOnOldServerMap, RUN_MAX_STEPS_KEY, STEPS_PER_REGION_KEY
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.favored.FavoredNodesPromoter
FAVORED_ALWAYS_ASSIGN_REGIONS
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
addRegionToMap
(Map<ServerName, List<RegionInfo>> assignmentMapForFavoredNodes, RegionInfo region, ServerName host) private void
assignRegionToAvailableFavoredNode
(Map<ServerName, List<RegionInfo>> assignmentMapForFavoredNodes, RegionInfo region, ServerName primaryHost, ServerName secondaryHost, ServerName tertiaryHost) Assign the region to primary if its available.protected List<RegionPlan>
balanceTable
(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) For all regions correctly assigned to favored nodes, we just use the stochastic balancer implementation.protected List<CandidateGenerator>
void
generateFavoredNodesForDaughter
(List<ServerName> servers, RegionInfo parent, RegionInfo regionA, RegionInfo regionB) Generate Favored Nodes for daughters during region split.void
generateFavoredNodesForMergedRegion
(RegionInfo merged, RegionInfo[] mergeParents) Generate favored nodes for a region during merge.private Map<ServerName,
List<RegionInfo>> generateFNForRegionsWithoutFN
(FavoredNodeAssignmentHelper helper, List<RegionInfo> regions) getFavoredNodes
(RegionInfo regionInfo) private Set<ServerName>
getInheritedFNForDaughter
(FavoredNodeAssignmentHelper helper, List<ServerName> parentFavoredNodes, FavoredNodesPlan.Position primary, FavoredNodesPlan.Position secondary) private List<ServerName>
getOnlineFavoredNodes
(List<ServerName> onlineServers, List<ServerName> serversWithoutStartCodes) Return list of favored nodes that are online.protected CandidateGenerator
Returns any candidate generator in randomprivate ServerName
getServerFromFavoredNode
(List<ServerName> servers, ServerName fn) Get the ServerName for the FavoredNode.private void
mergeAssignmentMaps
(Map<ServerName, List<RegionInfo>> assignmentMap, Map<ServerName, List<RegionInfo>> otherAssignments) randomAssignment
(RegionInfo regionInfo, List<ServerName> servers) If we have favored nodes for a region, we will return one of the FN as destination.retainAssignment
(Map<RegionInfo, ServerName> regions, List<ServerName> servers) Reuse BaseLoadBalancer's retainAssignment, but generate favored nodes when its missing.roundRobinAssignment
(List<RegionInfo> regions, List<ServerName> servers) Round robin assignment: Segregate the regions into two types: 1.private Pair<Map<ServerName,
List<RegionInfo>>, List<RegionInfo>> segregateRegionsAndAssignRegionsWithFavoredNodes
(Collection<RegionInfo> regions, List<ServerName> onlineServers) Return a pair - one with assignments when favored nodes are present and another with regions without favored nodes.void
private void
updateFavoredNodesForRegion
(RegionInfo regionInfo, List<ServerName> newFavoredNodes) Methods inherited from class org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer
composeAttributeName, computeCost, createCostFunctions, functionCost, getCandidateGenerators, getCostFunctionNames, getCostFunctions, initCosts, loadConf, needsBalance, nextAction, sendRejectionReasonToRingBuffer, setRackManager, updateBalancerLoadInfo, updateClusterMetrics, updateCostsAndWeightsWithAction, updateMetricsSize
Methods inherited from class org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
balanceCluster, getConf, getDefaultSlop, idleRegionServerExist, initialize, isStopped, onConfigurationChange, postMasterStartupInitialize, preBalanceCluster, regionOffline, regionOnline, setClusterInfoProvider, sloppyRegionServerExist, stop, toEnsumbleTableLoad, updateBalancerStatus
-
Field Details
-
LOG
-
fnm
-
-
Constructor Details
-
FavoredStochasticBalancer
public FavoredStochasticBalancer()
-
-
Method Details
-
setFavoredNodesManager
- Specified by:
setFavoredNodesManager
in interfaceFavoredNodesPromoter
-
createCandidateGenerators
- Overrides:
createCandidateGenerators
in classStochasticLoadBalancer
-
getRandomGenerator
Returns any candidate generator in random- Overrides:
getRandomGenerator
in classStochasticLoadBalancer
-
roundRobinAssignment
@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException Round robin assignment: Segregate the regions into two types: 1. The regions that have favored node assignment where at least one of the favored node is still alive. In this case, try to adhere to the current favored nodes assignment as much as possible - i.e., if the current primary is gone, then make the secondary or tertiary as the new host for the region (based on their current load). Note that we don't change the favored node assignments here (even though one or more favored node is currently down). That will be done by the admin operations. 2. The regions that currently don't have favored node assignments. Generate favored nodes for them and then assign. Generate the primary fn in round robin fashion and generate secondary and tertiary as per favored nodes constraints.- Specified by:
roundRobinAssignment
in interfaceLoadBalancer
- Overrides:
roundRobinAssignment
in classBaseLoadBalancer
- Parameters:
regions
- all regionsservers
- all servers- Returns:
- map of server to the regions it should take, or emptyMap if no assignment is possible (ie. no servers)
- Throws:
HBaseIOException
-
mergeAssignmentMaps
private void mergeAssignmentMaps(Map<ServerName, List<RegionInfo>> assignmentMap, Map<ServerName, List<RegionInfo>> otherAssignments) -
generateFNForRegionsWithoutFN
private Map<ServerName,List<RegionInfo>> generateFNForRegionsWithoutFN(FavoredNodeAssignmentHelper helper, List<RegionInfo> regions) throws IOException - Throws:
IOException
-
segregateRegionsAndAssignRegionsWithFavoredNodes
private Pair<Map<ServerName,List<RegionInfo>>, segregateRegionsAndAssignRegionsWithFavoredNodesList<RegionInfo>> (Collection<RegionInfo> regions, List<ServerName> onlineServers) throws HBaseIOException Return a pair - one with assignments when favored nodes are present and another with regions without favored nodes.- Throws:
HBaseIOException
-
addRegionToMap
private void addRegionToMap(Map<ServerName, List<RegionInfo>> assignmentMapForFavoredNodes, RegionInfo region, ServerName host) -
getServerFromFavoredNode
Get the ServerName for the FavoredNode. Since FN's startcode is -1, we could want to get the ServerName with the correct start code from the list of provided servers. -
assignRegionToAvailableFavoredNode
private void assignRegionToAvailableFavoredNode(Map<ServerName, List<RegionInfo>> assignmentMapForFavoredNodes, RegionInfo region, ServerName primaryHost, ServerName secondaryHost, ServerName tertiaryHost) Assign the region to primary if its available. If both secondary and tertiary are available, assign to the host which has less load. Else assign to secondary or tertiary whichever is available (in that order). -
randomAssignment
public ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException If we have favored nodes for a region, we will return one of the FN as destination. If favored nodes are not present for a region, we will generate and return one of the FN as destination. If we can't generate anything, lets fallback.- Specified by:
randomAssignment
in interfaceLoadBalancer
- Overrides:
randomAssignment
in classBaseLoadBalancer
- Parameters:
regionInfo
- Region for which this selection is being done.- Throws:
HBaseIOException
-
updateFavoredNodesForRegion
private void updateFavoredNodesForRegion(RegionInfo regionInfo, List<ServerName> newFavoredNodes) throws IOException - Throws:
IOException
-
retainAssignment
@NonNull public Map<ServerName,List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions, List<ServerName> servers) throws HBaseIOExceptionReuse BaseLoadBalancer's retainAssignment, but generate favored nodes when its missing.- Specified by:
retainAssignment
in interfaceLoadBalancer
- Overrides:
retainAssignment
in classBaseLoadBalancer
- Parameters:
regions
- regions and existing assignment from metaservers
- available servers- Returns:
- map of servers and regions to be assigned to them, or emptyMap if no assignment is possible (ie. no servers)
- Throws:
HBaseIOException
-
getOnlineFavoredNodes
private List<ServerName> getOnlineFavoredNodes(List<ServerName> onlineServers, List<ServerName> serversWithoutStartCodes) Return list of favored nodes that are online. -
getFavoredNodes
- Specified by:
getFavoredNodes
in interfaceFavoredNodesPromoter
-
generateFavoredNodesForDaughter
public void generateFavoredNodesForDaughter(List<ServerName> servers, RegionInfo parent, RegionInfo regionA, RegionInfo regionB) throws IOException Generate Favored Nodes for daughters during region split. If the parent does not have FN, regenerates them for the daughters. If the parent has FN, inherit two FN from parent for each daughter and generate the remaining. The primary FN for both the daughters should be the same as parent. Inherit the secondary FN from the parent but keep it different for each daughter. Choose the remaining FN randomly. This would give us better distribution over a period of time after enough splits.- Specified by:
generateFavoredNodesForDaughter
in interfaceFavoredNodesPromoter
- Throws:
IOException
-
getInheritedFNForDaughter
private Set<ServerName> getInheritedFNForDaughter(FavoredNodeAssignmentHelper helper, List<ServerName> parentFavoredNodes, FavoredNodesPlan.Position primary, FavoredNodesPlan.Position secondary) throws IOException - Throws:
IOException
-
generateFavoredNodesForMergedRegion
public void generateFavoredNodesForMergedRegion(RegionInfo merged, RegionInfo[] mergeParents) throws IOException Generate favored nodes for a region during merge. Choose the FN from one of the sources to keep it simple.- Specified by:
generateFavoredNodesForMergedRegion
in interfaceFavoredNodesPromoter
- Throws:
IOException
-
balanceTable
protected List<RegionPlan> balanceTable(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) For all regions correctly assigned to favored nodes, we just use the stochastic balancer implementation. For the misplaced regions, we assign a bogus server to it and AM takes care.- Overrides:
balanceTable
in classStochasticLoadBalancer
- Parameters:
tableName
- the table to be balancedloadOfOneTable
- region load of servers for the specific one table- Returns:
- List of plans
-