From 026873c155dcd71120d28091fc58caf3945884c6 Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Tue, 18 Dec 2012 19:50:46 +0000 Subject: [PATCH] HADOOP-9152. HDFS can report negative DFS Used on clusters with very small amounts of data. Contributed by Brock Noland. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1423604 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../src/main/java/org/apache/hadoop/fs/DU.java | 2 +- .../src/test/java/org/apache/hadoop/fs/TestDU.java | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 20c9c6dec1e..fa36365716f 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -202,6 +202,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-9135. JniBasedUnixGroupsMappingWithFallback should log at debug rather than info during fallback. (Colin Patrick McCabe via todd) + HADOOP-9152. HDFS can report negative DFS Used on clusters with very small + amounts of data. (Brock Noland via atm) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java index 2c96b0abaf0..9a9f1e3efc7 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java @@ -136,7 +136,7 @@ public class DU extends Shell { } } - return used.longValue(); + return Math.max(used.longValue(), 0L); } /** diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java index de3d5566eb5..71024acd9e6 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java @@ -103,4 +103,12 @@ public class TestDU extends TestCase { duSize >= writtenSize && writtenSize <= (duSize + slack)); } + public void testDUGetUsedWillNotReturnNegative() throws IOException { + File file = new File(DU_DIR, "data"); + assertTrue(file.createNewFile()); + DU du = new DU(file, 10000); + du.decDfsUsed(Long.MAX_VALUE); + long duSize = du.getUsed(); + assertTrue(String.valueOf(duSize), duSize >= 0L); + } }