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

    https://github.com/apache/spark/pull/10412#discussion_r48637157
  
    --- Diff: 
yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala ---
    @@ -399,40 +402,61 @@ private[yarn] class YarnAllocator(
        */
       private def runAllocatedContainers(containersToUse: 
ArrayBuffer[Container]): Unit = {
         for (container <- containersToUse) {
    -      numExecutorsRunning += 1
    -      assert(numExecutorsRunning <= targetNumExecutors)
    +      executorIdCounter += 1
           val executorHostname = container.getNodeId.getHost
           val containerId = container.getId
    -      executorIdCounter += 1
           val executorId = executorIdCounter.toString
    -
           assert(container.getResource.getMemory >= resource.getMemory)
    -
           logInfo("Launching container %s for on host %s".format(containerId, 
executorHostname))
    -      executorIdToContainer(executorId) = container
    -      containerIdToExecutorId(container.getId) = executorId
    -
    -      val containerSet = 
allocatedHostToContainersMap.getOrElseUpdate(executorHostname,
    -        new HashSet[ContainerId])
    -
    -      containerSet += containerId
    -      allocatedContainerToHostMap.put(containerId, executorHostname)
    -
    -      val executorRunnable = new ExecutorRunnable(
    -        container,
    -        conf,
    -        sparkConf,
    -        driverUrl,
    -        executorId,
    -        executorHostname,
    -        executorMemory,
    -        executorCores,
    -        appAttemptId.getApplicationId.toString,
    -        securityMgr)
    +
    +      def updateInternalState(): Unit = {
    +        numExecutorsRunning += 1
    +        assert(numExecutorsRunning <= targetNumExecutors)
    +        executorIdToContainer(executorId) = container
    +        containerIdToExecutorId(container.getId) = executorId
    +
    +        val containerSet = 
allocatedHostToContainersMap.getOrElseUpdate(executorHostname,
    +          new HashSet[ContainerId])
    +        containerSet += containerId
    +        allocatedContainerToHostMap.put(containerId, executorHostname)
    +      }
    +
           if (launchContainers) {
             logInfo("Launching ExecutorRunnable. driverUrl: %s,  
executorHostname: %s".format(
               driverUrl, executorHostname))
    -        launcherPool.execute(executorRunnable)
    +
    +        val future = Future {
    +          new ExecutorRunnable(
    +            container,
    +            conf,
    +            sparkConf,
    +            driverUrl,
    +            executorId,
    +            executorHostname,
    +            executorMemory,
    +            executorCores,
    +            appAttemptId.getApplicationId.toString,
    +            securityMgr)
    +            .run()
    +        }
    +
    +        future onSuccess {
    +          case _ =>
    +            // Only change the state when executor is successfully 
launched.
    +            updateInternalState()
    +        }
    --- End diff --
    
    Minor, but it might be better to use `ThreadUtils.sameThread` here instead 
of re-queuing the callback into the launcher thread pool for execution.


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