diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java index f66ac42a9e9..4d3f1d1a51e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java @@ -1484,9 +1484,13 @@ public class BlockManager implements BlockStatsMXBean { */ public boolean isSufficientlyReplicated(BlockInfo b) { // Compare against the lesser of the minReplication and number of live DNs. - final int replication = - Math.min(minReplication, getDatanodeManager().getNumLiveDataNodes()); - return countNodes(b).liveReplicas() >= replication; + final int liveReplicas = countNodes(b).liveReplicas(); + if (liveReplicas >= minReplication) { + return true; + } + // getNumLiveDataNodes() is very expensive and we minimize its use by + // comparing with minReplication first. + return liveReplicas >= getDatanodeManager().getNumLiveDataNodes(); } /** Get all blocks with location information from a datanode. */