vanzin commented on a change in pull request #23951: [SPARK-13704][CORE][YARN] 
Re-implement RackResolver to reduce resolving time
URL: https://github.com/apache/spark/pull/23951#discussion_r266680433
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala
 ##########
 @@ -811,8 +811,36 @@ private[spark] class TaskSchedulerImpl(
     
blacklistTrackerOpt.map(_.nodeBlacklist()).getOrElse(scala.collection.immutable.Set())
   }
 
-  // By default, rack is unknown
-  def getRackForHost(value: String): Option[String] = None
+  // Add a on-off switch to save time for rack resolving
+  lazy val skipRackResolving: Boolean = sc.conf.get(LOCALITY_WAIT_RACK) == 0L
+
+  /**
+   * Rack is unknown by default.
+   * It can be override in different TaskScheduler, like Yarn.
+   */
+  def defaultRackValue: Option[String] = None
+
+  def doGetRacksForHosts(preferredLocation: List[String]): 
List[Option[String]] = Nil
+
+  def getRackForHost(value: String): Option[String] = {
+    if (skipRackResolving) {
+      defaultRackValue
+    } else {
+      doGetRacksForHosts(List(value)) match {
+        case Nil => None
+        case h :: Nil => h
+        case _ => None
+      }
+    }
+  }
+
+  def getRacksForHosts(values: List[String]): List[Option[String]] = {
 
 Review comment:
   `values` is a pretty bad name for this argument.
   
   Is there a case where you'll get a `None` inside this list? That seems to 
come from `Node.getNetworkLocation`, will that ever be `null`?
   
   Lists of options are always a bit awkward.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to