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
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, namedQueueRecorder, 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, onlySystemTablesOnMaster, rackManager, regionFinder, services, 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, SYSTEM_TABLES_ON_MASTER, TABLES_ON_MASTER
-
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) protected List<RegionPlan>
balanceTable
(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) Given the cluster state this will try and approach an optimal balance.protected List<CandidateGenerator>
void
generateFavoredNodesForDaughter
(List<ServerName> servers, RegionInfo parent, RegionInfo regionA, RegionInfo regionB) void
generateFavoredNodesForMergedRegion
(RegionInfo merged, RegionInfo[] mergeParents) 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) protected CandidateGenerator
Returns any candidate generator in randomprivate ServerName
getServerFromFavoredNode
(List<ServerName> servers, ServerName fn) private void
mergeAssignmentMaps
(Map<ServerName, List<RegionInfo>> assignmentMap, Map<ServerName, List<RegionInfo>> otherAssignments) randomAssignment
(RegionInfo regionInfo, List<ServerName> servers) Used to assign a single region to a random server.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.roundRobinAssignment
(List<RegionInfo> regions, List<ServerName> servers) Generates a bulk assignment plan to be used on cluster startup using a simple round-robin assignment.private Pair<Map<ServerName,
List<RegionInfo>>, List<RegionInfo>> segregateRegionsAndAssignRegionsWithFavoredNodes
(Collection<RegionInfo> regions, List<ServerName> onlineServers) void
setMasterServices
(MasterServices masterServices) Set the master service.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, setRackManager, updateBalancerLoadInfo, updateClusterMetrics, updateCostsAndWeightsWithAction, updateMetricsSize
Methods inherited from class org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer
assignMasterSystemRegions, balanceCluster, balanceMasterRegions, getConf, getDefaultSlop, idleRegionServerExist, initialize, isStopped, onConfigurationChange, postMasterStartupInitialize, preBalanceCluster, regionOffline, regionOnline, shouldBeOnMaster, sloppyRegionServerExist, stop, toEnsumbleTableLoad, updateBalancerStatus
-
Field Details
-
LOG
-
fnm
-
-
Constructor Details
-
FavoredStochasticBalancer
public FavoredStochasticBalancer()
-
-
Method Details
-
createCandidateGenerators
- Overrides:
createCandidateGenerators
in classStochasticLoadBalancer
-
getRandomGenerator
Returns any candidate generator in random- Overrides:
getRandomGenerator
in classStochasticLoadBalancer
-
setMasterServices
Description copied from interface:LoadBalancer
Set the master service.- Specified by:
setMasterServices
in interfaceLoadBalancer
- Overrides:
setMasterServices
in classBaseLoadBalancer
-
roundRobinAssignment
@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException Description copied from class:BaseLoadBalancer
Generates a bulk assignment plan to be used on cluster startup using a simple round-robin assignment. 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- 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 - Throws:
HBaseIOException
-
addRegionToMap
private void addRegionToMap(Map<ServerName, List<RegionInfo>> assignmentMapForFavoredNodes, RegionInfo region, ServerName host) -
getServerFromFavoredNode
-
assignRegionToAvailableFavoredNode
private void assignRegionToAvailableFavoredNode(Map<ServerName, List<RegionInfo>> assignmentMapForFavoredNodes, RegionInfo region, ServerName primaryHost, ServerName secondaryHost, ServerName tertiaryHost) -
randomAssignment
public ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException Description copied from class:BaseLoadBalancer
Used to assign a single region to a random server.- 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 HBaseIOExceptionDescription copied from class:BaseLoadBalancer
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.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.
- 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) -
getFavoredNodes
-
generateFavoredNodesForDaughter
public void generateFavoredNodesForDaughter(List<ServerName> servers, RegionInfo parent, RegionInfo regionA, RegionInfo regionB) throws IOException - 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 - Specified by:
generateFavoredNodesForMergedRegion
in interfaceFavoredNodesPromoter
- Throws:
IOException
-
balanceTable
protected List<RegionPlan> balanceTable(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) Description copied from class:StochasticLoadBalancer
Given the cluster state this will try and approach an optimal balance. This should always approach the optimal state given enough steps.- Overrides:
balanceTable
in classStochasticLoadBalancer
- Parameters:
tableName
- the table to be balancedloadOfOneTable
- region load of servers for the specific one table- Returns:
- List of plans
-