[SPARK-53948][SQL][3.5] Fix deadlock in Observation #52657
Closed
+23
−19
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 proposes a fix to a deadlock bug in
Observation
. It replacessynchronized
locks with a promise to avoid deadlock happened betweenget
andonFinish
methodsWhy are the changes needed?
Observation
class has been evolved a few times during Spark 3.5 to Spark 4.0.0. Previously it uses locking mechanism (synchronized
) betweenget
andonFinish
methods to coordinate metrics update and retrieval.But it has a potential deadlocking bug. If
get
is called beforeObservationListener
is triggered to callonFinish
,get
will forever be waiting for metrics because it locks the observation object bysynchronized
so lateronFinish
call is locked out from updating the metrics.This locking mechanism was replaced by a promise by #47921 that is a large refacroring on observation feature. But in the PR, I don’t see the deadlock bug was mentioned, and there is no bug fix PR proposed to earlier versions. So I think that the bug was not known and the fix is unintentional in Spark 4.0.0. The bug is still in Spark 3.5 branch.
Does this PR introduce any user-facing change?
No
How was this patch tested?
The deadlock bug was hit by customer and is tricky to reproducing by unit test. This patch should pass existing tests.
Was this patch authored or co-authored using generative AI tooling?
No