Class BlockPlacementPolicyDefault
java.lang.Object
org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy
org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault
- Direct Known Subclasses:
AvailableSpaceBlockPlacementPolicy,BlockPlacementPolicyRackFaultTolerant,BlockPlacementPolicyWithNodeGroup,BlockPlacementPolicyWithUpgradeDomain
The class is responsible for choosing the desired number of targets
for placing block replicas.
The replica placement strategy is that if the writer is on a datanode,
the 1st replica is placed on the local machine by default
(By passing the
CreateFlag.NO_LOCAL_WRITE flag
the client can request not to put a block replica on the local datanode.
Subsequent replicas will still follow default block placement policy.).
If the writer is not on a datanode, the 1st replica is placed on a random
node.
The 2nd replica is placed on a datanode that is on a different rack.
The 3rd replica is placed on a datanode which is on a different node of the
rack as the second replica.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumNested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy
BlockPlacementPolicy.NotEnoughReplicasException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.hadoop.net.NetworkTopologyprotected booleanprotected doubleprotected longprotected org.apache.hadoop.hdfs.server.blockmanagement.Host2NodesMapprotected intA miss of that many heartbeats is tolerated for replica deletion policy.Fields inherited from class org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy
LOG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intaddToExcludedNodes(DatanodeDescriptor localMachine, Set<org.apache.hadoop.net.Node> excludedNodes) Add localMachine and related nodes to excludedNodes for next replica choosing.protected DatanodeDescriptorchooseDataNode(String scope, Collection<org.apache.hadoop.net.Node> excludedNodes) Choose a datanode from the given scope.protected DatanodeDescriptorchooseDataNode(String scope, Collection<org.apache.hadoop.net.Node> excludedNodes, org.apache.hadoop.fs.StorageType type) Choose a datanode from the given scope with specified storage type.protected voidchooseFavouredNodes(String src, int numOfReplicas, List<DatanodeDescriptor> favoredNodes, Set<org.apache.hadoop.net.Node> favoriteAndExcludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) protected DatanodeStorageInfochooseLocalOrFavoredStorage(org.apache.hadoop.net.Node localOrFavoredNode, boolean isFavoredNode, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) Choose storage of local or favored node.protected DatanodeStorageInfochooseLocalRack(org.apache.hadoop.net.Node localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) Choose one node from the rack that localMachine is on.protected DatanodeStorageInfochooseLocalStorage(org.apache.hadoop.net.Node localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) protected DatanodeStorageInfochooseLocalStorage(org.apache.hadoop.net.Node localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes, boolean fallbackToLocalRack) Choose localMachine as the target.protected DatanodeStorageInfochooseRandom(int numOfReplicas, String scope, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) Randomly choose numOfReplicas targets from the given scope.protected DatanodeStorageInfochooseRandom(String scope, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) Randomly choose one target from the given scope.protected voidchooseRemoteRack(int numOfReplicas, DatanodeDescriptor localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxReplicasPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) Choose numOfReplicas nodes from the racks that localMachine is NOT on.chooseReplicasToDelete(Collection<DatanodeStorageInfo> availableReplicas, Collection<DatanodeStorageInfo> delCandidates, int expectedNumOfReplicas, List<org.apache.hadoop.fs.StorageType> excessTypes, DatanodeDescriptor addedNode, DatanodeDescriptor delNodeHint) Select the excess replica storages for deletion based on either delNodehint/Excess storage types.chooseReplicaToDelete(Collection<DatanodeStorageInfo> moreThanOne, Collection<DatanodeStorageInfo> exactlyOne, List<org.apache.hadoop.fs.StorageType> excessTypes, Map<String, List<DatanodeStorageInfo>> rackMap) Decide whether deleting the specified replica of the block still makes the block conform to the configured block placement policy.chooseTarget(String srcPath, int numOfReplicas, org.apache.hadoop.net.Node writer, List<DatanodeStorageInfo> chosenNodes, boolean returnChosenNodes, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy, EnumSet<org.apache.hadoop.hdfs.AddBlockFlag> flags) choose numOfReplicas data nodes for writer to re-replicate a block with size blocksize If not, return as many as we can.chooseTarget(String srcPath, int numOfReplicas, org.apache.hadoop.net.Node writer, List<DatanodeStorageInfo> chosen, boolean returnChosenNodes, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy, EnumSet<org.apache.hadoop.hdfs.AddBlockFlag> flags, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) protected 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) booleanprotected int[]getMaxNodesPerRack(int numOfChosen, int numOfReplicas) Calculate the maximum number of replicas to allocate per rack.intvoidinitialize(org.apache.hadoop.conf.Configuration conf, FSClusterStats stats, org.apache.hadoop.net.NetworkTopology clusterMap, org.apache.hadoop.hdfs.server.blockmanagement.Host2NodesMap host2datanodeMap) Used to setup a BlockPlacementPolicy object.booleanisMovable(Collection<org.apache.hadoop.hdfs.protocol.DatanodeInfo> locs, org.apache.hadoop.hdfs.protocol.DatanodeInfo source, org.apache.hadoop.hdfs.protocol.DatanodeInfo target) Check if the move is allowed.protected static voidlogNodeIsNotChosen(DatanodeDescriptor node, BlockPlacementPolicyDefault.NodeNotChosenReason reason, String reasonDetails) 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.voidsetExcludeSlowNodesEnabled(boolean enable) Updates the value used for excludeSlowNodesEnabled, which is set byDFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEYinitially.voidsetMinBlocksForWrite(int minBlocksForWrite) Updates the value used for minBlocksForWrite, which is set byDFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_MIN_BLOCKS_FOR_WRITE_KEY.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.BlockPlacementPolicy
adjustSetsWithChosenReplica, getDatanodeInfo, getRack, splitNodesWithRack
-
Field Details
-
considerLoad
protected boolean considerLoad -
considerLoadFactor
protected double considerLoadFactor -
clusterMap
protected org.apache.hadoop.net.NetworkTopology clusterMap -
host2datanodeMap
protected org.apache.hadoop.hdfs.server.blockmanagement.Host2NodesMap host2datanodeMap -
heartbeatInterval
protected long heartbeatInterval -
tolerateHeartbeatMultiplier
protected int tolerateHeartbeatMultiplierA miss of that many heartbeats is tolerated for replica deletion policy.
-
-
Constructor Details
-
BlockPlacementPolicyDefault
protected BlockPlacementPolicyDefault()
-
-
Method Details
-
initialize
public void initialize(org.apache.hadoop.conf.Configuration conf, FSClusterStats stats, org.apache.hadoop.net.NetworkTopology clusterMap, org.apache.hadoop.hdfs.server.blockmanagement.Host2NodesMap host2datanodeMap) Description copied from class:BlockPlacementPolicyUsed to setup a BlockPlacementPolicy object. This should be defined by all implementations of a BlockPlacementPolicy.- Specified by:
initializein classBlockPlacementPolicy- Parameters:
conf- the configuration objectstats- retrieve cluster status from hereclusterMap- cluster topology
-
chooseTarget
public DatanodeStorageInfo[] chooseTarget(String srcPath, int numOfReplicas, org.apache.hadoop.net.Node writer, List<DatanodeStorageInfo> chosenNodes, boolean returnChosenNodes, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy, EnumSet<org.apache.hadoop.hdfs.AddBlockFlag> flags) Description copied from class:BlockPlacementPolicychoose numOfReplicas data nodes for writer to re-replicate a block with size blocksize If not, return as many as we can.- Specified by:
chooseTargetin classBlockPlacementPolicy- Parameters:
srcPath- the file to which this chooseTargets is being invoked.numOfReplicas- additional number of replicas wanted.writer- the writer's machine, null if not in the cluster.chosenNodes- datanodes that have been chosen as targets.returnChosenNodes- decide if the chosenNodes are returned.excludedNodes- datanodes that should not be considered as targets.blocksize- size of the data to be written.flags- Block placement flags.- Returns:
- array of DatanodeDescriptor instances chosen as target and sorted as a pipeline.
-
chooseTarget
public DatanodeStorageInfo[] chooseTarget(String srcPath, int numOfReplicas, org.apache.hadoop.net.Node writer, List<DatanodeStorageInfo> chosen, boolean returnChosenNodes, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy, EnumSet<org.apache.hadoop.hdfs.AddBlockFlag> flags, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) - Overrides:
chooseTargetin classBlockPlacementPolicystorageTypes- storage types that should be used as targets.
-
chooseFavouredNodes
protected void chooseFavouredNodes(String src, int numOfReplicas, List<DatanodeDescriptor> favoredNodes, Set<org.apache.hadoop.net.Node> favoriteAndExcludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasException -
getMaxNodesPerRack
protected int[] getMaxNodesPerRack(int numOfChosen, int numOfReplicas) Calculate 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.- 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.NotEnoughReplicasException -
chooseLocalStorage
protected DatanodeStorageInfo chooseLocalStorage(org.apache.hadoop.net.Node localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasException -
chooseLocalOrFavoredStorage
protected DatanodeStorageInfo chooseLocalOrFavoredStorage(org.apache.hadoop.net.Node localOrFavoredNode, boolean isFavoredNode, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasExceptionChoose storage of local or favored node.- Parameters:
localOrFavoredNode- local or favored nodeisFavoredNode- if target node is favored nodeexcludedNodes- datanodes that should not be considered as targetsblocksize- size of the data to be writtenmaxNodesPerRack- max nodes allowed per rackresults- the target nodes already chosenavoidStaleNodes- avoid stale nodes in replica choosingstorageTypes- storage type to be considered for target- Returns:
- storage of local or favored node (not chosen node)
- Throws:
BlockPlacementPolicy.NotEnoughReplicasException
-
chooseLocalStorage
protected DatanodeStorageInfo chooseLocalStorage(org.apache.hadoop.net.Node localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes, boolean fallbackToLocalRack) throws BlockPlacementPolicy.NotEnoughReplicasExceptionChoose localMachine as the target. if localMachine is not available, choose a node on the same rack- Returns:
- the chosen storage
- Throws:
BlockPlacementPolicy.NotEnoughReplicasException
-
addToExcludedNodes
protected int addToExcludedNodes(DatanodeDescriptor localMachine, Set<org.apache.hadoop.net.Node> excludedNodes) Add localMachine and related nodes to excludedNodes for next replica choosing. In sub class, we can add more nodes within the same failure domain of localMachine- Returns:
- number of new excluded nodes
-
chooseLocalRack
protected DatanodeStorageInfo chooseLocalRack(org.apache.hadoop.net.Node localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasExceptionChoose one node from the rack that localMachine is on. if no such node is available, choose one node from the rack where a second replica is on. if still no such node is available, choose a random node in the cluster.- Returns:
- the chosen node
- Throws:
BlockPlacementPolicy.NotEnoughReplicasException
-
chooseRemoteRack
protected void chooseRemoteRack(int numOfReplicas, DatanodeDescriptor localMachine, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxReplicasPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasExceptionChoose numOfReplicas nodes from the racks that localMachine is NOT on. If not enough nodes are available, choose the remaining ones from the local rack -
chooseRandom
protected DatanodeStorageInfo chooseRandom(String scope, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasExceptionRandomly choose one target from the given scope.- Returns:
- the chosen storage, if there is any.
- Throws:
BlockPlacementPolicy.NotEnoughReplicasException
-
chooseRandom
protected DatanodeStorageInfo chooseRandom(int numOfReplicas, String scope, Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<org.apache.hadoop.fs.StorageType, Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasExceptionRandomly choose numOfReplicas targets from the given scope.- Returns:
- the first chosen node, if there is any.
- Throws:
BlockPlacementPolicy.NotEnoughReplicasException
-
chooseDataNode
protected DatanodeDescriptor chooseDataNode(String scope, Collection<org.apache.hadoop.net.Node> excludedNodes) Choose a datanode from the given scope.- Returns:
- the chosen node, if there is any.
-
chooseDataNode
protected DatanodeDescriptor chooseDataNode(String scope, Collection<org.apache.hadoop.net.Node> excludedNodes, org.apache.hadoop.fs.StorageType type) Choose a datanode from the given scope with specified storage type.- Returns:
- the chosen node, if there is any.
-
logNodeIsNotChosen
protected static void logNodeIsNotChosen(DatanodeDescriptor node, BlockPlacementPolicyDefault.NodeNotChosenReason reason, String reasonDetails) -
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.- Specified by:
verifyBlockPlacementin classBlockPlacementPolicy- Parameters:
locs- block with locationsnumberOfReplicas- replica number of file to be verified- Returns:
- the result of verification
-
chooseReplicaToDelete
@VisibleForTesting public DatanodeStorageInfo chooseReplicaToDelete(Collection<DatanodeStorageInfo> moreThanOne, Collection<DatanodeStorageInfo> exactlyOne, List<org.apache.hadoop.fs.StorageType> excessTypes, Map<String, List<DatanodeStorageInfo>> rackMap) Decide whether deleting the specified replica of the block still makes the block conform to the configured block placement policy.- Parameters:
moreThanOne- The replica locations of this block that are present on more than one unique racks.exactlyOne- Replica locations of this block that are present on exactly one unique racks.excessTypes- The excessStorageTypes according to theBlockStoragePolicy.- Returns:
- the replica that is the best candidate for deletion
-
chooseReplicasToDelete
public List<DatanodeStorageInfo> chooseReplicasToDelete(Collection<DatanodeStorageInfo> availableReplicas, Collection<DatanodeStorageInfo> delCandidates, int expectedNumOfReplicas, List<org.apache.hadoop.fs.StorageType> excessTypes, DatanodeDescriptor addedNode, DatanodeDescriptor delNodeHint) Description copied from class:BlockPlacementPolicySelect the excess replica storages for deletion based on either delNodehint/Excess storage types.- Specified by:
chooseReplicasToDeletein classBlockPlacementPolicy- Parameters:
availableReplicas- available replicasdelCandidates- Candidates for deletion. For normal replication, this set is the same with availableReplicas. For striped blocks, this set is a subset of availableReplicas.expectedNumOfReplicas- The expected number of replicas remaining in the delCandidatesexcessTypes- type of the storagepolicyaddedNode- New replica reporteddelNodeHint- Hint for excess storage selection- Returns:
- Returns the list of excess replicas chosen for deletion
-
isMovable
public boolean isMovable(Collection<org.apache.hadoop.hdfs.protocol.DatanodeInfo> locs, org.apache.hadoop.hdfs.protocol.DatanodeInfo source, org.apache.hadoop.hdfs.protocol.DatanodeInfo target) Description copied from class:BlockPlacementPolicyCheck if the move is allowed. Used by balancer and other tools.- Specified by:
isMovablein classBlockPlacementPolicy- Parameters:
locs- all replicas including source and targetsource- source replica of the movetarget- target replica of the move
-
pickupReplicaSet
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. 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. -
setExcludeSlowNodesEnabled
public void setExcludeSlowNodesEnabled(boolean enable) Description copied from class:BlockPlacementPolicyUpdates the value used for excludeSlowNodesEnabled, which is set byDFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEYinitially.- Specified by:
setExcludeSlowNodesEnabledin classBlockPlacementPolicy- Parameters:
enable- true, we will filter out slow nodes when choosing targets for blocks, otherwise false not filter.
-
getExcludeSlowNodesEnabled
public boolean getExcludeSlowNodesEnabled()- Specified by:
getExcludeSlowNodesEnabledin classBlockPlacementPolicy
-
setMinBlocksForWrite
public void setMinBlocksForWrite(int minBlocksForWrite) Description copied from class:BlockPlacementPolicyUpdates the value used for minBlocksForWrite, which is set byDFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_MIN_BLOCKS_FOR_WRITE_KEY.- Specified by:
setMinBlocksForWritein classBlockPlacementPolicy- Parameters:
minBlocksForWrite- the minimum number of blocks required for write operations.
-
getMinBlocksForWrite
public int getMinBlocksForWrite()- Specified by:
getMinBlocksForWritein classBlockPlacementPolicy
-