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

    https://github.com/apache/spark/pull/14710#discussion_r76899230
  
    --- Diff: 
core/src/main/scala/org/apache/spark/scheduler/cluster/CoarseGrainedSchedulerBackend.scala
 ---
    @@ -532,39 +547,53 @@ class CoarseGrainedSchedulerBackend(scheduler: 
TaskSchedulerImpl, val rpcEnv: Rp
       final def killExecutors(
           executorIds: Seq[String],
           replace: Boolean,
    -      force: Boolean): Boolean = synchronized {
    +      force: Boolean): Boolean = {
         logInfo(s"Requesting to kill executor(s) ${executorIds.mkString(", 
")}")
    -    val (knownExecutors, unknownExecutors) = 
executorIds.partition(executorDataMap.contains)
    -    unknownExecutors.foreach { id =>
    -      logWarning(s"Executor to kill $id does not exist!")
    -    }
     
    -    // If an executor is already pending to be removed, do not kill it 
again (SPARK-9795)
    -    // If this executor is busy, do not kill it unless we are told to 
force kill it (SPARK-9552)
    -    val executorsToKill = knownExecutors
    -      .filter { id => !executorsPendingToRemove.contains(id) }
    -      .filter { id => force || !scheduler.isExecutorBusy(id) }
    -    executorsToKill.foreach { id => executorsPendingToRemove(id) = 
!replace }
    -
    -    // If we do not wish to replace the executors we kill, sync the target 
number of executors
    -    // with the cluster manager to avoid allocating new ones. When 
computing the new target,
    -    // take into account executors that are pending to be added or removed.
    -    if (!replace) {
    -      doRequestTotalExecutors(
    -        numExistingExecutors + numPendingExecutors - 
executorsPendingToRemove.size)
    -    } else {
    -      numPendingExecutors += knownExecutors.size
    +    val response = synchronized {
    +      val (knownExecutors, unknownExecutors) = 
executorIds.partition(executorDataMap.contains)
    +      unknownExecutors.foreach { id =>
    +        logWarning(s"Executor to kill $id does not exist!")
    +      }
    +
    +      // If an executor is already pending to be removed, do not kill it 
again (SPARK-9795)
    +      // If this executor is busy, do not kill it unless we are told to 
force kill it (SPARK-9552)
    +      val executorsToKill = knownExecutors
    +        .filter { id => !executorsPendingToRemove.contains(id) }
    +        .filter { id => force || !scheduler.isExecutorBusy(id) }
    +      executorsToKill.foreach { id => executorsPendingToRemove(id) = 
!replace }
    +
    +      // If we do not wish to replace the executors we kill, sync the 
target number of executors
    +      // with the cluster manager to avoid allocating new ones. When 
computing the new target,
    +      // take into account executors that are pending to be added or 
removed.
    +      val adjustTotalExecutors =
    +        if (!replace) {
    +          doRequestTotalExecutors(
    +            numExistingExecutors + numPendingExecutors - 
executorsPendingToRemove.size)
    +        } else {
    +          numPendingExecutors += knownExecutors.size
    +          Future.successful(true)
    +        }
    +
    +      val killExecutors: Boolean => Future[Boolean] =
    +        if (!executorsToKill.isEmpty) {
    +          _ => doKillExecutors(executorsToKill)
    +        } else {
    +          _ => Future.successful(false)
    +        }
    +
    +      adjustTotalExecutors.flatMap(killExecutors)(ThreadUtils.sameThread)
    --- End diff --
    
    When I originally started working on this I thought I wouldn't be able to 
avoid blocking on that call within the synchronized block. However my 
(admittedly novice) understanding of the code aligns with what @vanzin said - 
because all it does is send the kill message there's no need to synchronize 
over it.


---
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