Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions core/src/main/scala/org/apache/spark/executor/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ private[spark] class Executor(

logInfo(s"Starting executor ID $executorId on host $executorHostname")

private val executorShutdown = new AtomicBoolean(false)
ShutdownHookManager.addShutdownHook(
() => stop()
)
// Application dependencies (added through SparkContext) that we've fetched so far on this node.
// Each map holds the master's timestamp for the version of that file or JAR we got.
private val currentFiles: HashMap[String, Long] = new HashMap[String, Long]()
Expand Down Expand Up @@ -282,29 +278,27 @@ private[spark] class Executor(
}

def stop(): Unit = {
if (!executorShutdown.getAndSet(true)) {
env.metricsSystem.report()
try {
metricsPoller.stop()
} catch {
case NonFatal(e) =>
logWarning("Unable to stop executor metrics poller", e)
}
try {
heartbeater.stop()
} catch {
case NonFatal(e) =>
logWarning("Unable to stop heartbeater", e)
}
threadPool.shutdown()
env.metricsSystem.report()
try {
metricsPoller.stop()
} catch {
case NonFatal(e) =>
logWarning("Unable to stop executor metrics poller", e)
}
try {
heartbeater.stop()
} catch {
case NonFatal(e) =>
logWarning("Unable to stop heartbeater", e)
}
threadPool.shutdown()

// Notify plugins that executor is shutting down so they can terminate cleanly
Utils.withContextClassLoader(replClassLoader) {
plugins.foreach(_.shutdown())
}
if (!isLocal) {
env.stop()
}
// Notify plugins that executor is shutting down so they can terminate cleanly
Utils.withContextClassLoader(replClassLoader) {
plugins.foreach(_.shutdown())
}
if (!isLocal) {
env.stop()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val rpcEnv: Rp

val killExecutors: Boolean => Future[Boolean] =
if (executorsToKill.nonEmpty) {
executorsToKill.foreach(id =>
executorDataMap.get(id).foreach(_.executorEndpoint.send(StopExecutor)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we guarantee that stop is called before kill in this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StopExecutor may arrive at executor after kill arrive at worker/container due to network delay, isn't it possible?

_ => doKillExecutors(executorsToKill)
} else {
_ => Future.successful(false)
Expand Down