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
Nested ClassesModifier and TypeClassDescription(package private) classprivate classNested classes/interfaces inherited from class org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer
StochasticLoadBalancer.GeneratorType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FavoredNodesManagerprivate static final org.slf4j.LoggerFields 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_KEYFields 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, useRegionFinderFields inherited from interface org.apache.hadoop.hbase.favored.FavoredNodesPromoter
FAVORED_ALWAYS_ASSIGN_REGIONSFields inherited from interface org.apache.hadoop.hbase.master.LoadBalancer
BOGUS_SERVER_NAME, SYSTEM_TABLES_ON_MASTER, TABLES_ON_MASTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddRegionToMap(Map<ServerName, List<RegionInfo>> assignmentMapForFavoredNodes, RegionInfo region, ServerName host) private voidassignRegionToAvailableFavoredNode(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>voidgenerateFavoredNodesForDaughter(List<ServerName> servers, RegionInfo parent, RegionInfo regionA, RegionInfo regionB) voidgenerateFavoredNodesForMergedRegion(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 CandidateGeneratorReturns any candidate generator in randomprivate ServerNamegetServerFromFavoredNode(List<ServerName> servers, ServerName fn) private voidmergeAssignmentMaps(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) voidsetMasterServices(MasterServices masterServices) Set the master service.private voidupdateFavoredNodesForRegion(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, updateMetricsSizeMethods 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:
createCandidateGeneratorsin classStochasticLoadBalancer
-
getRandomGenerator
Returns any candidate generator in random- Overrides:
getRandomGeneratorin classStochasticLoadBalancer
-
setMasterServices
Description copied from interface:LoadBalancerSet the master service.- Specified by:
setMasterServicesin interfaceLoadBalancer- Overrides:
setMasterServicesin classBaseLoadBalancer
-
roundRobinAssignment
@NonNull public Map<ServerName,List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException Description copied from class:BaseLoadBalancerGenerates 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:
roundRobinAssignmentin interfaceLoadBalancer- Overrides:
roundRobinAssignmentin 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:BaseLoadBalancerUsed to assign a single region to a random server.- Specified by:
randomAssignmentin interfaceLoadBalancer- Overrides:
randomAssignmentin 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:BaseLoadBalancerGenerates 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:
retainAssignmentin interfaceLoadBalancer- Overrides:
retainAssignmentin 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:
generateFavoredNodesForDaughterin 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:
generateFavoredNodesForMergedRegionin interfaceFavoredNodesPromoter- Throws:
IOException
-
balanceTable
protected List<RegionPlan> balanceTable(TableName tableName, Map<ServerName, List<RegionInfo>> loadOfOneTable) Description copied from class:StochasticLoadBalancerGiven the cluster state this will try and approach an optimal balance. This should always approach the optimal state given enough steps.- Overrides:
balanceTablein classStochasticLoadBalancer- Parameters:
tableName- the table to be balancedloadOfOneTable- region load of servers for the specific one table- Returns:
- List of plans
-