Class BlockPlacementPolicyRackFaultTolerant
java.lang.Object
org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy
org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault
org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyRackFaultTolerant
- Direct Known Subclasses:
AvailableSpaceRackFaultTolerantBlockPlacementPolicy
The class is responsible for choosing the desired number of targets
for placing block replicas.
The strategy is that it tries its best to place the replicas to most racks.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault
BlockPlacementPolicyDefault.NodeNotChosenReasonNested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy
BlockPlacementPolicy.NotEnoughReplicasException -
Field Summary
Fields inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault
clusterMap, considerLoad, considerLoadFactor, heartbeatInterval, host2datanodeMap, tolerateHeartbeatMultiplierFields inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy
LOG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.hadoop.net.NodechooseTargetInOrder(int numOfReplicas, org.apache.hadoop.net.Node writer, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, boolean newBlock, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) Choose numOfReplicas in order: 1.protected int[]getMaxNodesPerRack(int numOfChosen, int numOfReplicas) Calculate the maximum number of replicas to allocate per rack.protected Collection<DatanodeStorageInfo>pickupReplicaSet(Collection<DatanodeStorageInfo> moreThanOne, Collection<DatanodeStorageInfo> exactlyOne, Map<String, List<DatanodeStorageInfo>> rackMap) Pick up replica node set for deleting replica as over-replicated.verifyBlockPlacement(org.apache.hadoop.hdfs.protocol.DatanodeInfo[] locs, int numberOfReplicas) Verify if the block's placement meets requirement of placement policy, i.e. replicas are placed on no less than minRacks racks in the system.Methods inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault
addToExcludedNodes, chooseDataNode, chooseDataNode, chooseFavouredNodes, chooseLocalOrFavoredStorage, chooseLocalRack, chooseLocalStorage, chooseLocalStorage, chooseRandom, chooseRandom, chooseRemoteRack, chooseReplicasToDelete, chooseReplicaToDelete, chooseTarget, chooseTarget, getExcludeSlowNodesEnabled, getMinBlocksForWrite, initialize, isMovable, logNodeIsNotChosen, setExcludeSlowNodesEnabled, setMinBlocksForWriteMethods inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy
adjustSetsWithChosenReplica, getDatanodeInfo, getRack, splitNodesWithRack
-
Constructor Details
-
BlockPlacementPolicyRackFaultTolerant
public BlockPlacementPolicyRackFaultTolerant()
-
-
Method Details
-
getMaxNodesPerRack
protected int[] getMaxNodesPerRack(int numOfChosen, int numOfReplicas) Description copied from class:BlockPlacementPolicyDefaultCalculate the maximum number of replicas to allocate per rack. It also limits the total number of replicas to the total number of nodes in the cluster. Caller should adjust the replica count to the return value.- Overrides:
getMaxNodesPerRackin classBlockPlacementPolicyDefault- Parameters:
numOfChosen- The number of already chosen nodes.numOfReplicas- The number of additional nodes to allocate.- Returns:
- integer array. Index 0: The number of nodes allowed to allocate in addition to already chosen nodes. Index 1: The maximum allowed number of nodes per rack. This is independent of the number of chosen nodes, as it is calculated using the target number of replicas.
-
chooseTargetInOrder
protected org.apache.hadoop.net.Node chooseTargetInOrder(int numOfReplicas, org.apache.hadoop.net.Node writer, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, boolean newBlock, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasExceptionChoose numOfReplicas in order: 1. If total replica expected is less than numOfRacks in cluster, it choose randomly. 2. If total replica expected is bigger than numOfRacks, it choose: 2a. Fill each rack exactly (maxNodesPerRack-1) replicas. 2b. For some random racks, place one more replica to each one of them, until numOfReplicas have been chosen.
3. If after step 2, there are still replicas not placed (due to some racks have fewer datanodes than maxNodesPerRack), the rest of the replicas is placed evenly on the rest of the racks who have Datanodes that have not been placed a replica. 4. If after step 3, there are still replicas not placed. ABlockPlacementPolicy.NotEnoughReplicasExceptionis thrown.For normal setups, step 2 would suffice. So in the end, the difference of the numbers of replicas for each two racks is no more than 1. Either way it always prefer local storage.
- Overrides:
chooseTargetInOrderin classBlockPlacementPolicyDefault- Returns:
- local node of writer
- Throws:
BlockPlacementPolicy.NotEnoughReplicasException
-
verifyBlockPlacement
public BlockPlacementStatus verifyBlockPlacement(org.apache.hadoop.hdfs.protocol.DatanodeInfo[] locs, int numberOfReplicas) Description copied from class:BlockPlacementPolicyVerify if the block's placement meets requirement of placement policy, i.e. replicas are placed on no less than minRacks racks in the system.- Overrides:
verifyBlockPlacementin classBlockPlacementPolicyDefault- Parameters:
locs- block with locationsnumberOfReplicas- replica number of file to be verified- Returns:
- the result of verification
-
pickupReplicaSet
protected Collection<DatanodeStorageInfo> pickupReplicaSet(Collection<DatanodeStorageInfo> moreThanOne, Collection<DatanodeStorageInfo> exactlyOne, Map<String, List<DatanodeStorageInfo>> rackMap) Description copied from class:BlockPlacementPolicyDefaultPick up replica node set for deleting replica as over-replicated. First set contains replica nodes on rack with more than one replica while second set contains remaining replica nodes. If only 1 rack, pick all. If 2 racks, pick all that have more than 1 replicas on the same rack; if no such replicas, pick all. If 3 or more racks, pick all.- Overrides:
pickupReplicaSetin classBlockPlacementPolicyDefault
-