Repository navigation
[SPARK-61166][CONNECT][PYTHON] Make the threads of inheritable_thread_target share the copy of the tags of the session, in the Rust and Python clients, as PySpark does - #357
Closed
HyukjinKwon wants to merge 1 commit into
Conversation
…_target share the copy of the tags of the session, in the Rust and Python clients, as PySpark does PySpark Connect's inheritable_thread_target(session) copies the thread_local of the client, of the tags, when it decorates a function, and every thread that runs the function gets that one copy, so the threads share it. The client copied the tags into each thread instead, so a thread that the function started from another thread of the function lacked the tags that that thread added. The tags of a thread in the core are now a set that threads can share: the session copies those of the current thread (copy_thread_tags) and gives the copy to a thread (share_thread_tags); clear_tags gives the thread a new set of its own, as PySpark's clearTags does. The decorator copies the tags when it decorates the function and gives the copy to each of its threads. Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
SPARK-61166: PySpark Connect's
inheritable_thread_target(session)copies thethread_localof the client, of the tags of the thread, when it decorates a function. Every thread that runs the function gets that one copy, so the threads share it: a tag that one of them adds is a tag of the others.The client now does the same.
Rust core: the tags of a thread are a set that threads can share:
SparkSession::copy_thread_tagscopies the tags of the current thread, as of now, into a newSharedTags.SparkSession::share_thread_tagsmakes such a copy the tags of the current thread.clear_tagsgives the thread a new empty set of its own, as PySpark'sclearTagssets the tags of thethread_localto a new set.Python client:
inheritable_thread_target(session)copies the tags when it decorates the function, as before, and gives each of its threads the copy (_share_thread_tags), rather than adding the tags to each thread.InheritableThread, which copies the tags when the thread starts, is not changed. Nor are the thread-local user context extensions, which PySpark's decorator copies in the samethread_local: the client's decorator does not propagate them, before or after this change.Why are the changes needed?
The client copied the tags into each thread instead. So a thread that the function started, from another thread of the function, lacked the tags that that other thread had added. Apache Spark's
test_inheritable_tags_with_decooftest_parity_job_cancellation.pyfailed on this client: the nested thread lacked the tag "b" of the thread that started it.Does this PR introduce any user-facing change?
Yes. The threads of
inheritable_thread_targetshare their tags, as with PySpark 4.3.0. For the Rust API,SharedTags,SparkSession::copy_thread_tagsandSparkSession::share_thread_tagsare new.How was this patch tested?
test_parity_job_cancellation.pypasses on this client against a local server: 8 tests pass and 1 is skipped.wasm-udf, the offline Python suites (2222 passed, 8 skipped), and the live drop-in and Arrow suites (204 passed) and live cases (10 passed) against a local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.