hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1099590 - in /hadoop/mapreduce/trunk: CHANGES.txt src/java/org/apache/hadoop/mapred/TaskRunner.java src/test/mapred/org/apache/hadoop/mapred/TestTaskChildOptsParsing.java
Date Wed, 04 May 2011 20:24:03 GMT
Author: todd
Date: Wed May  4 20:24:02 2011
New Revision: 1099590

URL: http://svn.apache.org/viewvc?rev=1099590&view=rev
Log:
MAPREDUCE-2472. Extra whitespace in mapred.child.java.opts breaks JVM initialization. Contributed
by Aaron T. Myers.

Added:
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskChildOptsParsing.java
Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=1099590&r1=1099589&r2=1099590&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Wed May  4 20:24:02 2011
@@ -692,6 +692,9 @@ Release 0.22.0 - Unreleased
     MAPREDUCE-2457. Job submission should inject group.name on the JobTracker
     (Alejandro Abdelnur via todd)
 
+    MAPREDUCE-2472. Extra whitespace in mapred.child.java.opts breaks JVM
+    initialization. (Aaron T. Myers via todd)
+
 Release 0.21.1 - Unreleased
 
   NEW FEATURES

Modified: hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java?rev=1099590&r1=1099589&r2=1099590&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java (original)
+++ hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java Wed May  4 20:24:02
2011
@@ -331,6 +331,20 @@ abstract class TaskRunner extends Thread
   }
 
   /**
+   * Parse the given string and return an array of individual java opts. Split
+   * on whitespace and replace the special string "@taskid@" with the task ID
+   * given.
+   * 
+   * @param javaOpts The string to parse
+   * @param taskid The task ID to replace the special string with
+   * @return An array of individual java opts.
+   */
+  static String[] parseChildJavaOpts(String javaOpts, TaskAttemptID taskid) {
+    javaOpts = javaOpts.replace("@taskid@", taskid.toString());
+    return javaOpts.trim().split("\\s+");
+  }
+
+  /**
    * @param taskid
    * @param workDir
    * @param classPaths
@@ -375,10 +389,9 @@ abstract class TaskRunner extends Thread
     //    </value>
     //  </property>
     //
-    String javaOpts = getChildJavaOpts(conf, 
-                                       JobConf.DEFAULT_MAPRED_TASK_JAVA_OPTS);
-    javaOpts = javaOpts.replace("@taskid@", taskid.toString());
-    String [] javaOptsSplit = javaOpts.split(" ");
+    String[] javaOptsSplit = parseChildJavaOpts(getChildJavaOpts(conf,
+                                       JobConf.DEFAULT_MAPRED_TASK_JAVA_OPTS),
+                                       taskid);
     
     // Add java.library.path; necessary for loading native libraries.
     //

Added: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskChildOptsParsing.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskChildOptsParsing.java?rev=1099590&view=auto
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskChildOptsParsing.java
(added)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskChildOptsParsing.java
Wed May  4 20:24:02 2011
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.mapred;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestTaskChildOptsParsing {
+  
+  @SuppressWarnings("deprecation")
+  private static final TaskAttemptID TASK_ID = new TaskAttemptID();
+  private static final String[] EXPECTED_RESULTS = new String[]{"-Dfoo=bar", "-Dbaz=biz"};
+  
+  private void performTest(String input) {
+    String[] result = TaskRunner.parseChildJavaOpts(input, TASK_ID);
+    assertArrayEquals(EXPECTED_RESULTS, result);
+  }
+  
+  @Test
+  public void testParseChildJavaOptsLeadingSpace() {
+    performTest(" -Dfoo=bar -Dbaz=biz");
+  }
+  
+  @Test
+  public void testParseChildJavaOptsTrailingSpace() {
+    performTest("-Dfoo=bar -Dbaz=biz ");
+  }
+  
+  @Test
+  public void testParseChildJavaOptsOneSpace() {
+    performTest("-Dfoo=bar -Dbaz=biz");
+  }
+  
+  @Test
+  public void testParseChildJavaOptsMulitpleSpaces() {
+    performTest("-Dfoo=bar  -Dbaz=biz");
+  }
+  
+  @Test
+  public void testParseChildJavaOptsOneTab() {
+    performTest("-Dfoo=bar\t-Dbaz=biz");
+  }
+  
+  @Test
+  public void testParseChildJavaOptsMultipleTabs() {
+    performTest("-Dfoo=bar\t\t-Dbaz=biz");
+  }
+}



Mime
View raw message