From 041a1e0a5289b4808d3f9e8e38427c7c449e96fb Mon Sep 17 00:00:00 2001 From: Jitendra Nath Pandey Date: Thu, 23 Aug 2012 04:05:12 +0000 Subject: [PATCH] Merged from trunk for HDFS-3819. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1376360 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 443535bc1f9..45dff7a5b67 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -224,6 +224,9 @@ Release 2.0.1-alpha - UNRELEASED HDFS-3832. Remove protocol methods related to DistributedUpgrade. (suresh) + HDFS-3819. Should check whether invalidate work percentage default value is + not greater than 1.0f. (Jing Zhao via jitendra) + OPTIMIZATIONS HDFS-2982. Startup performance suffers when there are many edit log 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 f1fbde63566..4c4dc1bd68d 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 @@ -1162,11 +1162,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 9a3f96c3b52..a10a0a3cf63 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 @@ -595,10 +595,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() { @@ -613,7 +613,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); }