Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/10412#discussion_r66359813
--- 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 = synchronized {
+ 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()
+ }(ThreadUtils.sameThread)
+
+ future.onFailure {
+ case NonFatal(e) =>
+ logError(s"Failed to launch executor $executorId on container
$containerId", e)
+ // Assigned container should be released immediately to avoid
unnecessary resource
+ // occupation.
+ amClient.releaseAssignedContainer(containerId)
+ case t => throw t
--- End diff --
nit: not needed? This also should cause a compiler warning (matching on
Throwable).
---
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]