HeartSaVioR commented on code in PR #60657:
URL: https://github.com/apache/spark/pull/60657#discussion_r4621702297
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/streaming/PythonStreamingSourceRunner.scala:
##########
@@ -108,6 +108,15 @@ class PythonStreamingSourceRunner(
envVars.put("SPARK_AUTH_SOCKET_TIMEOUT", authSocketTimeout.toString)
envVars.put("SPARK_BUFFER_SIZE", bufferSize.toString)
envVars.put("SPARK_PYTHON_RUNTIME", "PYTHON_WORKER")
+ // The stream thread creates the source under the artifact state of the
stream's session, so
+ // that this worker sees the files of that session, as its executor-side
readers do.
+ val jobArtifactUUID =
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Thanks, confirmed. On this PR's head, under Spark Connect with isolation on,
both cases fail with `ModuleNotFoundError`:
- a `transformWithStateInPandas` processor whose class comes from a file
added with `addArtifacts(pyfile=True)`, when the first batch is planned;
- a `foreachBatch` function that imports such a file.
This PR doesn't change `StreamingPythonRunner`, so master behaves the same,
and I'd like to keep it out of this PR. Fixing it needs the init message of
every module that `StreamingPythonRunner` starts to carry the files root and
includes, including the listener worker. That is a protocol change of its own,
so I filed SPARK-62045 with the reproducers.
In this PR I've narrowed the config doc in bfed2b46423 to "Python UDFs and
other Python functions on the executors", so it no longer claims these
driver-side workers.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -5560,6 +5560,24 @@ object SQLConf {
.booleanConf
.createWithDefault(true)
+ val STREAMING_PROPAGATE_ARTIFACT_STATE_ENABLED =
+ buildConf("spark.sql.streaming.propagateArtifactState.enabled")
+ .internal()
+ .doc("When true, a streaming query runs its stream thread with the
artifact state of its " +
+ "own session, a clone of the session that started it, so that the
query uses the " +
+ "artifacts of that session, as a batch query of the session does. This
covers its " +
+ "Python UDFs and other Python functions, the readers of its Python
data sources on the " +
+ "executors and on the driver, the writers of its Python data sources
on the executors, " +
+ "and other code that runs on the stream thread outside the execution
of a batch, such " +
+ "as SparkFiles.get or SparkContext.addFile in a source or a listener.
This only " +
+ "matters when artifact isolation is on. Set to false to restore the
previous behavior " +
+ "for all of them, where they use the default files directory and
artifacts of the " +
+ "Spark context, or a fixed directory for the driver-side reader of a
Python data source.")
+ .version("4.0.6")
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Thanks, agreed. Fixed in bfed2b46423: we don't plan a backport to the
maintenance lines, so this is a normal change to master and branch-4.x.
- The version is now `4.5.0`. That is the version of branch-4.x, the branch
for the next feature release, as `dev/next_version_candidates.py` gives for a
PR to master.
- The migration guide entry moved to a new section, "Upgrading from
Structured Streaming 4.4 to 4.5", and says "Since Spark 4.5". The guides add
one "X to Y" section per feature release, and branch-4.4 is already cut, so 4.5
needs a section of its own above "4.3 to 4.4".
##########
docs/streaming/ss-migration-guide.md:
##########
@@ -25,6 +25,8 @@ Please refer [Migration Guide: SQL, Datasets and
DataFrame](../sql-migration-gui
## Upgrading from Structured Streaming 4.3 to 4.4
+- Since Spark 4.4, with artifact isolation on (the default in Spark Connect,
and in Scala and Java sessions without Hive support), a streaming query uses
the artifacts of its own session, a clone of the session that started it, as a
batch query of the session does. Its Python UDFs and the readers and writers of
its Python data sources now see the files and Python files that the session
added with `addArtifact` or `addArtifacts`. As a result, they no longer see
files that are only in the default context, such as `--files` or `spark.files`
entries, or files added with `SparkContext.addFile`. Python files given with
`--py-files` or `spark.submit.pyFiles` are handled by
[SPARK-62000](https://issues.apache.org/jira/browse/SPARK-62000). Code on the
stream thread outside the execution of a batch, such as `SparkFiles.get` in a
custom source or a listener, also resolves to the folder of that session. To
restore the previous behavior, set
`spark.sql.streaming.propagateArtifactState.enabled` t
o `false`. (See
[SPARK-61959](https://issues.apache.org/jira/browse/SPARK-61959) for more
details.)
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Thanks, fixed in bfed2b46423. The entry now says:
- spark-shell turns artifact isolation off, so it keeps the previous
behavior;
- of a listener's callbacks, only `onQueryStarted` runs on the stream
thread, and the others keep the previous behavior;
- Python files given with `--py-files` or `spark.submit.pyFiles` that reach
the workers only through the default context, as for a Spark Connect server in
client mode outside YARN, are no longer importable from streaming Python code,
as already for the batch Python UDFs of a Spark Connect session. SPARK-62000
handles them.
The config doc now says "in a source or in the onQueryStarted callback of a
listener".
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/StreamExecution.scala:
##########
@@ -233,7 +230,21 @@ abstract class StreamExecution(
// To fix call site like "run at <unknown>:0", we bridge the call site
from the caller
// thread to this micro batch thread
sparkSession.sparkContext.setCallSite(callSite)
- runStream()
+ // The batches run in `sparkSessionForStream`, a clone of the session
with its own copy
+ // of the artifacts. `SQLExecution` applies its artifact state only to
run the jobs, but
+ // the batches are planned before that, and some plan nodes keep the
state they are built
+ // with, for example the Python UDFs.
+ // TODO(SPARK-61997): Spark Connect builds the Python foreach writer
on the request
+ // thread, under the artifact state of the session that starts the
query, so its Python
+ // worker does not see the files of this stream's session yet.
+ if (sparkSessionForStream.sessionState.conf.getConf(
+ SQLConf.STREAMING_PROPAGATE_ARTIFACT_STATE_ENABLED)) {
+
JobArtifactSet.withActiveJobArtifactState(sparkSessionForStream.artifactManager.state)
{
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Thanks, added a `TODO(SPARK-61998)` next to the SPARK-61997 one in
bfed2b46423. It says that each run gives its Python workers its own artifact
UUID, so each executor that runs its Python tasks keeps one more Python worker
pool until it stops.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]