From 770cc462281518545e3d1c0f8c21cf9ec9673200 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Mon, 24 Jul 2017 16:23:01 +0900 Subject: [PATCH] HDFS-12176. dfsadmin shows DFS Used%: NaN% if the cluster has zero block. Contributed by Weiwei Yang. --- .../main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java index ea76093724..f2233eb3ac 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java @@ -520,9 +520,13 @@ public void report(String[] argv, int i) throws IOException { + " (" + StringUtils.byteDesc(remaining) + ")"); System.out.println("DFS Used: " + used + " (" + StringUtils.byteDesc(used) + ")"); + double dfsUsedPercent = 0; + if (presentCapacity != 0) { + dfsUsedPercent = used/(double)presentCapacity; + } System.out.println("DFS Used%: " - + StringUtils.formatPercent(used/(double)presentCapacity, 2)); - + + StringUtils.formatPercent(dfsUsedPercent, 2)); + /* These counts are not always upto date. They are updated after * iteration of an internal list. Should be updated in a few seconds to * minutes. Use "-metaSave" to list of all such blocks and accurate