diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 029c03259b7..f8d27c66845 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -482,6 +482,9 @@ Branch-2 ( Unreleased changes ) HADOOP-8431. Running distcp wo args throws IllegalArgumentException. (Sandy Ryza via eli) + HADOOP-8775. MR2 distcp permits non-positive value to -bandwidth option + which causes job never to complete. (Sandy Ryza via atm) + BREAKDOWN OF HDFS-3042 SUBTASKS HADOOP-8220. ZKFailoverController doesn't handle failure to become active diff --git a/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java b/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java index fe78b70448a..79487e59b90 100644 --- a/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java +++ b/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java @@ -156,6 +156,10 @@ public class OptionsParser { try { Integer mapBandwidth = Integer.parseInt( getVal(command, DistCpOptionSwitch.BANDWIDTH.getSwitch()).trim()); + if (mapBandwidth.intValue() <= 0) { + throw new IllegalArgumentException("Bandwidth specified is not positive: " + + mapBandwidth); + } option.setMapBandwidth(mapBandwidth); } catch (NumberFormatException e) { throw new IllegalArgumentException("Bandwidth specified is invalid: " + diff --git a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java index 14c409e8b26..5ab345c7246 100644 --- a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java +++ b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java @@ -110,6 +110,24 @@ public class TestOptionsParser { "hdfs://localhost:8020/target/"}); Assert.assertEquals(options.getMapBandwidth(), 11); } + + @Test(expected=IllegalArgumentException.class) + public void testParseNonPositiveBandwidth() { + OptionsParser.parse(new String[] { + "-bandwidth", + "-11", + "hdfs://localhost:8020/source/first", + "hdfs://localhost:8020/target/"}); + } + + @Test(expected=IllegalArgumentException.class) + public void testParseZeroBandwidth() { + OptionsParser.parse(new String[] { + "-bandwidth", + "0", + "hdfs://localhost:8020/source/first", + "hdfs://localhost:8020/target/"}); + } @Test public void testParseSkipCRC() {