diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java index eb65b3843a9c4..caf88c89bf87c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java @@ -652,24 +652,27 @@ private void scanDatanodeStorage(DatanodeDescriptor dn, Iterator it = s.getBlockIterator(); while (it.hasNext()) { BlockInfo b = it.next(); - if (!initialScan || dn.isEnteringMaintenance()) { - // this is a rescan, so most blocks should be replicated now, - // or this node is going into maintenance. On a healthy - // cluster using racks or upgrade domain, a node should be - // able to go into maintenance without replicating many blocks - // so we will check them immediately. - if (!isBlockReplicatedOk(dn, b, false, null)) { - blockList.put(b, null); - } - } else { - blockList.put(b, null); - } + blockList.put(b, null); numBlocksChecked++; } } finally { namesystem.readUnlock(); } } + if (!initialScan || dn.isEnteringMaintenance()) { + // this is a rescan, so most blocks should be replicated now, + // or this node is going into maintenance. On a healthy + // cluster using racks or upgrade domain, a node should be + // able to go into maintenance without replicating many blocks + // so we will check them immediately. + Iterator iterator = blockList.keySet().iterator(); + while(iterator.hasNext()) { + BlockInfo b = iterator.next(); + if (isBlockReplicatedOk(dn, b, false, null)) { + iterator.remove(); + } + } + } } /**