Skip to content

[SPARK-52013] [CONNECT] [ML] Remove SparkConnectClient.ml_caches#50832

Closed
WeichenXu123 wants to merge 8 commits into
apache:masterfrom
WeichenXu123:SPARK-52013-2
Closed

[SPARK-52013] [CONNECT] [ML] Remove SparkConnectClient.ml_caches#50832
WeichenXu123 wants to merge 8 commits into
apache:masterfrom
WeichenXu123:SPARK-52013-2

Conversation

@WeichenXu123
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Remove SparkConnectClient.ml_caches

The current implementation of SparkConnectClient.ml_caches is buggy (should be global but it is thread-local)
and we already have MLcache dict in Spark driver as the source of truth,
we don't need to maintain a copy of the dict in client,

so in this PR I remove it.

Why are the changes needed?

Bugfix, and remove redundant data structure.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Unit tests.

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

No.

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Copy link
Copy Markdown
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)

@WeichenXu123
Copy link
Copy Markdown
Contributor Author

WeichenXu123 commented May 8, 2025

The CI https://github.com/WeichenXu123/spark/actions/runs/14906306045/job/41869504809
hangs at pyspark.sql.tests.connect.client.test_client suite.
I think it hangs at the 'atexit' hook:

atexit.register(self._cleanup_ml_cache)

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
# The _cleanup_ml_cache invocation will hang in this test (no valid spark cluster)
# and it blocks the test process exiting because it is registered as the atexit handler
# in `SparkConnectClient` constructor. To bypass the issue, patch the method in the test.
SparkConnectClient._cleanup_ml_cache = lambda _: None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we just del this axexit as well?
ml cache is always cleaned when the SessionHolder is closed in the server side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is the session ensured to be closed when the client exits or client crashes ? @HyukjinKwon

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we should do it in follow-up PR, it needs some discussion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the session ensured to be closed when the client exits or client crashes ?

From what I know, I don't think so

@WeichenXu123
Copy link
Copy Markdown
Contributor Author

merged to master

yhuang-db pushed a commit to yhuang-db/spark that referenced this pull request Jun 9, 2025
### What changes were proposed in this pull request?

Remove `SparkConnectClient.ml_caches`

The current implementation of `SparkConnectClient.ml_caches` is buggy (should be global but it is thread-local)
and we already have MLcache dict in Spark driver as the source of truth,
we don't need to maintain a copy of the dict in client,

so in this PR I remove it.

### Why are the changes needed?

Bugfix, and remove redundant data structure.

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

No.

### How was this patch tested?

Unit tests.

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

No.

Closes apache#50832 from WeichenXu123/SPARK-52013-2.

Authored-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants