You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ul...@apache.org on 2024/07/05 09:26:11 UTC

(spark) branch master updated: [SPARK-48815][CONNECT] Update environment when stoping connect session

This is an automated email from the ASF dual-hosted git repository.

ulyssesyou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c1066d0654d [SPARK-48815][CONNECT] Update environment when stoping connect session
4c1066d0654d is described below

commit 4c1066d0654d9d1a9b5c7dc76825cd32bd819842
Author: ulysses-you <ul...@gmail.com>
AuthorDate: Fri Jul 5 17:25:57 2024 +0800

    [SPARK-48815][CONNECT] Update environment when stoping connect session
    
    ### What changes were proposed in this pull request?
    
    We should update environment if any added files are removed when stoping connect session.
    
    ### Why are the changes needed?
    
    To sync the resources with event environment and UI
    
    ### Does this PR introduce _any_ user-facing change?
    
    yes, the event and UI changed
    
    ### How was this patch tested?
    
    manually test, after this change, the resources in UI environment are removed when stoping connect session.
    
    `spark.addArtifact("/Users/cathy/Desktop/code/spark/dist/jars/zjsonpatch-0.3.0.jar")`
    
    <img width="1011" alt="image" src="https://github.com/apache/spark/assets/12025282/903750f5-a03b-432e-a96b-bd39cda7c234">
    
    `spark.stop`
    
    <img width="1042" alt="image" src="https://github.com/apache/spark/assets/12025282/fa517af5-c84e-46c1-9197-eb7083c7b6c4">
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    no
    
    Closes #47223 from ulysses-you/env.
    
    Authored-by: ulysses-you <ul...@gmail.com>
    Signed-off-by: youxiduo <yo...@corp.netease.com>
---
 core/src/main/scala/org/apache/spark/SparkContext.scala      |  2 +-
 .../org/apache/spark/sql/artifact/ArtifactManager.scala      | 12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/core/src/main/scala/org/apache/spark/SparkContext.scala b/core/src/main/scala/org/apache/spark/SparkContext.scala
index 76138640dd2a..5ac2a090dcbe 100644
--- a/core/src/main/scala/org/apache/spark/SparkContext.scala
+++ b/core/src/main/scala/org/apache/spark/SparkContext.scala
@@ -2840,7 +2840,7 @@ class SparkContext(config: SparkConf) extends Logging {
   }
 
   /** Post the environment update event once the task scheduler is ready */
-  private def postEnvironmentUpdate(): Unit = {
+  private[spark] def postEnvironmentUpdate(): Unit = {
     if (taskScheduler != null) {
       val schedulingMode = getSchedulingMode.toString
       val addedJarPaths = allAddedJars.keys.toSeq
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/artifact/ArtifactManager.scala b/sql/core/src/main/scala/org/apache/spark/sql/artifact/ArtifactManager.scala
index 9e4b6ef31636..ea7a33f6887d 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/artifact/ArtifactManager.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/artifact/ArtifactManager.scala
@@ -233,9 +233,15 @@ class ArtifactManager(session: SparkSession) extends Logging {
     // Clean up added files
     val fileserver = SparkEnv.get.rpcEnv.fileServer
     val sparkContext = session.sparkContext
-    sparkContext.addedFiles.remove(state.uuid).foreach(_.keys.foreach(fileserver.removeFile))
-    sparkContext.addedArchives.remove(state.uuid).foreach(_.keys.foreach(fileserver.removeFile))
-    sparkContext.addedJars.remove(state.uuid).foreach(_.keys.foreach(fileserver.removeJar))
+    val shouldUpdateEnv = sparkContext.addedFiles.contains(state.uuid) ||
+      sparkContext.addedArchives.contains(state.uuid) ||
+      sparkContext.addedJars.contains(state.uuid)
+    if (shouldUpdateEnv) {
+      sparkContext.addedFiles.remove(state.uuid).foreach(_.keys.foreach(fileserver.removeFile))
+      sparkContext.addedArchives.remove(state.uuid).foreach(_.keys.foreach(fileserver.removeFile))
+      sparkContext.addedJars.remove(state.uuid).foreach(_.keys.foreach(fileserver.removeJar))
+      sparkContext.postEnvironmentUpdate()
+    }
 
     // Clean up cached relations
     val blockManager = sparkContext.env.blockManager


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org