mridulm commented on code in PR #36238:
URL: https://github.com/apache/spark/pull/36238#discussion_r852361162
##########
core/src/main/scala/org/apache/spark/executor/Executor.scala:
##########
@@ -264,16 +290,26 @@ private[spark] class Executor(
decommissioned = true
}
+ private[executor] def createTaskRunner(context: ExecutorBackend,
+ taskDescription: TaskDescription) = new TaskRunner(context,
taskDescription, plugins)
+
def launchTask(context: ExecutorBackend, taskDescription: TaskDescription):
Unit = {
- val tr = new TaskRunner(context, taskDescription, plugins)
- runningTasks.put(taskDescription.taskId, tr)
+ val taskId = taskDescription.taskId
+ val tr = createTaskRunner(context, taskDescription)
+ runningTasks.put(taskId, tr)
+ val killMark = killMarks.get(taskId)
+ if (killMark != null) {
+ tr.kill(killMark._1, killMark._2)
+ killMarks.remove(taskId)
+ }
threadPool.execute(tr)
Review Comment:
If killed, do we need to execute it ?
##########
core/src/main/scala/org/apache/spark/executor/Executor.scala:
##########
@@ -174,7 +174,33 @@ private[spark] class Executor(
private val maxResultSize = conf.get(MAX_RESULT_SIZE)
// Maintains the list of running tasks.
- private val runningTasks = new ConcurrentHashMap[Long, TaskRunner]
+ private[executor] val runningTasks = new ConcurrentHashMap[Long, TaskRunner]
+
+ // Kill mark TTL in milliseconds - 10 seconds.
+ private val KILL_MARK_TTL_MS = 10000L
+
+ // Kill marks with interruptThread flag, kill reason and timestamp.
+ // This is to avoid dropping the kill event when killTask() is called before
launchTask().
+ private[executor] val killMarks = new ConcurrentHashMap[Long, (Boolean,
String, Long)]
+
+ private val killMarkCleanupTask = new Runnable {
+ override def run(): Unit = {
+ val oldest = System.currentTimeMillis() - KILL_MARK_TTL_MS
+ val iter = killMarks.entrySet().iterator()
+ while (iter.hasNext) {
+ if (iter.next().getValue._3 < oldest) {
+ iter.remove()
+ }
+ }
+ }
+ }
+
+ // Kill mark cleanup thread executor.
+ private val killMarkCleanupService =
+
ThreadUtils.newDaemonSingleThreadScheduledExecutor("executor-kill-mark-cleanup")
+
+ killMarkCleanupService.scheduleAtFixedRate(
+ killMarkCleanupTask, KILL_MARK_TTL_MS, KILL_MARK_TTL_MS,
TimeUnit.MILLISECONDS)
Review Comment:
Why do we need this ?
##########
core/src/main/scala/org/apache/spark/executor/Executor.scala:
##########
@@ -296,6 +332,8 @@ private[spark] class Executor(
} else {
taskRunner.kill(interruptThread = interruptThread, reason = reason)
}
+ // Safe to remove kill mark as we got a chance with the TaskRunner.
+ killMarks.remove(taskId)
Review Comment:
Add the remove in a try/finally
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]