Package org.apache.hadoop.hbase.favored
Class FavoredNodeAssignmentHelper
java.lang.Object
org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper
Helper class for
FavoredNodeLoadBalancer
that has all the intelligence for racks, meta
scans, etc. Instantiated by the FavoredNodeLoadBalancer
when needed (from within calls
like FavoredNodeLoadBalancer.randomAssignment(RegionInfo, List)
). All updates to favored
nodes should only be done from FavoredNodesManager
and not through this helper class
(except for tests).-
Field Summary
Modifier and TypeFieldDescriptionstatic final short
static final byte[]
private static final org.slf4j.Logger
static final short
private RackManager
private Map<String,
List<ServerName>> private List<ServerName>
-
Constructor Summary
ConstructorDescriptionFavoredNodeAssignmentHelper
(List<ServerName> servers, org.apache.hadoop.conf.Configuration conf) FavoredNodeAssignmentHelper
(List<ServerName> servers, RackManager rackManager) -
Method Summary
Modifier and TypeMethodDescriptionboolean
private Map<RegionInfo,
List<ServerName>> generateFavoredNodes
(Map<RegionInfo, ServerName> primaryRSMap) generateFavoredNodesRoundRobin
(Map<ServerName, List<RegionInfo>> assignmentMap, List<RegionInfo> regions) generateMissingFavoredNode
(List<ServerName> favoredNodes) generateMissingFavoredNode
(List<ServerName> favoredNodes, List<ServerName> excludeNodes) private ServerName
generateMissingFavoredNodeMultiRack
(List<ServerName> favoredNodes) private ServerName
generateMissingFavoredNodeMultiRack
(List<ServerName> favoredNodes, List<ServerName> excludeNodes) private ServerName
generateMissingFavoredNodeSingleRack
(List<ServerName> favoredNodes, List<ServerName> excludeNodes) static byte[]
getFavoredNodes
(List<ServerName> serverAddrList) Returns PB'ed bytes ofHBaseProtos.FavoredNodes
generated by the server list.static String
getFavoredNodesAsString
(List<ServerName> nodes) static ServerName[]
getFavoredNodesList
(byte[] favoredNodes) Convert PB bytes to ServerName.(package private) String
getOneRandomRack
(Set<String> skipRackSet) private ServerName
getOneRandomServer
(String rack) protected ServerName
getOneRandomServer
(String rack, Set<ServerName> skipServerSet) Gets a random server from the specified rack and skips anything specified.private String
getSecondaryAndTertiary
(RegionInfo regionInfo, ServerName primaryRS) private List<ServerName>
getServersFromRack
(String rack) private int
void
private static Put
makePut
(RegionInfo regionInfo, List<ServerName> favoredNodeList) private Map<ServerName,
Set<RegionInfo>> mapRSToPrimaries
(Map<RegionInfo, ServerName> primaryRSMap) private ServerName[]
multiRackCase
(ServerName primaryRS, String primaryRack) Place secondary and tertiary nodes in a multi rack case.private ServerName[]
multiRackCaseWithRestrictions
(Map<ServerName, Set<RegionInfo>> serverToPrimaries, Map<RegionInfo, ServerName[]> secondaryAndTertiaryMap, String primaryRack, ServerName primaryRS, RegionInfo regionInfo) void
placePrimaryRSAsRoundRobin
(Map<ServerName, List<RegionInfo>> assignmentMap, Map<RegionInfo, ServerName> primaryRSMap, List<RegionInfo> regions) placeSecondaryAndTertiaryRS
(Map<RegionInfo, ServerName> primaryRSMap) placeSecondaryAndTertiaryWithRestrictions
(Map<RegionInfo, ServerName> primaryRSMap) For regions that share the primary, avoid placing the secondary and tertiary on a same RS.private ServerName[]
singleRackCase
(RegionInfo regionInfo, ServerName primaryRS, String primaryRack) static void
updateMetaWithFavoredNodesInfo
(Map<RegionInfo, List<ServerName>> regionToFavoredNodes, org.apache.hadoop.conf.Configuration conf) Update meta table with favored nodes infostatic void
updateMetaWithFavoredNodesInfo
(Map<RegionInfo, List<ServerName>> regionToFavoredNodes, Connection connection) Update meta table with favored nodes info
-
Field Details
-
LOG
-
rackManager
-
rackToRegionServerMap
-
uniqueRackList
-
regionServerToRackMap
-
servers
-
FAVOREDNODES_QUALIFIER
-
FAVORED_NODES_NUM
- See Also:
-
MAX_ATTEMPTS_FN_GENERATION
- See Also:
-
-
Constructor Details
-
FavoredNodeAssignmentHelper
public FavoredNodeAssignmentHelper(List<ServerName> servers, org.apache.hadoop.conf.Configuration conf) -
FavoredNodeAssignmentHelper
-
-
Method Details
-
initialize
-
updateMetaWithFavoredNodesInfo
public static void updateMetaWithFavoredNodesInfo(Map<RegionInfo, List<ServerName>> regionToFavoredNodes, Connection connection) throws IOExceptionUpdate meta table with favored nodes info- Parameters:
regionToFavoredNodes
- map of RegionInfo's to their favored nodesconnection
- connection to be used- Throws:
IOException
-
updateMetaWithFavoredNodesInfo
public static void updateMetaWithFavoredNodesInfo(Map<RegionInfo, List<ServerName>> regionToFavoredNodes, org.apache.hadoop.conf.Configuration conf) throws IOExceptionUpdate meta table with favored nodes info- Throws:
IOException
-
makePut
private static Put makePut(RegionInfo regionInfo, List<ServerName> favoredNodeList) throws IOException - Throws:
IOException
-
getFavoredNodesList
Convert PB bytes to ServerName.- Parameters:
favoredNodes
- The PB'ed bytes of favored nodes- Returns:
- the array of
ServerName
for the byte array of favored nodes. - Throws:
IOException
-
getFavoredNodes
Returns PB'ed bytes ofHBaseProtos.FavoredNodes
generated by the server list. -
placePrimaryRSAsRoundRobin
public void placePrimaryRSAsRoundRobin(Map<ServerName, List<RegionInfo>> assignmentMap, Map<RegionInfo, ServerName> primaryRSMap, List<RegionInfo> regions) -
placeSecondaryAndTertiaryRS
public Map<RegionInfo,ServerName[]> placeSecondaryAndTertiaryRS(Map<RegionInfo, ServerName> primaryRSMap) -
getSecondaryAndTertiary
public ServerName[] getSecondaryAndTertiary(RegionInfo regionInfo, ServerName primaryRS) throws IOException - Throws:
IOException
-
mapRSToPrimaries
-
placeSecondaryAndTertiaryWithRestrictions
public Map<RegionInfo,ServerName[]> placeSecondaryAndTertiaryWithRestrictions(Map<RegionInfo, ServerName> primaryRSMap) For regions that share the primary, avoid placing the secondary and tertiary on a same RS. Used for generating new assignments for the primary/secondary/tertiary RegionServers- Returns:
- the map of regions to the servers the region-files should be hosted on
-
multiRackCaseWithRestrictions
private ServerName[] multiRackCaseWithRestrictions(Map<ServerName, Set<RegionInfo>> serverToPrimaries, Map<RegionInfo, throws IOExceptionServerName[]> secondaryAndTertiaryMap, String primaryRack, ServerName primaryRS, RegionInfo regionInfo) - Throws:
IOException
-
singleRackCase
private ServerName[] singleRackCase(RegionInfo regionInfo, ServerName primaryRS, String primaryRack) throws IOException - Throws:
IOException
-
multiRackCase
Place secondary and tertiary nodes in a multi rack case. If there are only two racks, then we try the place the secondary and tertiary on different rack than primary. But if the other rack has only one region server, then we place primary and tertiary on one rack and secondary on another. The aim is two distribute the three favored nodes on >= 2 racks. TODO: see how we can use generateMissingFavoredNodeMultiRack API here- Parameters:
primaryRS
- The primary favored node.primaryRack
- The rack of the primary favored node.- Returns:
- Array containing secondary and tertiary favored nodes.
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
canPlaceFavoredNodes
-
getTotalNumberOfRacks
-
getServersFromRack
-
getOneRandomServer
Gets a random server from the specified rack and skips anything specified.- Parameters:
rack
- rack from a server is neededskipServerSet
- the server shouldn't belong to this set
-
getOneRandomServer
- Throws:
IOException
-
getOneRandomRack
- Throws:
IOException
-
getFavoredNodesAsString
-
generateMissingFavoredNode
- Throws:
IOException
-
generateMissingFavoredNode
public ServerName generateMissingFavoredNode(List<ServerName> favoredNodes, List<ServerName> excludeNodes) throws IOException - Throws:
IOException
-
generateMissingFavoredNodeSingleRack
private ServerName generateMissingFavoredNodeSingleRack(List<ServerName> favoredNodes, List<ServerName> excludeNodes) throws IOException - Throws:
IOException
-
generateMissingFavoredNodeMultiRack
private ServerName generateMissingFavoredNodeMultiRack(List<ServerName> favoredNodes) throws IOException - Throws:
IOException
-
generateMissingFavoredNodeMultiRack
private ServerName generateMissingFavoredNodeMultiRack(List<ServerName> favoredNodes, List<ServerName> excludeNodes) throws IOException - Throws:
IOException
-
generateFavoredNodes
- Throws:
IOException
-
generateFavoredNodesRoundRobin
public Map<RegionInfo,List<ServerName>> generateFavoredNodesRoundRobin(Map<ServerName, List<RegionInfo>> assignmentMap, List<RegionInfo> regions) throws IOException- Throws:
IOException
-
generateFavoredNodes
private Map<RegionInfo,List<ServerName>> generateFavoredNodes(Map<RegionInfo, ServerName> primaryRSMap) -
getRackOfServer
-