From 80732146c6f8d8dcbf233c8767473bba67e4f891 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Fri, 15 Mar 2019 11:06:42 -0700 Subject: [PATCH] HDFS-14366. Improve HDFS append performance. Contributed by Chao Sun. (cherry picked from commit ff06ef0631cb8a0f67bbc39b5b5a1b0a81ca3b3c) --- .../hdfs/server/blockmanagement/BlockManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 92ea202846a..b08ba20f0bf 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 @@ -1469,9 +1469,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. */