From 901b1739c63306f7742fb0d453584a60c3f55753 Mon Sep 17 00:00:00 2001 From: Jitendra Nath Pandey Date: Wed, 22 Aug 2012 18:44:44 +0000 Subject: [PATCH] HDFS-3819. Should check whether invalidate work percentage default value is not greater than 1.0f. Contributed by Jing Zhao. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1376185 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../java/org/apache/hadoop/hdfs/DFSUtil.java | 6 +-- .../TestReplicationPolicy.java | 47 +++++++++++++++++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 7f84efec959..5c143a3191e 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 0a95af86b1a..2ce21379b0e 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 class DFSUtil { 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 81b38c9bd40..ada74ce7fc9 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 class TestReplicationPolicy { } /** - * 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 class TestReplicationPolicy { 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); }