From 519092322dd1bf71984bef1393d8e082643408cd Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Tue, 28 Apr 2015 14:05:26 -0700 Subject: [PATCH] MAPREDUCE-6343. JobConf.parseMaximumHeapSizeMB() fails to parse value greater than 2GB expressed in bytes. (Hao Xia via kasha) --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../java/org/apache/hadoop/mapred/JobConf.java | 10 +++++----- .../org/apache/hadoop/mapred/TestJobConf.java | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 2090007d74..e9e1a4b0ef 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -188,6 +188,9 @@ Trunk (Unreleased) MAPREDUCE-6234. TestHighRamJob fails due to the change in MAPREDUCE-5785. (Masatake Iwasaki via kasha) + MAPREDUCE-6343. JobConf.parseMaximumHeapSizeMB() fails to parse value + greater than 2GB expressed in bytes. (Hao Xia via kasha) + BREAKDOWN OF MAPREDUCE-2841 (NATIVE TASK) SUBTASKS MAPREDUCE-5985. native-task: Fix build on macosx. Contributed by diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobConf.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobConf.java index 9cac685db2..059593ae2a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobConf.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobConf.java @@ -2080,28 +2080,28 @@ public static int parseMaximumHeapSizeMB(String javaOpts) { // Find the last matching -Xmx following word boundaries Matcher m = JAVA_OPTS_XMX_PATTERN.matcher(javaOpts); if (m.matches()) { - int size = Integer.parseInt(m.group(1)); + long size = Long.parseLong(m.group(1)); if (size <= 0) { return -1; } if (m.group(2).isEmpty()) { // -Xmx specified in bytes - return size / (1024 * 1024); + return (int) (size / (1024 * 1024)); } char unit = m.group(2).charAt(0); switch (unit) { case 'g': case 'G': // -Xmx specified in GB - return size * 1024; + return (int) (size * 1024); case 'm': case 'M': // -Xmx specified in MB - return size; + return (int) size; case 'k': case 'K': // -Xmx specified in KB - return size / 1024; + return (int) (size / 1024); } } // -Xmx not specified diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobConf.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobConf.java index 0612ade83d..57fa4e69d8 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobConf.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobConf.java @@ -361,4 +361,20 @@ public void testMaxTaskFailuresPerTracker() { jobConf.getMaxTaskFailuresPerTracker() < jobConf.getMaxReduceAttempts() ); } + + /** + * Test parsing various types of Java heap options. + */ + @Test + public void testParseMaximumHeapSizeMB() { + // happy cases + Assert.assertEquals(4096, JobConf.parseMaximumHeapSizeMB("-Xmx4294967296")); + Assert.assertEquals(4096, JobConf.parseMaximumHeapSizeMB("-Xmx4194304k")); + Assert.assertEquals(4096, JobConf.parseMaximumHeapSizeMB("-Xmx4096m")); + Assert.assertEquals(4096, JobConf.parseMaximumHeapSizeMB("-Xmx4g")); + + // sad cases + Assert.assertEquals(-1, JobConf.parseMaximumHeapSizeMB("-Xmx4?")); + Assert.assertEquals(-1, JobConf.parseMaximumHeapSizeMB("")); + } }