You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "vicennial (via GitHub)" <gi...@apache.org> on 2023/06/22 17:22:04 UTC
[GitHub] [spark] vicennial opened a new pull request, #41701: [WIP][CONNECT][SPARK-44146] Isolate Spark Connect sessions/artifacts
vicennial opened a new pull request, #41701:
URL: https://github.com/apache/spark/pull/41701
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
This PR follows up on https://github.com/apache/spark/pull/41625 to utilize the classloader/resource isolation in Spark Connect to support multi-user Spark Connect sessions which are isolated from each other.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
To enable support for multi-user sessions coexisting on a singular Spark cluster. For example, multi-user Scala REPLs/UDFs will be supported with this PR.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
Yes, multiple Spark Connect REPLs may use a single Spark cluster at once.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
New unit tests in `ArtifactManagerSuite` + existing tests.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell closed pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell closed pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
URL: https://github.com/apache/spark/pull/41701
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41701:
URL: https://github.com/apache/spark/pull/41701#discussion_r1243033235
##########
connector/connect/server/src/test/scala/org/apache/spark/sql/connect/artifact/ArtifactManagerSuite.scala:
##########
@@ -155,10 +169,113 @@ class ArtifactManagerSuite extends SharedSparkSession with ResourceHelper {
val stagingPath = copyDir.resolve("smallClassFile.class")
val remotePath = Paths.get("forward_to_fs", destFSDir.toString, "smallClassFileCopied.class")
assert(stagingPath.toFile.exists())
- artifactManager.uploadArtifactToFs(sessionHolder, remotePath, stagingPath)
- artifactManager.addArtifact(sessionHolder, remotePath, stagingPath, None)
+ artifactManager.uploadArtifactToFs(remotePath, stagingPath)
+ artifactManager.addArtifact(remotePath, stagingPath, None)
val copiedClassFile = Paths.get(destFSDir.toString, "smallClassFileCopied.class").toFile
assert(copiedClassFile.exists())
}
+
+ test("Removal of resources") {
+ withTempPath { path =>
+ // Setup cache
+ val stagingPath = path.toPath
+ Files.write(path.toPath, "test".getBytes(StandardCharsets.UTF_8))
+ val remotePath = Paths.get("cache/abc")
+ val session = sessionHolder()
+ val blockManager = spark.sparkContext.env.blockManager
+ val blockId = CacheId(session.userId, session.sessionId, "abc")
+ // Setup artifact dir
+ val copyDir = Utils.createTempDir().toPath
+ FileUtils.copyDirectory(artifactPath.toFile, copyDir.toFile)
+ try {
+ artifactManager.addArtifact(remotePath, stagingPath, None)
+ val stagingPathFile = copyDir.resolve("smallClassFile.class")
+ val remotePathFile = Paths.get("classes/smallClassFile.class")
+ artifactManager.addArtifact(remotePathFile, stagingPathFile, None)
+
+ // Verify resources exist
+ val bytes = blockManager.getLocalBytes(blockId)
+ assert(bytes.isDefined)
+ blockManager.releaseLock(blockId)
+ val expectedPath = SparkConnectArtifactManager.artifactRootPath
+ .resolve(s"$sessionUUID/classes/smallClassFile.class")
+ assert(expectedPath.toFile.exists())
+
+ // Remove resources
+ artifactManager.cleanUpResources()
+
+ assert(!blockManager.getLocalBytes(blockId).isDefined)
+ assert(!expectedPath.toFile.exists())
+ } finally {
+ try {
+ blockManager.releaseLock(blockId)
+ } catch {
+ case _: SparkException =>
+ case throwable: Throwable => throw throwable
+ } finally {
+ FileUtils.deleteDirectory(copyDir.toFile)
+ blockManager.removeCache(session.userId, session.sessionId)
+ }
+ }
+ }
+ }
+
+ test("Classloaders for spark sessions are isolated") {
+ val holder1 = SparkConnectService.getOrCreateIsolatedSession("c1", "session1")
+ val holder2 = SparkConnectService.getOrCreateIsolatedSession("c2", "session2")
+
+ def addHelloClass(holder: SessionHolder): Unit = {
+ val copyDir = Utils.createTempDir().toPath
+ FileUtils.copyDirectory(artifactPath.toFile, copyDir.toFile)
+ val stagingPath = copyDir.resolve("Hello.class")
+ val remotePath = Paths.get("classes/Hello.class")
+ assert(stagingPath.toFile.exists())
+ holder.addArtifact(remotePath, stagingPath, None)
+ }
+
+ // Add the classfile only for the first user
+ addHelloClass(holder1)
+
+ val classLoader1 = holder1.classloader
+ val instance1 = classLoader1
Review Comment:
You could add another session here where you can load Hello. In that cases the classes for the different sessions should not be equal.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] vicennial commented on pull request #41701: [CONNECT][SPARK-44146] Isolate Spark Connect Session jars and classfiles
Posted by "vicennial (via GitHub)" <gi...@apache.org>.
vicennial commented on PR #41701:
URL: https://github.com/apache/spark/pull/41701#issuecomment-1606897840
@HyukjinKwon @hvanhovell Could you have a look? Thanks!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41701:
URL: https://github.com/apache/spark/pull/41701#discussion_r1243019808
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/artifact/SparkConnectArtifactManager.scala:
##########
@@ -200,48 +225,80 @@ class SparkConnectArtifactManager private[connect] {
}
}
-object SparkConnectArtifactManager {
+object SparkConnectArtifactManager extends Logging {
val forwardToFSPrefix = "forward_to_fs"
- private var _activeArtifactManager: SparkConnectArtifactManager = _
+ private var currentArtifactRootUri: String = _
+ private var lastKnownSparkContextInstance: SparkContext = _
- /**
- * Obtain the active artifact manager or create a new artifact manager.
- *
- * @return
- */
- def getOrCreateArtifactManager: SparkConnectArtifactManager = {
- if (_activeArtifactManager == null) {
- _activeArtifactManager = new SparkConnectArtifactManager
- }
- _activeArtifactManager
+ private val ARTIFACT_DIRECTORY_PREFIX = "artifacts"
+
+ // The base directory where all artifacts are stored.
+ private[spark] lazy val artifactRootPath = {
+ Utils.createTempDir(ARTIFACT_DIRECTORY_PREFIX).toPath
}
- private lazy val artifactManager = getOrCreateArtifactManager
+ private[spark] def getArtifactDirectoryAndUriForSession(session: SparkSession): (Path, String) =
+ (
+ ArtifactUtils.concatenatePaths(artifactRootPath, session.sessionUUID),
+ s"$artifactRootURI/${session.sessionUUID}")
+
+ private[spark] def getArtifactDirectoryAndUriForSession(
+ sessionHolder: SessionHolder): (Path, String) =
+ getArtifactDirectoryAndUriForSession(sessionHolder.session)
+
+ private[spark] def getClassfileDirectoryAndUriForSession(
+ session: SparkSession): (Path, String) = {
+ val (artDir, artUri) = getArtifactDirectoryAndUriForSession(session)
+ (ArtifactUtils.concatenatePaths(artDir, "classes"), s"$artUri/classes/")
+ }
+
+ private[spark] def getClassfileDirectoryAndUriForSession(
+ sessionHolder: SessionHolder): (Path, String) =
+ getClassfileDirectoryAndUriForSession(sessionHolder.session)
/**
- * Obtain a classloader that contains jar and classfile artifacts on the classpath.
+ * Updates the URI for the artifact directory.
*
- * @return
+ * This is required if the SparkContext is restarted.
+ *
+ * Note: This logic is solely to handle testing where a [[SparkContext]] may be restarted
+ * several times in a single JVM lifetime. In a general Spark cluster, the [[SparkContext]] is
+ * not expected to be restarted at any point in time.
*/
- def classLoaderWithArtifacts: ClassLoader = {
- val urls = artifactManager.getSparkConnectAddedJars :+
- artifactManager.classArtifactDir.toUri.toURL
- new URLClassLoader(urls.toArray, Utils.getContextOrSparkClassLoader)
+ private def refreshArtifactUri(sc: SparkContext): Unit = synchronized {
+ // If a competing thread had updated the URI, we do not need to refresh the URI again.
+ if (sc eq lastKnownSparkContextInstance) {
+ return
+ }
+ val oldArtifactUri = currentArtifactRootUri
+ currentArtifactRootUri = SparkEnv.get.rpcEnv.fileServer
+ .addDirectoryIfAbsent(ARTIFACT_DIRECTORY_PREFIX, artifactRootPath.toFile)
Review Comment:
Can we use `addDirectory` instead? The if-absent bit if pretty well protected by this object.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41701:
URL: https://github.com/apache/spark/pull/41701#discussion_r1243017490
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -88,6 +89,15 @@ class SparkConnectPlanner(val sessionHolder: SessionHolder) extends Logging {
private lazy val pythonExec =
sys.env.getOrElse("PYSPARK_PYTHON", sys.env.getOrElse("PYSPARK_DRIVER_PYTHON", "python3"))
+ // SparkConnectPlanner is used per request.
Review Comment:
We could put this in the session holder right?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41701:
URL: https://github.com/apache/spark/pull/41701#discussion_r1243025430
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SessionHolder.scala:
##########
@@ -60,6 +67,102 @@ case class SessionHolder(userId: String, sessionId: String, session: SparkSessio
}
}
}
+
+ private[connect] lazy val artifactManager = new SparkConnectArtifactManager(this)
+
+ /**
+ * Add an artifact to this SparkConnect session.
+ *
+ * @param remoteRelativePath
+ * @param serverLocalStagingPath
+ * @param fragment
+ */
+ private[connect] def addArtifact(
+ remoteRelativePath: Path,
+ serverLocalStagingPath: Path,
+ fragment: Option[String]): Unit = {
+ artifactManager.addArtifact(remoteRelativePath, serverLocalStagingPath, fragment)
+ }
+
+ /**
+ * A [[JobArtifactSet]] for this SparkConnect session.
+ */
+ def connectJobArtifactSet: JobArtifactSet = artifactManager.jobArtifactSet
+
+ /**
+ * A [[ClassLoader]] for jar/class file resources specific to this SparkConnect session.
+ */
+ def classloader: ClassLoader = artifactManager.classloader
+
+ /**
+ * Expire this session and trigger state cleanup mechanisms.
+ */
+ private[connect] def expireSession(): Unit = {
+ logDebug(s"Expiring session with userId: $userId and sessionId: $sessionId")
+ artifactManager.cleanUpResources()
+ }
+
+ /**
+ * Execute a block of code using this session's classloader.
+ * @param f
+ * @tparam T
+ */
+ def withContext[T](f: => T): T = {
+ // Needed for deserializing and evaluating the UDF on the driver
+ Utils.withContextClassLoader(classloader) {
+ // Needed for propagating the dependencies to the executors.
+ JobArtifactSet.withActive(connectJobArtifactSet) {
+ f
+ }
+ }
+ }
+
+ /**
+ * Set the session-based Python paths to include in Python UDF.
+ * @param f
+ * @tparam T
+ */
+ def withSessionBasedPythonPaths[T](f: => T): T = {
+ try {
+ session.conf.set(
Review Comment:
qq, we don't really need to unset this right? Or is exposing it to the client a bad idea? cc @HyukjinKwon
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41701:
URL: https://github.com/apache/spark/pull/41701#discussion_r1243025430
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SessionHolder.scala:
##########
@@ -60,6 +67,102 @@ case class SessionHolder(userId: String, sessionId: String, session: SparkSessio
}
}
}
+
+ private[connect] lazy val artifactManager = new SparkConnectArtifactManager(this)
+
+ /**
+ * Add an artifact to this SparkConnect session.
+ *
+ * @param remoteRelativePath
+ * @param serverLocalStagingPath
+ * @param fragment
+ */
+ private[connect] def addArtifact(
+ remoteRelativePath: Path,
+ serverLocalStagingPath: Path,
+ fragment: Option[String]): Unit = {
+ artifactManager.addArtifact(remoteRelativePath, serverLocalStagingPath, fragment)
+ }
+
+ /**
+ * A [[JobArtifactSet]] for this SparkConnect session.
+ */
+ def connectJobArtifactSet: JobArtifactSet = artifactManager.jobArtifactSet
+
+ /**
+ * A [[ClassLoader]] for jar/class file resources specific to this SparkConnect session.
+ */
+ def classloader: ClassLoader = artifactManager.classloader
+
+ /**
+ * Expire this session and trigger state cleanup mechanisms.
+ */
+ private[connect] def expireSession(): Unit = {
+ logDebug(s"Expiring session with userId: $userId and sessionId: $sessionId")
+ artifactManager.cleanUpResources()
+ }
+
+ /**
+ * Execute a block of code using this session's classloader.
+ * @param f
+ * @tparam T
+ */
+ def withContext[T](f: => T): T = {
+ // Needed for deserializing and evaluating the UDF on the driver
+ Utils.withContextClassLoader(classloader) {
+ // Needed for propagating the dependencies to the executors.
+ JobArtifactSet.withActive(connectJobArtifactSet) {
+ f
+ }
+ }
+ }
+
+ /**
+ * Set the session-based Python paths to include in Python UDF.
+ * @param f
+ * @tparam T
+ */
+ def withSessionBasedPythonPaths[T](f: => T): T = {
+ try {
+ session.conf.set(
Review Comment:
qq, we don't really need to unset this right?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on a diff in pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41701:
URL: https://github.com/apache/spark/pull/41701#discussion_r1243024756
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SessionHolder.scala:
##########
@@ -60,6 +67,102 @@ case class SessionHolder(userId: String, sessionId: String, session: SparkSessio
}
}
}
+
+ private[connect] lazy val artifactManager = new SparkConnectArtifactManager(this)
+
+ /**
+ * Add an artifact to this SparkConnect session.
+ *
+ * @param remoteRelativePath
+ * @param serverLocalStagingPath
+ * @param fragment
+ */
+ private[connect] def addArtifact(
+ remoteRelativePath: Path,
+ serverLocalStagingPath: Path,
+ fragment: Option[String]): Unit = {
+ artifactManager.addArtifact(remoteRelativePath, serverLocalStagingPath, fragment)
+ }
+
+ /**
+ * A [[JobArtifactSet]] for this SparkConnect session.
+ */
+ def connectJobArtifactSet: JobArtifactSet = artifactManager.jobArtifactSet
+
+ /**
+ * A [[ClassLoader]] for jar/class file resources specific to this SparkConnect session.
+ */
+ def classloader: ClassLoader = artifactManager.classloader
+
+ /**
+ * Expire this session and trigger state cleanup mechanisms.
+ */
+ private[connect] def expireSession(): Unit = {
+ logDebug(s"Expiring session with userId: $userId and sessionId: $sessionId")
+ artifactManager.cleanUpResources()
+ }
+
+ /**
+ * Execute a block of code using this session's classloader.
+ * @param f
+ * @tparam T
+ */
+ def withContext[T](f: => T): T = {
Review Comment:
This name is a bit too vague for my liking. How about `withContextClassLoader`?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] vicennial commented on pull request #41701: [CONNECT][SPARK-44146] Isolate Spark Connect Session jars and classfiles
Posted by "vicennial (via GitHub)" <gi...@apache.org>.
vicennial commented on PR #41701:
URL: https://github.com/apache/spark/pull/41701#issuecomment-1604932773
The PR is ready to review (the falling tests are flaky, I've submitted a rerun request).
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #41701:
URL: https://github.com/apache/spark/pull/41701#discussion_r1251417288
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SessionHolder.scala:
##########
@@ -60,6 +67,102 @@ case class SessionHolder(userId: String, sessionId: String, session: SparkSessio
}
}
}
+
+ private[connect] lazy val artifactManager = new SparkConnectArtifactManager(this)
+
+ /**
+ * Add an artifact to this SparkConnect session.
+ *
+ * @param remoteRelativePath
+ * @param serverLocalStagingPath
+ * @param fragment
+ */
+ private[connect] def addArtifact(
+ remoteRelativePath: Path,
+ serverLocalStagingPath: Path,
+ fragment: Option[String]): Unit = {
+ artifactManager.addArtifact(remoteRelativePath, serverLocalStagingPath, fragment)
+ }
+
+ /**
+ * A [[JobArtifactSet]] for this SparkConnect session.
+ */
+ def connectJobArtifactSet: JobArtifactSet = artifactManager.jobArtifactSet
+
+ /**
+ * A [[ClassLoader]] for jar/class file resources specific to this SparkConnect session.
+ */
+ def classloader: ClassLoader = artifactManager.classloader
+
+ /**
+ * Expire this session and trigger state cleanup mechanisms.
+ */
+ private[connect] def expireSession(): Unit = {
+ logDebug(s"Expiring session with userId: $userId and sessionId: $sessionId")
+ artifactManager.cleanUpResources()
+ }
+
+ /**
+ * Execute a block of code using this session's classloader.
+ * @param f
+ * @tparam T
+ */
+ def withContext[T](f: => T): T = {
+ // Needed for deserializing and evaluating the UDF on the driver
+ Utils.withContextClassLoader(classloader) {
+ // Needed for propagating the dependencies to the executors.
+ JobArtifactSet.withActive(connectJobArtifactSet) {
+ f
+ }
+ }
+ }
+
+ /**
+ * Set the session-based Python paths to include in Python UDF.
+ * @param f
+ * @tparam T
+ */
+ def withSessionBasedPythonPaths[T](f: => T): T = {
+ try {
+ session.conf.set(
Review Comment:
yeah I planned to remove this and @vicennial removed it in https://github.com/apache/spark/pull/41789#discussion_r1247634835. This was just a hack I added to avoid additional refactoring.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] hvanhovell commented on pull request #41701: [SPARK-44146][CONNECT] Isolate Spark Connect Session jars and classfiles
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on PR #41701:
URL: https://github.com/apache/spark/pull/41701#issuecomment-1608577372
I am merging this to unblock a couple of follow-ups. Please address my comments in a small follow-up.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org