[SPARK-40235][CORE] Use interruptible lock instead of synchronized in Executor.updateDependencies() #37681
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This patch modifies the synchronization in
Executor.updateDependencies()
in order to allow tasks to be interrupted while they are blocked and waiting on other tasks to finish downloading dependencies.This synchronization was added years ago in mesos/spark@7b9e96c in order to prevent concurrently-launching tasks from performing concurrent dependency updates. If one task is downloading dependencies, all other newly-launched tasks will block until the original dependency download is complete.
Let's say that a Spark task launches, becomes blocked on a
updateDependencies()
call, then is cancelled while it is blocked. Although Spark will send aThread.interrupt()
to the canceled task, the task will continue waiting because threads blocked on asynchronized
won't throw an InterruptedException in response to the interrupt. As a result, the blocked thread will continue to wait until the other thread exits the synchronized block.This PR aims to fix this problem by replacing the
synchronized
with aReentrantLock
, which has alockInterruptibly
method.Why are the changes needed?
In a real-world scenario, we hit a case where a task was canceled right after being launched while another task was blocked in a slow library download. The slow library download took so long that the TaskReaper killed the executor because the canceled task could not exit in a timely fashion. This patch's fix prevents this issue.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New unit test case.