hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1135895 - in /hadoop/common/branches/MR-279/mapreduce: ./ mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/ mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/a...
Date Wed, 15 Jun 2011 02:10:33 GMT
Author: ddas
Date: Wed Jun 15 02:10:32 2011
New Revision: 1135895

URL: http://svn.apache.org/viewvc?rev=1135895&view=rev
Log:
Changes for invoking rack resolution in the RM and in the AM. Contributed by Devaraj Das.

Added:
    hadoop/common/branches/MR-279/mapreduce/yarn/yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
Modified:
    hadoop/common/branches/MR-279/mapreduce/CHANGES.txt
    hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TaskAttemptImpl.java
    hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java
    hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTrackerImpl.java

Modified: hadoop/common/branches/MR-279/mapreduce/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/CHANGES.txt?rev=1135895&r1=1135894&r2=1135895&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/CHANGES.txt (original)
+++ hadoop/common/branches/MR-279/mapreduce/CHANGES.txt Wed Jun 15 02:10:32 2011
@@ -5,6 +5,8 @@ Trunk (unreleased changes)
 
     MAPREDUCE-279
 
+    Changes for invoking rack resolution in the RM and in the AM (ddas)
+
     Fix ClassCastException in JobHistoryServer for certain jobs.
     (Siddharth Seth via llu)
 

Modified: hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TaskAttemptImpl.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TaskAttemptImpl.java?rev=1135895&r1=1135894&r2=1135895&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TaskAttemptImpl.java
(original)
+++ hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TaskAttemptImpl.java
Wed Jun 15 02:10:32 2011
@@ -114,6 +114,7 @@ import org.apache.hadoop.yarn.state.Stat
 import org.apache.hadoop.yarn.state.StateMachineFactory;
 import org.apache.hadoop.yarn.util.BuilderUtils;
 import org.apache.hadoop.yarn.util.ConverterUtils;
