diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 7f84efec95..5c143a3191 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -123,6 +123,9 @@ Trunk (unreleased changes) HDFS-3817. Avoid printing SafeModeException stack trace. (Brandon Li via suresh) + HDFS-3819. Should check whether invalidate work percentage default value is + not greater than 1.0f. (Jing Zhao via jitendra) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java index 0a95af86b1..2ce21379b0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java @@ -1156,11 +1156,11 @@ public static float getInvalidateWorkPctPerIteration(Configuration conf) { DFSConfigKeys.DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION, DFSConfigKeys.DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION_DEFAULT); Preconditions.checkArgument( - (blocksInvalidateWorkPct > 0), + (blocksInvalidateWorkPct > 0 && blocksInvalidateWorkPct <= 1.0f), DFSConfigKeys.DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION + " = '" + blocksInvalidateWorkPct + "' is invalid. " + - "It should be a positive, non-zero float value " + - "indicating a percentage."); + "It should be a positive, non-zero float value, not greater than 1.0f, " + + "to indicate a percentage."); return blocksInvalidateWorkPct; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java index 81b38c9bd4..ada74ce7fc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java @@ -642,10 +642,10 @@ public void testChooseReplicaToDelete() throws Exception { } /** - * This testcase tests whether the defaultvalue returned by + * This testcase tests whether the default value returned by * DFSUtil.getInvalidateWorkPctPerIteration() is positive, * and whether an IllegalArgumentException will be thrown - * when a non-positive value is retrieved + * when 0.0f is retrieved */ @Test public void testGetInvalidateWorkPctPerIteration() { @@ -660,7 +660,48 @@ public void testGetInvalidateWorkPctPerIteration() { assertEquals(blocksInvalidateWorkPct, 0.5f, blocksInvalidateWorkPct * 1e-7); conf.set(DFSConfigKeys. - DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION, "0.0"); + DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION, "1.0f"); + blocksInvalidateWorkPct = DFSUtil.getInvalidateWorkPctPerIteration(conf); + assertEquals(blocksInvalidateWorkPct, 1.0f, blocksInvalidateWorkPct * 1e-7); + + conf.set(DFSConfigKeys. + DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION, "0.0f"); + exception.expect(IllegalArgumentException.class); + blocksInvalidateWorkPct = DFSUtil.getInvalidateWorkPctPerIteration(conf); + } + + /** + * This testcase tests whether an IllegalArgumentException + * will be thrown when a negative value is retrieved by + * DFSUtil#getInvalidateWorkPctPerIteration + */ + @Test + public void testGetInvalidateWorkPctPerIteration_NegativeValue() { + Configuration conf = new Configuration(); + float blocksInvalidateWorkPct = DFSUtil + .getInvalidateWorkPctPerIteration(conf); + assertTrue(blocksInvalidateWorkPct > 0); + + conf.set(DFSConfigKeys. + DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION, "-0.5f"); + exception.expect(IllegalArgumentException.class); + blocksInvalidateWorkPct = DFSUtil.getInvalidateWorkPctPerIteration(conf); + } + + /** + * This testcase tests whether an IllegalArgumentException + * will be thrown when a value greater than 1 is retrieved by + * DFSUtil#getInvalidateWorkPctPerIteration + */ + @Test + public void testGetInvalidateWorkPctPerIteration_GreaterThanOne() { + Configuration conf = new Configuration(); + float blocksInvalidateWorkPct = DFSUtil + .getInvalidateWorkPctPerIteration(conf); + assertTrue(blocksInvalidateWorkPct > 0); + + conf.set(DFSConfigKeys. + DFS_NAMENODE_INVALIDATE_WORK_PCT_PER_ITERATION, "1.5f"); exception.expect(IllegalArgumentException.class); blocksInvalidateWorkPct = DFSUtil.getInvalidateWorkPctPerIteration(conf); }