|
@@ -266,6 +266,7 @@ import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
|
|
import org.apache.hadoop.metrics2.util.MBeans;
|
|
|
import org.apache.hadoop.net.NetworkTopology;
|
|
|
import org.apache.hadoop.net.Node;
|
|
|
+import org.apache.hadoop.net.NodeBase;
|
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
|
|
@@ -3122,7 +3123,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
final long blockSize;
|
|
|
final int replication;
|
|
|
final byte storagePolicyID;
|
|
|
- DatanodeDescriptor clientNode = null;
|
|
|
+ Node clientNode = null;
|
|
|
+ String clientMachine = null;
|
|
|
|
|
|
if(NameNode.stateChangeLog.isDebugEnabled()) {
|
|
|
NameNode.stateChangeLog.debug("BLOCK* NameSystem.getAdditionalBlock: "
|
|
@@ -3153,14 +3155,20 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
+ maxBlocksPerFile);
|
|
|
}
|
|
|
blockSize = pendingFile.getPreferredBlockSize();
|
|
|
+ clientMachine = pendingFile.getFileUnderConstructionFeature()
|
|
|
+ .getClientMachine();
|
|
|
clientNode = blockManager.getDatanodeManager().getDatanodeByHost(
|
|
|
- pendingFile.getFileUnderConstructionFeature().getClientMachine());
|
|
|
+ clientMachine);
|
|
|
replication = pendingFile.getFileReplication();
|
|
|
storagePolicyID = pendingFile.getStoragePolicyID();
|
|
|
} finally {
|
|
|
readUnlock();
|
|
|
}
|
|
|
|
|
|
+ if (clientNode == null) {
|
|
|
+ clientNode = getClientNode(clientMachine);
|
|
|
+ }
|
|
|
+
|
|
|
// choose targets for the new block to be allocated.
|
|
|
final DatanodeStorageInfo targets[] = getBlockManager().chooseTarget4NewBlock(
|
|
|
src, replication, clientNode, excludedNodes, blockSize, favoredNodes,
|
|
@@ -3217,6 +3225,24 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
return makeLocatedBlock(newBlock, targets, offset);
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * Resolve clientmachine address to get a network location path
|
|
|
+ */
|
|
|
+ private Node getClientNode(String clientMachine) {
|
|
|
+ List<String> hosts = new ArrayList<String>(1);
|
|
|
+ hosts.add(clientMachine);
|
|
|
+ List<String> rName = getBlockManager().getDatanodeManager()
|
|
|
+ .resolveNetworkLocation(hosts);
|
|
|
+ Node clientNode = null;
|
|
|
+ if (rName != null) {
|
|
|
+ // Able to resolve clientMachine mapping.
|
|
|
+ // Create a temp node to findout the rack local nodes
|
|
|
+ clientNode = new NodeBase(rName.get(0) + NodeBase.PATH_SEPARATOR_STR
|
|
|
+ + clientMachine);
|
|
|
+ }
|
|
|
+ return clientNode;
|
|
|
+ }
|
|
|
+
|
|
|
static class FileState {
|
|
|
public final INodeFile inode;
|
|
|
public final String path;
|
|
@@ -3350,7 +3376,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
//check if the feature is enabled
|
|
|
dtpReplaceDatanodeOnFailure.checkEnabled();
|
|
|
|
|
|
- final DatanodeDescriptor clientnode;
|
|
|
+ Node clientnode = null;
|
|
|
+ String clientMachine;
|
|
|
final long preferredblocksize;
|
|
|
final byte storagePolicyID;
|
|
|
final List<DatanodeStorageInfo> chosen;
|
|
@@ -3375,8 +3402,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
if (inode != null) src = inode.getFullPathName();
|
|
|
}
|
|
|
final INodeFile file = checkLease(src, clientName, inode, fileId);
|
|
|
- String clientMachine = file.getFileUnderConstructionFeature()
|
|
|
- .getClientMachine();
|
|
|
+ clientMachine = file.getFileUnderConstructionFeature().getClientMachine();
|
|
|
clientnode = blockManager.getDatanodeManager().getDatanodeByHost(clientMachine);
|
|
|
preferredblocksize = file.getPreferredBlockSize();
|
|
|
storagePolicyID = file.getStoragePolicyID();
|
|
@@ -3388,6 +3414,10 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
readUnlock();
|
|
|
}
|
|
|
|
|
|
+ if (clientnode == null) {
|
|
|
+ clientnode = getClientNode(clientMachine);
|
|
|
+ }
|
|
|
+
|
|
|
// choose new datanodes.
|
|
|
final DatanodeStorageInfo[] targets = blockManager.chooseTarget4AdditionalDatanode(
|
|
|
src, numAdditionalNodes, clientnode, chosen,
|