diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java index e9fb7f342f..70186e2552 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java @@ -207,8 +207,10 @@ private DatanodeStorageInfo[] chooseTarget(int numOfReplicas, final List results = new ArrayList(chosenStorage); for (DatanodeStorageInfo storage : chosenStorage) { - // add localMachine and related nodes to excludedNodes - addToExcludedNodes(storage.getDatanodeDescriptor(), excludedNodes); + if(storage!=null){ + // add localMachine and related nodes to excludedNodes + addToExcludedNodes(storage.getDatanodeDescriptor(), excludedNodes); + } } boolean avoidStaleNodes = (stats != null diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index bfa0ee2cb0..0057d770f3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -3165,7 +3165,11 @@ public Object performTask() throws IOException { //find datanode storages final DatanodeManager dm = blockManager.getDatanodeManager(); - chosen = Arrays.asList(dm.getDatanodeStorageInfos(existings, storageIDs)); + if(existings.length!=0){ + chosen = Arrays.asList(dm.getDatanodeStorageInfos(existings, storageIDs)); + } else { + chosen = Collections.emptyList(); + } // choose new datanodes. final DatanodeStorageInfo[] targets = blockManager.chooseTarget4AdditionalDatanode(