Commit 5b5ff6d
[SPARK-54753][SQL] fix memory leak of ArtifactManager
### What changes were proposed in this pull request?
As stated in https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/ref/Cleaner.html
**The cleaning action could be a lambda but all too easily will capture the object reference, by referring to fields of the object being cleaned, preventing the object from becoming phantom reachable. Using a static nested class, as above, will avoid accidentally retaining the object reference.**
For more details, and the test and analysis are in https://issues.apache.org/jira/browse/SPARK-54753
<img width="1462" height="559" alt="image" src="https://github.com/user-attachments/assets/83de9e8e-8f63-41fe-8318-b1cea6a1de9c" />
After running with Spark 4.0.1, the ArtififactManager is leaked, its referenced SessionState/SparkSession is as well leaked.
### Why are the changes needed?
use a separate class to ref the cleanup state
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
with test program in https://issues.apache.org/jira/browse/SPARK-54753, and use Visual VM to monitor the memory usage
### Was this patch authored or co-authored using generative AI tooling?
No
cc dongjoon-hyun pranavdev022 hvanhovell vicennial HyukjinKwon
Closes #53591 from scottme/master.
Lead-authored-by: xihuan_mstr <[email protected]>
Co-authored-by: scottme <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>1 parent 2ab68d1 commit 5b5ff6d
File tree
2 files changed
+9
-2
lines changed- sql
- connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/client
- core/src/main/scala/org/apache/spark/sql/artifact
2 files changed
+9
-2
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
237 | 239 | | |
238 | 240 | | |
239 | 241 | | |
| |||
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
425 | | - | |
426 | | - | |
| 425 | + | |
427 | 426 | | |
428 | 427 | | |
429 | 428 | | |
| |||
529 | 528 | | |
530 | 529 | | |
531 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
532 | 537 | | |
533 | 538 | | |
534 | 539 | | |
| |||
0 commit comments