+import org.apache.hadoop.yarn.util.RackResolver;
 
 /**
  * Implementation of TaskAttempt interface.
@@ -417,6 +418,7 @@ public abstract class TaskAttemptImpl im
     this.resourceCapability = recordFactory.newRecordInstance(Resource.class);
     this.resourceCapability.setMemory(getMemoryRequired(conf, taskId.getTaskType()));
     this.dataLocalHosts = dataLocalHosts;
+    RackResolver.init(conf);
 
     // This "this leak" is okay because the retained pointer is in an
     //  instance variable.
@@ -872,7 +874,6 @@ public abstract class TaskAttemptImpl im
     return tauce;
   }
 
-  private static String[] racks = new String[] {NetworkTopology.DEFAULT_RACK};
   private static class RequestContainerTransition implements
       SingleArcTransition<TaskAttemptImpl, TaskAttemptEvent> {
     boolean rescheduled = false;
@@ -892,6 +893,11 @@ public abstract class TaskAttemptImpl im
                 taskAttempt.attemptId, 
                 taskAttempt.resourceCapability));
       } else {
+        int i = 0;
+        String[] racks = new String[taskAttempt.dataLocalHosts.length];
+        for (String host : taskAttempt.dataLocalHosts) {
+          racks[i++] = RackResolver.resolve(host).getNetworkLocation();
+        }
         taskAttempt.eventHandler.handle(
             new ContainerRequestEvent(taskAttempt.attemptId, 
                 taskAttempt.resourceCapability, 

Modified: hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java?rev=1135895&r1=1135894&r2=1135895&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java
(original)
+++ hadoop/common/branches/MR-279/mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java
Wed Jun 15 02:10:32 2011
@@ -51,6 +51,7 @@ import org.apache.hadoop.yarn.api.record
 import org.apache.hadoop.yarn.api.records.ContainerState;
 import org.apache.hadoop.yarn.api.records.Priority;
 import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
+import org.apache.hadoop.yarn.util.RackResolver;
 
 /**
  * Allocates the container from the ResourceManager scheduler.
@@ -136,6 +137,7 @@ public class RMContainerAllocator extend
     maxReducePreemptionLimit = conf.getFloat(
         AMConstants.REDUCE_PREEMPTION_LIMIT,
         AMConstants.DEFAULT_REDUCE_PREEMPTION_LIMIT);
+    RackResolver.init(conf);
   }
 
   @Override
@@ -616,8 +618,7 @@ public class RMContainerAllocator extend
           }
         }
         if (assigned == null) {
-          // TODO: get rack
-          String rack = "";
+          String rack = RackResolver.resolve(host).getNetworkLocation();
           list = mapsRackMapping.get(rack);
           while (list != null && list.size() > 0) {
             TaskAttemptId tId = list.removeFirst();

Added: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java?rev=1135895&view=auto
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
(added)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
Wed Jun 15 02:10:32 2011
@@ -0,0 +1,94 @@
+/**
+* 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.yarn.util;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.net.DNSToSwitchMapping;
+import org.apache.hadoop.net.Node;
+import org.apache.hadoop.net.NodeBase;
+import org.apache.hadoop.net.ScriptBasedMapping;
+
+public class RackResolver {
+  private static DNSToSwitchMapping dnsToSwitchMapping;
+  private static boolean initCalled = false;
+  private static final Log LOG = LogFactory.getLog(RackResolver.class);
+
+  public synchronized static void init(Configuration conf) {
+    if (initCalled) {
+      return;
+    } else {
+      initCalled = true;
+    }
+    Class<? extends DNSToSwitchMapping> dnsToSwitchMappingClass =
+      conf.getClass(
+        CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY, 
+        ScriptBasedMapping.class,
+        DNSToSwitchMapping.class);
+    try {
+      Constructor<? extends DNSToSwitchMapping> dnsToSwitchMappingConstructor
+                             = dnsToSwitchMappingClass.getConstructor();
+      dnsToSwitchMapping = dnsToSwitchMappingConstructor.newInstance();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+  
+  /**
+   * Utility method for getting a hostname resolved to a node in the
+   * network topology. This method initializes the class with the 
+   * right resolver implementation.
+   * @param conf
+   * @param hostName
+   * @return
+   */
+  public static Node resolve(Configuration conf, String hostName) {
+    init(conf);
+    return coreResolve(hostName);
+  }
+
+  /**
+   * Utility method for getting a hostname resolved to a node in the
+   * network topology. This method doesn't initialize the class.
+   * Call {@link #init(Configuration)} explicitly.
+   * @param hostName
+   * @return
+   */
+  public static Node resolve(String hostName) {
+    if (!initCalled) {
+      throw new IllegalStateException("RackResolver class not yet initialized");
+    }
+    return coreResolve(hostName);
+  }
+  
+  private static Node coreResolve(String hostName) {
+    List <String> tmpList = new ArrayList<String>(1);
+    tmpList.add(hostName);
+    List <String> rNameList = dnsToSwitchMapping.resolve(tmpList);
+    String rName = rNameList.get(0);
+    LOG.info("Resolved " + hostName + " to " + rName);
+    return new NodeBase(hostName, rName);
+  }
+}

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTrackerImpl.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTrackerImpl.java?rev=1135895&r1=1135894&r2=1135895&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTrackerImpl.java
(original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTrackerImpl.java
Wed Jun 15 02:10:32 2011
@@ -36,9 +36,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience.Private;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.net.NetworkTopology;
 import org.apache.hadoop.net.Node;
-import org.apache.hadoop.net.NodeBase;
 import org.apache.hadoop.util.HostsFileReader;
 import org.apache.hadoop.yarn.Lock;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
@@ -64,6 +62,7 @@ import org.apache.hadoop.yarn.server.res
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
 import org.apache.hadoop.yarn.server.security.ContainerTokenSecretManager;
 import org.apache.hadoop.yarn.service.AbstractService;
+import org.apache.hadoop.yarn.util.RackResolver;
 
 /**
  * This class is responsible for the interaction with the NodeManagers.
@@ -153,6 +152,7 @@ NodeTracker, ClusterTracker {
         this.hostsReader = null;
       }
     }
+    RackResolver.init(conf);
   }
 
   private void printConfiguredHosts() {
@@ -194,7 +194,7 @@ NodeTracker, ClusterTracker {
    */
   @Lock(Lock.NoLock.class)
   public static Node resolve(String hostName) {
-    return new NodeBase(hostName, NetworkTopology.DEFAULT_RACK);
+    return RackResolver.resolve(hostName);
   }
   
   @Lock(Lock.NoLock.class)



Mime
View raw message