From e45b10365568185d0fd22546a4b666fa77dea7a9 Mon Sep 17 00:00:00 2001 From: Harsh J Date: Fri, 28 Sep 2012 16:48:01 +0000 Subject: [PATCH] MAPREDUCE-4678. Running the Pentomino example with defaults throws java.lang.NegativeArraySizeException. Contributed by Chris McConnell. (harsh) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1391551 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 2 ++ .../dancing/DistributedPentomino.java | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 8cea603343..26ba089d9d 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -132,6 +132,8 @@ Trunk (Unreleased) MAPREDUCE-3223. Remove MR1 configs from mapred-default.xml (tlipcon via harsh) + MAPREDUCE-4678. Running the Pentomino example with defaults throws + java.lang.NegativeArraySizeException (Chris McConnell via harsh) Release 2.0.3-alpha - Unreleased diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/dancing/DistributedPentomino.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/dancing/DistributedPentomino.java index 09d65b0bb5..5f76d87ea2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/dancing/DistributedPentomino.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/dancing/DistributedPentomino.java @@ -165,16 +165,30 @@ public static void main(String[] args) throws Exception { } public int run(String[] args) throws Exception { + Configuration conf = getConf(); if (args.length == 0) { - System.out.println("pentomino "); + System.out.println("Usage: pentomino [-depth #] [-height #] [-width #]"); ToolRunner.printGenericCommandUsage(System.out); return 2; } - - Configuration conf = getConf(); - int width = conf.getInt(Pentomino.WIDTH, PENT_WIDTH); - int height = conf.getInt(Pentomino.HEIGHT, PENT_HEIGHT); - int depth = conf.getInt(Pentomino.DEPTH, PENT_DEPTH); + // check for passed parameters, otherwise use defaults + int width = PENT_WIDTH; + int height = PENT_HEIGHT; + int depth = PENT_DEPTH; + for (int i = 0; i < args.length; i++) { + if (args[i].equalsIgnoreCase("-depth")) { + depth = Integer.parseInt(args[i++].trim()); + } else if (args[i].equalsIgnoreCase("-height")) { + height = Integer.parseInt(args[i++].trim()); + } else if (args[i].equalsIgnoreCase("-width") ) { + width = Integer.parseInt(args[i++].trim()); + } + } + // now set the values within conf for M/R tasks to read, this + // will ensure values are set preventing MAPREDUCE-4678 + conf.setInt(Pentomino.WIDTH, width); + conf.setInt(Pentomino.HEIGHT, height); + conf.setInt(Pentomino.DEPTH, depth); Class pentClass = conf.getClass(Pentomino.CLASS, OneSidedPentomino.class, Pentomino.class); int numMaps = conf.getInt(MRJobConfig.NUM_MAPS, DEFAULT_MAPS);