Browse Source

MAPREDUCE-6198. NPE from JobTracker#resolveAndAddToTopology in MR1 cause initJob and heartbeat failure. (zxu via rkanter)

Robert Kanter 10 years ago
parent
commit
eb5191195a

+ 3 - 0
CHANGES.txt

@@ -262,6 +262,9 @@ Release 1.3.0 - unreleased
     MAPREDUCE-6196. Fix BigDecimal ArithmeticException in PiEstimator
     (rchiang via rkanter)
 
+    MAPREDUCE-6198. NPE from JobTracker#resolveAndAddToTopology in MR1 cause
+    initJob and heartbeat failure. (zxu via rkanter)
+
 Release 1.2.2 - unreleased
 
   INCOMPATIBLE CHANGES

+ 2 - 2
src/core/org/apache/hadoop/net/ScriptBasedMapping.java

@@ -42,8 +42,8 @@ implements Configurable
   static final int MIN_ALLOWABLE_ARGS = 1;
   
   static final int DEFAULT_ARG_COUNT = 100;
-  
-  static final String SCRIPT_FILENAME_KEY = "topology.script.file.name";
+
+  public static final String SCRIPT_FILENAME_KEY = "topology.script.file.name";
   static final String SCRIPT_ARG_COUNT_KEY = "topology.script.number.args";
   
   public ScriptBasedMapping(Configuration conf) {

+ 8 - 1
src/mapred/org/apache/hadoop/mapred/JobTracker.java

@@ -2818,7 +2818,14 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
     List <String> tmpList = new ArrayList<String>(1);
     tmpList.add(name);
     List <String> rNameList = dnsToSwitchMapping.resolve(tmpList);
-    String rName = rNameList.get(0);
+    String rName = null;
+    if (rNameList == null || rNameList.get(0) == null) {
+      rName = NetworkTopology.DEFAULT_RACK;
+      LOG.warn("Couldn't resolve " + name + ". Falling back to "
+          + NetworkTopology.DEFAULT_RACK);
+    } else {
+      rName = rNameList.get(0);
+    }
     String networkLoc = NodeBase.normalize(rName);
     return addHostToNodeMapping(name, networkLoc);
   }

+ 43 - 0
src/test/org/apache/hadoop/mapred/TestJobTrackerTopology.java

@@ -0,0 +1,43 @@
+/**
+ * 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 junit.framework.TestCase;
+import org.apache.hadoop.net.ScriptBasedMapping;
+import org.junit.Assert;
+
+/**
+ * Test {@link JobTracker} w.r.t resolveAndAddToTopology.
+ */
+public class TestJobTrackerTopology extends TestCase {
+
+  public void testJobTrackerResolveAndAddToTopology() throws Exception {
+    JobConf conf = new JobConf();
+    conf.set(ScriptBasedMapping.SCRIPT_FILENAME_KEY,
+        "test.sh");
+    conf = MiniMRCluster.configureJobConf(conf, "file:///", 0, 0, null);
+
+    JobTracker jt = JobTracker.startTracker(conf);
+    try {
+      jt.resolveAndAddToTopology("test.host");
+    } catch (NullPointerException e) {
+      Assert.fail("NullPointerException should not happen");
+    }
+    jt.stopTracker();
+  }
+}