From f24684ca9cd70326e24376a33cda937c98295af0 Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Fri, 28 Dec 2018 10:34:18 -0800 Subject: [PATCH] HDFS-14171. Performance improvement in Tailing EditLog. Contributed by Kenneth Yang. (cherry picked from commit e9a005dfcf4d2249235aeff4da85b321dddc1ca9) (cherry picked from commit c48640ffbd3852b75f898325ae0b3ea0ba864578) --- .../hdfs/server/blockmanagement/BlockManagerSafeMode.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java index 8de17ef5c37..b730f61fe40 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java @@ -561,7 +561,12 @@ class BlockManagerSafeMode { */ private boolean areThresholdsMet() { assert namesystem.hasWriteLock(); - int datanodeNum = blockManager.getDatanodeManager().getNumLiveDataNodes(); + // Calculating the number of live datanodes is time-consuming + // in large clusters. Skip it when datanodeThreshold is zero. + int datanodeNum = 0; + if (datanodeThreshold > 0) { + datanodeNum = blockManager.getDatanodeManager().getNumLiveDataNodes(); + } synchronized (this) { return blockSafe >= blockThreshold && datanodeNum >= datanodeThreshold; }