HeartSaVioR commented on code in PR #60674:
URL: https://github.com/apache/spark/pull/60674#discussion_r4622084283
##########
core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala:
##########
@@ -571,4 +603,28 @@ private[spark] object PythonWorkerFactory {
val IDLE_WORKER_TIMEOUT_NS = TimeUnit.MINUTES.toNanos(1) // kill idle
workers after 1 minute
private[spark] val defaultDaemonModule = "pyspark.daemon"
+
+ // The directory that holds copies of the application's Python modules, and
their paths.
+ @GuardedBy("this")
+ private var globalPythonModules: Option[(Seq[String], File)] = None
+
+ /**
+ * Returns a directory under the local directory that holds copies of
`modules`, the
+ * application's Python modules, and nothing else, like `__pyfiles__` on
YARN. It is created
+ * once for each set of modules, which does not change while an application
runs.
+ */
+ private def globalPythonModulesDirectory(conf: SparkConf, modules:
Seq[File]): File =
+ synchronized {
+ val paths = modules.map(_.getPath)
+ globalPythonModules.collect {
+ case (cachedPaths, dir) if cachedPaths == paths && dir.isDirectory =>
dir
+ }.getOrElse {
+ val dir = Utils.createTempDir(Utils.getLocalDir(conf), "pyfiles")
+ modules.foreach { module =>
+ Files.copy(module.toPath, dir.toPath.resolve(module.getName))
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. Fixed in 0ccc47082db: the factory now drops repeated
files with `.distinct` right after it maps the listed paths to the copies in
the default files directory, which keeps the order of first listing.
`PythonGlobalPyFilesSuite` now lists a module twice in `spark.submit.pyFiles`.
Without `.distinct`, every test of the suite fails with
`FileAlreadyExistsException`.
##########
core/src/main/scala/org/apache/spark/internal/config/Python.scala:
##########
@@ -94,6 +94,21 @@ private[spark] object Python {
.booleanConf
.createWithDefault(false)
+ val PYTHON_ISOLATED_SESSION_GLOBAL_PY_FILES_ENABLED =
+ ConfigBuilder("spark.python.isolatedSession.globalPyFiles.enabled")
+ .internal()
+ .doc("When true, the Python workers of a session with artifact
isolation, such as a " +
+ "Spark Connect session, can also import the Python files that the
application was " +
+ "started with (--py-files or spark.submit.pyFiles), after the
session's own files. " +
+ "Only these files are added, not the other files of the default files
directory. Set " +
+ "to false when starting the application to restore the previous
behavior, where these " +
+ "workers can only import the session's own Python files, except on the
application " +
+ "master and executors on YARN, which puts the application's Python
files on their " +
+ "PYTHONPATH.")
+ .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. The config and the note now name the same release, but it is 4.5
rather than 4.4. This is a normal change to master and branch-4.x, and
branch-4.4 is already cut.
So in 0ccc47082db:
- the version is `4.5.0`, which is what `dev/next_version_candidates.py`
gives for branch-4.x;
- the migration guide entry moved to a new section, "Upgrading from Core 4.4
to 4.5", and says "Since Spark 4.5".
The other new entry at `Python.scala:71` is `4.4.0` because that change went
into branch-4.4 too.
##########
docs/core-migration-guide.md:
##########
@@ -24,6 +24,8 @@ license: |
## Upgrading from Core 4.3 to 4.4
+- Since Spark 4.4, with artifact isolation on (the default in Spark Connect),
the Python workers of a session also import the Python files that the
application was started with (`--py-files` or `spark.submit.pyFiles`), after
the session's own Python files and before installed packages. Before, they
could import these files only on the executors on YARN. As a result, a module
from these files can now take the place of an installed package with the same
name. To restore the previous behavior, set
`spark.python.isolatedSession.globalPyFiles.enabled` to `false` when starting
the application. (See
[SPARK-62000](https://issues.apache.org/jira/browse/SPARK-62000) 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 0ccc47082db. The note now says that, before, the files were
importable only on YARN's application master and executors, and that the Python
workers of a YARN client-mode driver still can't import them. The config's doc
now has the same client-mode driver qualifier in its first sentence.
--
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]