Skip to content

Conversation

liuzqt
Copy link
Contributor

@liuzqt liuzqt commented Sep 2, 2025

What changes were proposed in this pull request?

backport 871fe3d

There is race condition between CachedRDDBuilder.cachedColumnBuffers and CachedRDDBuilder.clearCache: when they interleave each other, cachedColumnBuffers might return a nullptr.

This looks like a day-1 bug introduced from 20ca208#diff-4068fce361a50e3d32af2ba2d4231905f500e7b2da9f46d5ddd99b758c30fd43

Why are the changes needed?

The race condition might lead to NPE from here which is basically a null RDD returned from CachedRDDBuilder.cachedColumnBuffers

Does this PR introduce any user-facing change?

NO

How was this patch tested?

Theoretically this race condition might be triggered as long as cache materialization and unpersistence happen on different thread. But there is no reliable way to construct unit test.

Was this patch authored or co-authored using generative AI tooling?

NO

### What changes were proposed in this pull request?

There is race condition between `CachedRDDBuilder.cachedColumnBuffers` and `CachedRDDBuilder.clearCache`: when they interleave each other, `cachedColumnBuffers` might return a `nullptr`.

This looks like a day-1 bug introduced from  apache@20ca208#diff-4068fce361a50e3d32af2ba2d4231905f500e7b2da9f46d5ddd99b758c30fd43

### Why are the changes needed?

The race condition might lead to NPE from [here](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/QueryStageExec.scala#L303) which is basically a null `RDD` returned from `CachedRDDBuilder.cachedColumnBuffers`

### Does this PR introduce _any_ user-facing change?
NO

### How was this patch tested?
Theoretically this race condition might be triggered as long as cache materialization and unpersistence happen on different thread. But there is no reliable way to construct unit test.

### Was this patch authored or co-authored using generative AI tooling?
NO

Closes apache#52174 from liuzqt/SPARK-53435.

Authored-by: ziqi liu <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
@github-actions github-actions bot added the SQL label Sep 2, 2025
@liuzqt
Copy link
Contributor Author

liuzqt commented Sep 2, 2025

backport to 3.5 @cloud-fan @dongjoon-hyun

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-53435][SQL] Fix race condition in CachedRDDBuilder [SPARK-53435][SQL][3.5] Fix race condition in CachedRDDBuilder Sep 2, 2025
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM (Pending CIs). Thank you, @liuzqt .

dongjoon-hyun pushed a commit that referenced this pull request Sep 2, 2025
### What changes were proposed in this pull request?
backport 871fe3d

There is race condition between `CachedRDDBuilder.cachedColumnBuffers` and `CachedRDDBuilder.clearCache`: when they interleave each other, `cachedColumnBuffers` might return a `nullptr`.

This looks like a day-1 bug introduced from  20ca208#diff-4068fce361a50e3d32af2ba2d4231905f500e7b2da9f46d5ddd99b758c30fd43

### Why are the changes needed?
The race condition might lead to NPE from [here](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/QueryStageExec.scala#L303) which is basically a null `RDD` returned from `CachedRDDBuilder.cachedColumnBuffers`

### Does this PR introduce _any_ user-facing change?
NO

### How was this patch tested?
Theoretically this race condition might be triggered as long as cache materialization and unpersistence happen on different thread. But there is no reliable way to construct unit test.

### Was this patch authored or co-authored using generative AI tooling?
NO

Closes #52199 from liuzqt/SPARK-53435-3.5.

Authored-by: ziqi liu <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
@dongjoon-hyun
Copy link
Member

Merged to branch-3.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants