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

    https://github.com/apache/spark/pull/14710#discussion_r76984890
  
    --- 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 --
    
    Thanks, I was mostly just trying to make sure I understood correctly. I'm 
not worried about the rpc call outside of the synchronize block because as you 
say its best if it is done outside since its safe to call it multi-threaded. It 
was more to make sure other datastructures weren't modified outside synchronize 
block.  In this case all its accessing is the local executorsToKill so doesn't 
matter.


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