AvailableSpaceBlockPlacementPolicy, BlockPlacementPolicyRackFaultTolerant, BlockPlacementPolicyWithNodeGroup, BlockPlacementPolicyWithUpgradeDomain@Private public class BlockPlacementPolicyDefault extends BlockPlacementPolicy
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.BlockPlacementPolicy.NotEnoughReplicasException| Modifier and Type | Field | Description |
|---|---|---|
protected org.apache.hadoop.net.NetworkTopology |
clusterMap |
|
protected boolean |
considerLoad |
|
protected double |
considerLoadFactor |
|
protected long |
heartbeatInterval |
|
protected org.apache.hadoop.hdfs.server.blockmanagement.Host2NodesMap |
host2datanodeMap |
|
protected int |
tolerateHeartbeatMultiplier |
A miss of that many heartbeats is tolerated for replica deletion policy.
|
LOG| Modifier | Constructor | Description |
|---|---|---|
protected |
BlockPlacementPolicyDefault() |
| Modifier and Type | Method | Description |
|---|---|---|
protected int |
addToExcludedNodes(DatanodeDescriptor localMachine,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes) |
Add localMachine and related nodes to excludedNodes
for next replica choosing.
|
protected DatanodeDescriptor |
chooseDataNode(java.lang.String scope,
java.util.Collection<org.apache.hadoop.net.Node> excludedNodes) |
Choose a datanode from the given scope.
|
protected DatanodeDescriptor |
chooseDataNode(java.lang.String scope,
java.util.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 void |
chooseFavouredNodes(java.lang.String src,
int numOfReplicas,
java.util.List<DatanodeDescriptor> favoredNodes,
java.util.Set<org.apache.hadoop.net.Node> favoriteAndExcludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
|
protected DatanodeStorageInfo |
chooseLocalOrFavoredStorage(org.apache.hadoop.net.Node localOrFavoredNode,
boolean isFavoredNode,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
Choose storage of local or favored node.
|
protected DatanodeStorageInfo |
chooseLocalRack(org.apache.hadoop.net.Node localMachine,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
Choose one node from the rack that localMachine is on.
|
protected DatanodeStorageInfo |
chooseLocalStorage(org.apache.hadoop.net.Node localMachine,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
|
protected DatanodeStorageInfo |
chooseLocalStorage(org.apache.hadoop.net.Node localMachine,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes,
boolean fallbackToLocalRack) |
Choose localMachine as the target.
|
protected DatanodeStorageInfo |
chooseRandom(int numOfReplicas,
java.lang.String scope,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
Randomly choose numOfReplicas targets from the given scope.
|
protected DatanodeStorageInfo |
chooseRandom(java.lang.String scope,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
Randomly choose one target from the given scope.
|
protected void |
chooseRemoteRack(int numOfReplicas,
DatanodeDescriptor localMachine,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxReplicasPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
Choose numOfReplicas nodes from the racks
that localMachine is NOT on.
|
java.util.List<DatanodeStorageInfo> |
chooseReplicasToDelete(java.util.Collection<DatanodeStorageInfo> availableReplicas,
java.util.Collection<DatanodeStorageInfo> delCandidates,
int expectedNumOfReplicas,
java.util.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.
|
DatanodeStorageInfo |
chooseReplicaToDelete(java.util.Collection<DatanodeStorageInfo> moreThanOne,
java.util.Collection<DatanodeStorageInfo> exactlyOne,
java.util.List<org.apache.hadoop.fs.StorageType> excessTypes,
java.util.Map<java.lang.String,java.util.List<DatanodeStorageInfo>> rackMap) |
Decide whether deleting the specified replica of the block still makes
the block conform to the configured block placement policy.
|
DatanodeStorageInfo[] |
chooseTarget(java.lang.String srcPath,
int numOfReplicas,
org.apache.hadoop.net.Node writer,
java.util.List<DatanodeStorageInfo> chosenNodes,
boolean returnChosenNodes,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy,
java.util.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.
|
DatanodeStorageInfo[] |
chooseTarget(java.lang.String srcPath,
int numOfReplicas,
org.apache.hadoop.net.Node writer,
java.util.List<DatanodeStorageInfo> chosen,
boolean returnChosenNodes,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy,
java.util.EnumSet<org.apache.hadoop.hdfs.AddBlockFlag> flags,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
|
protected org.apache.hadoop.net.Node |
chooseTargetInOrder(int numOfReplicas,
org.apache.hadoop.net.Node writer,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
boolean newBlock,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) |
|
boolean |
getExcludeSlowNodesEnabled() |
|
protected int[] |
getMaxNodesPerRack(int numOfChosen,
int numOfReplicas) |
Calculate the maximum number of replicas to allocate per rack.
|
int |
getMinBlocksForWrite() |
|
void |
initialize(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.
|
boolean |
isMovable(java.util.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 java.util.Collection<DatanodeStorageInfo> |
pickupReplicaSet(java.util.Collection<DatanodeStorageInfo> moreThanOne,
java.util.Collection<DatanodeStorageInfo> exactlyOne,
java.util.Map<java.lang.String,java.util.List<DatanodeStorageInfo>> rackMap) |
Pick up replica node set for deleting replica as over-replicated.
|
void |
setExcludeSlowNodesEnabled(boolean enable) |
Updates the value used for excludeSlowNodesEnabled, which is set by
DFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY
initially. |
void |
setMinBlocksForWrite(int minBlocksForWrite) |
Updates the value used for minBlocksForWrite, which is set by
DFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_MIN_BLOCKS_FOR_WRITE_KEY. |
BlockPlacementStatus |
verifyBlockPlacement(org.apache.hadoop.hdfs.protocol.DatanodeInfo[] locs,
int numberOfReplicas) |
Verify if the block's placement meets requirement of placement policy,
i.e.
|
adjustSetsWithChosenReplica, getDatanodeInfo, getRack, splitNodesWithRackprotected boolean considerLoad
protected double considerLoadFactor
protected org.apache.hadoop.net.NetworkTopology clusterMap
protected org.apache.hadoop.hdfs.server.blockmanagement.Host2NodesMap host2datanodeMap
protected long heartbeatInterval
protected int tolerateHeartbeatMultiplier
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)
BlockPlacementPolicyinitialize in class BlockPlacementPolicyconf - the configuration objectstats - retrieve cluster status from hereclusterMap - cluster topologypublic DatanodeStorageInfo[] chooseTarget(java.lang.String srcPath, int numOfReplicas, org.apache.hadoop.net.Node writer, java.util.List<DatanodeStorageInfo> chosenNodes, boolean returnChosenNodes, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy, java.util.EnumSet<org.apache.hadoop.hdfs.AddBlockFlag> flags)
BlockPlacementPolicychooseTarget in class BlockPlacementPolicysrcPath - 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.public DatanodeStorageInfo[] chooseTarget(java.lang.String srcPath, int numOfReplicas, org.apache.hadoop.net.Node writer, java.util.List<DatanodeStorageInfo> chosen, boolean returnChosenNodes, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, org.apache.hadoop.hdfs.protocol.BlockStoragePolicy storagePolicy, java.util.EnumSet<org.apache.hadoop.hdfs.AddBlockFlag> flags, java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes)
chooseTarget in class BlockPlacementPolicystorageTypes - storage types that should be used as targets.protected void chooseFavouredNodes(java.lang.String src,
int numOfReplicas,
java.util.List<DatanodeDescriptor> favoredNodes,
java.util.Set<org.apache.hadoop.net.Node> favoriteAndExcludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes)
throws BlockPlacementPolicy.NotEnoughReplicasException
protected int[] getMaxNodesPerRack(int numOfChosen,
int numOfReplicas)
numOfChosen - The number of already chosen nodes.numOfReplicas - The number of additional nodes to allocate.protected org.apache.hadoop.net.Node chooseTargetInOrder(int numOfReplicas,
org.apache.hadoop.net.Node writer,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxNodesPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
boolean newBlock,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes)
throws BlockPlacementPolicy.NotEnoughReplicasException
protected DatanodeStorageInfo chooseLocalStorage(org.apache.hadoop.net.Node localMachine, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, java.util.List<DatanodeStorageInfo> results, boolean avoidStaleNodes, java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasException
protected DatanodeStorageInfo chooseLocalOrFavoredStorage(org.apache.hadoop.net.Node localOrFavoredNode, boolean isFavoredNode, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, java.util.List<DatanodeStorageInfo> results, boolean avoidStaleNodes, java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasException
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 targetBlockPlacementPolicy.NotEnoughReplicasExceptionprotected DatanodeStorageInfo chooseLocalStorage(org.apache.hadoop.net.Node localMachine, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, java.util.List<DatanodeStorageInfo> results, boolean avoidStaleNodes, java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes, boolean fallbackToLocalRack) throws BlockPlacementPolicy.NotEnoughReplicasException
BlockPlacementPolicy.NotEnoughReplicasExceptionprotected int addToExcludedNodes(DatanodeDescriptor localMachine, java.util.Set<org.apache.hadoop.net.Node> excludedNodes)
protected DatanodeStorageInfo chooseLocalRack(org.apache.hadoop.net.Node localMachine, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, java.util.List<DatanodeStorageInfo> results, boolean avoidStaleNodes, java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasException
BlockPlacementPolicy.NotEnoughReplicasExceptionprotected void chooseRemoteRack(int numOfReplicas,
DatanodeDescriptor localMachine,
java.util.Set<org.apache.hadoop.net.Node> excludedNodes,
long blocksize,
int maxReplicasPerRack,
java.util.List<DatanodeStorageInfo> results,
boolean avoidStaleNodes,
java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes)
throws BlockPlacementPolicy.NotEnoughReplicasException
protected DatanodeStorageInfo chooseRandom(java.lang.String scope, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, java.util.List<DatanodeStorageInfo> results, boolean avoidStaleNodes, java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasException
BlockPlacementPolicy.NotEnoughReplicasExceptionprotected DatanodeStorageInfo chooseRandom(int numOfReplicas, java.lang.String scope, java.util.Set<org.apache.hadoop.net.Node> excludedNodes, long blocksize, int maxNodesPerRack, java.util.List<DatanodeStorageInfo> results, boolean avoidStaleNodes, java.util.EnumMap<org.apache.hadoop.fs.StorageType,java.lang.Integer> storageTypes) throws BlockPlacementPolicy.NotEnoughReplicasException
BlockPlacementPolicy.NotEnoughReplicasExceptionprotected DatanodeDescriptor chooseDataNode(java.lang.String scope, java.util.Collection<org.apache.hadoop.net.Node> excludedNodes)
protected DatanodeDescriptor chooseDataNode(java.lang.String scope, java.util.Collection<org.apache.hadoop.net.Node> excludedNodes, org.apache.hadoop.fs.StorageType type)
public BlockPlacementStatus verifyBlockPlacement(org.apache.hadoop.hdfs.protocol.DatanodeInfo[] locs, int numberOfReplicas)
BlockPlacementPolicyverifyBlockPlacement in class BlockPlacementPolicylocs - block with locationsnumberOfReplicas - replica number of file to be verified@VisibleForTesting public DatanodeStorageInfo chooseReplicaToDelete(java.util.Collection<DatanodeStorageInfo> moreThanOne, java.util.Collection<DatanodeStorageInfo> exactlyOne, java.util.List<org.apache.hadoop.fs.StorageType> excessTypes, java.util.Map<java.lang.String,java.util.List<DatanodeStorageInfo>> rackMap)
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 excess StorageTypes according to the
BlockStoragePolicy.public java.util.List<DatanodeStorageInfo> chooseReplicasToDelete(java.util.Collection<DatanodeStorageInfo> availableReplicas, java.util.Collection<DatanodeStorageInfo> delCandidates, int expectedNumOfReplicas, java.util.List<org.apache.hadoop.fs.StorageType> excessTypes, DatanodeDescriptor addedNode, DatanodeDescriptor delNodeHint)
BlockPlacementPolicychooseReplicasToDelete in class BlockPlacementPolicyavailableReplicas - 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 selectionpublic boolean isMovable(java.util.Collection<org.apache.hadoop.hdfs.protocol.DatanodeInfo> locs,
org.apache.hadoop.hdfs.protocol.DatanodeInfo source,
org.apache.hadoop.hdfs.protocol.DatanodeInfo target)
BlockPlacementPolicyisMovable in class BlockPlacementPolicylocs - all replicas including source and targetsource - source replica of the movetarget - target replica of the moveprotected java.util.Collection<DatanodeStorageInfo> pickupReplicaSet(java.util.Collection<DatanodeStorageInfo> moreThanOne, java.util.Collection<DatanodeStorageInfo> exactlyOne, java.util.Map<java.lang.String,java.util.List<DatanodeStorageInfo>> rackMap)
public void setExcludeSlowNodesEnabled(boolean enable)
BlockPlacementPolicyDFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY
initially.setExcludeSlowNodesEnabled in class BlockPlacementPolicyenable - true, we will filter out slow nodes
when choosing targets for blocks, otherwise false not filter.public boolean getExcludeSlowNodesEnabled()
getExcludeSlowNodesEnabled in class BlockPlacementPolicypublic void setMinBlocksForWrite(int minBlocksForWrite)
BlockPlacementPolicyDFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_MIN_BLOCKS_FOR_WRITE_KEY.setMinBlocksForWrite in class BlockPlacementPolicyminBlocksForWrite - the minimum number of blocks required for write operations.public int getMinBlocksForWrite()
getMinBlocksForWrite in class BlockPlacementPolicyCopyright © 2008–2025 Apache Software Foundation. All rights reserved.