Github user squito commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8760#discussion_r40088646
  
    --- Diff: 
core/src/main/scala/org/apache/spark/scheduler/BlacklistTracker.scala ---
    @@ -0,0 +1,165 @@
    +/*
    + * 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.spark.scheduler
    +
    +import java.util.concurrent.TimeUnit
    +
    +import scala.collection.mutable
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.Success
    +import org.apache.spark.TaskEndReason
    +import org.apache.spark.annotation.DeveloperApi
    +import org.apache.spark.util.SystemClock
    +import org.apache.spark.util.ThreadUtils
    +import org.apache.spark.util.Utils
    +
    +
    +/**
    + * BlacklistTracker is design to track problematic executors and node on 
application level.
    + * It is shared by all TaskSet, so that once a new TaskSet coming, it 
could be benefit from
    + * previous experience of other TaskSet.
    + *
    + * Once task finished, the callback method in TaskSetManager should update 
failedExecutorMap.
    + */
    +class BlacklistTracker(sparkConf: SparkConf) {
    +  // maintain a ExecutorId --> FailureStatus HashMap
    +  private val failedExecutorMap: mutable.HashMap[String, FailureStatus] = 
mutable.HashMap()
    +
    +  // Apply Strategy pattern here to change different blacklist detection 
logic
    +  private val strategy = BlacklistStrategy(sparkConf)
    +
    +  // A daemon thread to expire blacklist executor periodically
    +  private val scheduler = 
ThreadUtils.newDaemonSingleThreadScheduledExecutor(
    +      "spark-scheduler-blacklist-expire-timer")
    +
    +  private val clock = new SystemClock()
    +
    +  def start(): Unit = {
    +    val scheduleTask = new Runnable() {
    +      override def run(): Unit = {
    +        
Utils.logUncaughtExceptions(expireExecutorsInBlackList(failedExecutorMap))
    +      }
    +    }
    +    scheduler.scheduleAtFixedRate(scheduleTask, 0L, 60, TimeUnit.SECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    scheduler.shutdown()
    +    scheduler.awaitTermination(10, TimeUnit.SECONDS)
    +  }
    +
    +  // The actual implementation is delegated to strategy
    +  private def expireExecutorsInBlackList(
    +      failureExecutors: mutable.HashMap[String, FailureStatus]): Unit = 
synchronized {
    +    strategy.expireExecutorsInBlackList(failureExecutors)
    +  }
    +
    +  def updateFailureExecutors(info: TaskInfo, reason: TaskEndReason) : Unit 
= synchronized {
    +    reason match {
    +      // If task succeeding, remove related record from failedExecutorMap
    +      case Success =>
    +        removeFailureExecutors(info.executorId, Some(info.taskId))
    +
    +      // If task failing, update latest failure time and failedTaskIds
    +      case _ =>
    +        val executorId = info.executorId
    +        failedExecutorMap.get(executorId) match {
    +          case Some(failureStatus) =>
    +            failureStatus.updatedTime = clock.getTimeMillis()
    +            val failedTimes = 
failureStatus.failedTasks.getOrElse(info.taskId, 0) + 1
    +            failureStatus.failedTasks.update(info.taskId, failedTimes)
    +          case None =>
    +            val failedTasks = mutable.HashMap(info.taskId -> 1)
    +            val failureStatus = new FailureStatus(
    +              clock.getTimeMillis(),
    +              info.host,
    +              failedTasks)
    +            failedExecutorMap.update(executorId, failureStatus)
    +        }
    +    }
    +  }
    +
    +  def removeFailureExecutors(
    +      executorId: String,
    +      taskId: Option[Long]) : Unit = synchronized {
    +        taskId match {
    +          // If taskId is provided, remove the taskId from failedTasks
    +          case Some(id) =>
    +            failedExecutorMap.get(executorId).map(fs => {
    +              fs.updatedTime = clock.getTimeMillis()
    +              fs.failedTasks.remove(id)
    +              if(fs.failedTasks.isEmpty){
    +                failedExecutorMap.remove(executorId)
    +              }
    +            })
    +          // if taskId is not provided, remove the whole record related to 
given executorId
    +          case None =>
    +            failedExecutorMap.remove(executorId)
    +        }
    +  }
    +
    +  def executorIsBlacklisted(
    +      executorId: String,
    +      sched: TaskSchedulerImpl,
    +      taskId: Option[Long]) : Boolean = {
    +
    +    executorBlacklist(sched, taskId).contains(executorId)
    +  }
    +
    +  // The actual implementation is delegated to strategy
    +  def executorBlacklist(
    +      sched: TaskSchedulerImpl,
    +      taskId: Option[Long]): Set[String] = synchronized {
    +
    +    // If the node is in blacklist, all executors allocated on that node 
will
    +    // also be put into  executor blacklist.
    +    // By default it's turned off, user can enable it in sparkConf.
    +    val speculationFailedExecutor: Set[String] =
    +      if (sparkConf.getBoolean("spark.scheduler.blacklist.speculate", 
false)) {
    +      Set.empty[String]
    +    } else {
    +      nodeBlacklist(taskId).flatMap(sched.getExecutorsAliveOnHost(_)
    +          .getOrElse(Set.empty[String])).toSet
    +    }
    +
    +    speculationFailedExecutor ++ 
strategy.getExecutorBlacklist(failedExecutorMap, taskId)
    +  }
    +
    +  // The actual implementation is delegated to strategy
    +  def nodeBlacklist(taskId: Option[Long] = None): Set[String] = 
synchronized {
    +    strategy.getNodeBlacklist(failedExecutorMap, taskId)
    +  }
    +}
    +
    +/**
    + * A class to record details of failure.
    + *
    + * @param initialTime the time when failure status be created
    + * @param host the node name which running executor on
    + * @param failedTasks all tasks failed on the executor (key is task id,
    + *  value is failure time of this task)
    + */
    +final class FailureStatus(
    +    initialTime: Long,
    +    val host: String,
    +    val failedTasks: mutable.HashMap[Long, Int]) {
    +
    +  var updatedTime = initialTime
    +  def failureTimes : Int = failedTasks.values.sum
    --- End diff --
    
    and then rename this to `totalNumFailures` or something like that


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to