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

HyukjinKwon pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.x by this push:
     new 062d6d294110 [SPARK-60769][SQL] Read Maven resolution settings from 
session configuration
062d6d294110 is described below

commit 062d6d2941108faddf41d295622eaab75838ae3a
Author: qianlan717 <[email protected]>
AuthorDate: Thu Nov 12 07:36:06 2026 +0900

    [SPARK-60769][SQL] Read Maven resolution settings from session configuration
    
    ### What changes were proposed in this pull request?
    
    Read Maven resolution settings from the owning SparkSession for 
`SparkSession.addArtifact` and
    `addArtifacts`: `spark.jars.ivySettings`, `spark.jars.ivy`, 
`spark.jars.ivyConnectTimeout`, and
    `spark.jars.ivyReadTimeout`.
    
    Preserve configuration substitution, timeout validation, the optional local 
Ivy repository, and
    session-local caches. Spark Connect routing and JVM-client resolution are 
handled by #59982.
    
    ### Why are the changes needed?
    
    Use the session that owns the artifact manager as the configuration source. 
Cluster SparkConf
    values are inherited, and this leaves room for future runtime-provided 
session settings.
    
    JIRA: https://issues.apache.org/jira/browse/SPARK-60769
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. Artifact APIs now read these settings from their session instead of 
SparkContext. Existing
    cluster configuration continues to work through inheritance. Runtime 
updates to these core Spark
    settings through `spark.conf.set` and SQL `SET` remain blocked by default; 
this PR preserves the
    existing public configuration-write rules.
    
    ### How was this patch tested?
    
    `ArtifactManagerIvySettingsSuite`: 7 tests passed, covering inherited and 
internally supplied
    session settings, timeout defaults and validation, local Ivy repositories, 
and isolated caches.
    
    ```text
    build/sbt 'sql/testOnly 
org.apache.spark.sql.artifact.ArtifactManagerIvySettingsSuite'
    ```
    
    The latest follow-up changes documentation only. `git diff --check`, 
changed-source line-length
    checks, and ASCII checks passed; functional tests were not rerun for this 
documentation update.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: OpenAI Codex (GPT-6)
    
    Closes #59977 from qianlan717/session-ivy-settings.
    
    Authored-by: qianlan717 <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
    
    (cherry picked from commit c942bd076efef81cf223a1a99e244d9021ce4d5f)
    Signed-off-by: Hyukjin Kwon <[email protected]>
    
    
    skip-checks: true
---
 .../org/apache/spark/internal/config/package.scala |  10 +-
 docs/configuration.md                              |   8 +-
 .../spark/sql/artifact/ArtifactManager.scala       |  14 +--
 .../artifact/ArtifactManagerIvySettingsSuite.scala | 112 ++++++++++++++++++++-
 4 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/core/src/main/scala/org/apache/spark/internal/config/package.scala 
b/core/src/main/scala/org/apache/spark/internal/config/package.scala
index d8240dc1506d..715146e9e0bc 100644
--- a/core/src/main/scala/org/apache/spark/internal/config/package.scala
+++ b/core/src/main/scala/org/apache/spark/internal/config/package.scala
@@ -3073,7 +3073,9 @@ package object config {
       .doc("Path to specify the Ivy user directory, used for the local Ivy 
cache and " +
         "package files from spark.jars.packages. " +
         "This will override the Ivy property ivy.default.ivy.user.dir " +
-        "which defaults to ~/.ivy2.5.2")
+        "which defaults to ~/.ivy2.5.2. " +
+        "SparkSession.addArtifact reads the local repository search path from 
the session " +
+        "configuration and keeps its runtime cache and downloaded jars 
session-local.")
       .version("1.3.0")
       .stringConf
       .createWithDefault("~/.ivy2.5.2")
@@ -3083,6 +3085,8 @@ package object config {
       .doc("Path to an Ivy settings file to customize resolution of jars 
specified " +
         "using spark.jars.packages or ivy:// URIs passed to 
SparkSession.addArtifact instead " +
         "of the built-in defaults, such as maven central. " +
+        "SparkSession.addArtifact reads this setting from its session, 
including values " +
+        "inherited from SparkConf. Updates through spark.conf.set are blocked 
by default. " +
         "For spark.jars.packages, additional repositories from 
spark.jars.repositories will " +
         "also be included. " +
         "Client-resolved Spark Connect Ivy URIs use this setting only when the 
settings file is " +
@@ -3099,7 +3103,7 @@ package object config {
     ConfigBuilder("spark.jars.ivyConnectTimeout")
       .doc("Connection timeout for Ivy repository requests made by " +
         "SparkSession.addArtifact. Client-resolved Spark Connect Ivy URIs do 
not use this " +
-        "setting. This must be set before the SparkContext starts.")
+        "setting. The session configuration value is captured on first use of 
the artifact APIs.")
       .version("4.4.0")
       .withBindingPolicy(ConfigBindingPolicy.NOT_APPLICABLE)
       .timeConf(TimeUnit.MILLISECONDS)
@@ -3112,7 +3116,7 @@ package object config {
     ConfigBuilder("spark.jars.ivyReadTimeout")
       .doc("Read timeout for Ivy repository requests made by 
SparkSession.addArtifact. " +
         "Client-resolved Spark Connect Ivy URIs do not use this setting. " +
-        "This must be set before the SparkContext starts.")
+        "The session configuration value is captured on first use of the 
artifact APIs.")
       .version("4.4.0")
       .withBindingPolicy(ConfigBindingPolicy.NOT_APPLICABLE)
       .timeConf(TimeUnit.MILLISECONDS)
diff --git a/docs/configuration.md b/docs/configuration.md
index b94f863f2f2b..1195b759c9b4 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -1083,6 +1083,8 @@ Apart from these, the following properties are also 
available, and may be useful
     Path to specify the Ivy user directory, used for the local Ivy cache and 
package files from
     <code>spark.jars.packages</code>. This will override the Ivy property 
<code>ivy.default.ivy.user.dir</code>
     which defaults to ~/.ivy2.
+    <code>SparkSession.addArtifact</code> reads the local repository search 
path from the session
+    configuration. Its runtime cache and downloaded jars remain session-local.
   </td>
   <td>1.3.0</td>
 </tr>
@@ -1093,6 +1095,8 @@ Apart from these, the following properties are also 
available, and may be useful
     Path to an Ivy settings file to customize resolution of jars specified 
using
     <code>spark.jars.packages</code> or <code>ivy://</code> URIs passed to
     <code>SparkSession.addArtifact</code> instead of the built-in defaults, 
such as maven central.
+    <code>SparkSession.addArtifact</code> reads this setting from its session, 
including values
+    inherited from SparkConf. Updates through <code>spark.conf.set</code> are 
blocked by default.
     For <code>spark.jars.packages</code>, additional repositories from
     <code>spark.jars.repositories</code> will also be included.
     The <code>spark-submit --repositories</code> option applies to 
submission-time resolution.
@@ -1118,7 +1122,7 @@ Apart from these, the following properties are also 
available, and may be useful
     Connection timeout for Ivy repository requests made by
     <code>SparkSession.addArtifact</code>.
     Client-resolved Spark Connect Ivy URIs do not use this setting.
-    This must be set before the SparkContext starts.
+    The session configuration value is captured on first use of the artifact 
APIs.
   </td>
   <td>4.4.0</td>
 </tr>
@@ -1128,7 +1132,7 @@ Apart from these, the following properties are also 
available, and may be useful
   <td>
     Read timeout for Ivy repository requests made by 
<code>SparkSession.addArtifact</code>.
     Client-resolved Spark Connect Ivy URIs do not use this setting.
-    This must be set before the SparkContext starts.
+    The session configuration value is captured on first use of the artifact 
APIs.
   </td>
   <td>4.4.0</td>
 </tr>
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 8e6f7f920f1e..33d1b5743bea 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
@@ -33,7 +33,7 @@ import org.apache.hadoop.fs.{LocalFileSystem, Path => FSPath}
 
 import org.apache.spark.{JobArtifactSet, JobArtifactState, SparkContext, 
SparkEnv, SparkException, SparkRuntimeException, 
SparkUnsupportedOperationException}
 import org.apache.spark.internal.{Logging, LogKeys}
-import org.apache.spark.internal.config.{CONNECT_SCALA_UDF_STUB_PREFIXES, 
EXECUTOR_USER_CLASS_PATH_FIRST, JAR_IVY_CONNECT_TIMEOUT, JAR_IVY_READ_TIMEOUT, 
JAR_IVY_REPO_PATH, JAR_IVY_SETTING_PATH}
+import org.apache.spark.internal.config.{ConfigReader, 
CONNECT_SCALA_UDF_STUB_PREFIXES, EXECUTOR_USER_CLASS_PATH_FIRST, 
JAR_IVY_CONNECT_TIMEOUT, JAR_IVY_READ_TIMEOUT, JAR_IVY_REPO_PATH, 
JAR_IVY_SETTING_PATH, SparkConfigProvider}
 import org.apache.spark.sql.Artifact
 import org.apache.spark.sql.classic.SparkSession
 import 
org.apache.spark.sql.execution.datasources.v2.ffi.NativeDataSourcePackage
@@ -74,20 +74,22 @@ class ArtifactManager(session: SparkSession) extends 
AutoCloseable with Logging
 
   private val ivyCachePath = artifactPath.resolve(".ivy-cache")
 
+  private def ivyConfigReader: ConfigReader =
+    new ConfigReader(new SparkConfigProvider(session.conf.getAllAsJava))
+
   private lazy val runtimeDependencyResolver = {
-    val sparkConf = session.sparkContext.getConf
     val ivyPath = Files.createDirectories(ivyCachePath).toString
     new RuntimeDependencyResolver(
-      ivySettingsPath = sparkConf.get(JAR_IVY_SETTING_PATH),
+      ivySettingsPath = JAR_IVY_SETTING_PATH.readFrom(ivyConfigReader),
       ivyPath = Some(ivyPath),
-      localIvyPath = sparkConf.getOption(JAR_IVY_REPO_PATH.key))
+      localIvyPath = session.conf.getAll.get(JAR_IVY_REPO_PATH.key))
   }
 
   private[sql] lazy val ivyConnectTimeoutMs: Int =
-    session.sparkContext.getConf.get(JAR_IVY_CONNECT_TIMEOUT).toInt
+    JAR_IVY_CONNECT_TIMEOUT.readFrom(ivyConfigReader).toInt
 
   private[sql] lazy val ivyReadTimeoutMs: Int =
-    session.sparkContext.getConf.get(JAR_IVY_READ_TIMEOUT).toInt
+    JAR_IVY_READ_TIMEOUT.readFrom(ivyConfigReader).toInt
 
   // The base directory/URI where all class file artifacts are stored for this 
`sessionUUID`.
   protected[artifact] val (classDir, replClassURI): (Path, String) =
diff --git 
a/sql/core/src/test/scala/org/apache/spark/sql/artifact/ArtifactManagerIvySettingsSuite.scala
 
b/sql/core/src/test/scala/org/apache/spark/sql/artifact/ArtifactManagerIvySettingsSuite.scala
index efb57fd0e478..4de7675b17b4 100644
--- 
a/sql/core/src/test/scala/org/apache/spark/sql/artifact/ArtifactManagerIvySettingsSuite.scala
+++ 
b/sql/core/src/test/scala/org/apache/spark/sql/artifact/ArtifactManagerIvySettingsSuite.scala
@@ -20,7 +20,7 @@ import java.net.URI
 import java.nio.file.Files
 
 import org.apache.spark.SparkConf
-import org.apache.spark.internal.config.{JAR_IVY_CONNECT_TIMEOUT, 
JAR_IVY_READ_TIMEOUT}
+import org.apache.spark.internal.config.{JAR_IVY_CONNECT_TIMEOUT, 
JAR_IVY_READ_TIMEOUT, JAR_IVY_REPO_PATH}
 import org.apache.spark.sql.test.SharedSparkSession
 import org.apache.spark.util.{IvyTestUtils, MavenUtils, Utils}
 import org.apache.spark.util.MavenUtils.MavenCoordinate
@@ -45,7 +45,10 @@ class ArtifactManagerIvySettingsSuite extends 
SharedSparkSession {
 
   override protected def sparkConf: SparkConf = {
     super.sparkConf
-      .set(MavenUtils.JAR_IVY_SETTING_PATH_KEY, ivySettings.toString)
+      .set("spark.test.artifact.ivySettingsDir", ivySettingsDir.toString)
+      .set(
+        MavenUtils.JAR_IVY_SETTING_PATH_KEY,
+        "${spark.test.artifact.ivySettingsDir}/ivysettings.xml")
       .set(JAR_IVY_CONNECT_TIMEOUT, 7000L)
       .set(JAR_IVY_READ_TIMEOUT, 11000L)
   }
@@ -64,6 +67,46 @@ class ArtifactManagerIvySettingsSuite extends 
SharedSparkSession {
     assert(conf.get(JAR_IVY_READ_TIMEOUT) == 300000L)
   }
 
+  test("Ivy timeouts use session configuration and retain defaults") {
+    val session = spark.newSession()
+    val defaultSession = spark.newSession()
+    try {
+      session.sessionState.conf.setConfString(JAR_IVY_CONNECT_TIMEOUT.key, 
"2s")
+      session.sessionState.conf.setConfString(JAR_IVY_READ_TIMEOUT.key, "3m")
+      defaultSession.sessionState.conf.unsetConf(JAR_IVY_CONNECT_TIMEOUT.key)
+      defaultSession.sessionState.conf.unsetConf(JAR_IVY_READ_TIMEOUT.key)
+
+      assert(session.artifactManager.ivyConnectTimeoutMs == 2000)
+      assert(session.artifactManager.ivyReadTimeoutMs == 180000)
+      assert(defaultSession.artifactManager.ivyConnectTimeoutMs == 30000)
+      assert(defaultSession.artifactManager.ivyReadTimeoutMs == 300000)
+    } finally {
+      session.artifactManager.cleanUpResourcesForTesting()
+      defaultSession.artifactManager.cleanUpResourcesForTesting()
+    }
+  }
+
+  test("Ivy timeouts validate session configuration") {
+    for {
+      entry <- Seq(JAR_IVY_CONNECT_TIMEOUT, JAR_IVY_READ_TIMEOUT)
+      value <- Seq("0ms", "-1ms", "2147483648ms")
+    } {
+      val session = spark.newSession()
+      try {
+        session.sessionState.conf.setConfString(entry.key, value)
+        intercept[IllegalArgumentException] {
+          if (entry == JAR_IVY_CONNECT_TIMEOUT) {
+            session.artifactManager.ivyConnectTimeoutMs
+          } else {
+            session.artifactManager.ivyReadTimeoutMs
+          }
+        }
+      } finally {
+        session.artifactManager.cleanUpResourcesForTesting()
+      }
+    }
+  }
+
   test("SparkSession artifact APIs use spark.jars.ivySettings") {
     val ivyUri = URI.create(s"ivy://${coordinate.toString}")
     val otherSession = spark.newSession()
@@ -85,6 +128,71 @@ class ArtifactManagerIvySettingsSuite extends 
SharedSparkSession {
     assert(spark.artifactManager.ivyReadTimeoutMs == 11000)
   }
 
+  test("SparkSession artifact APIs use session Ivy settings") {
+    withTempDir { dir =>
+      val sessionCoordinate = MavenCoordinate("my.session.lib", "mylib", "0.1")
+      val sessionRepository = IvyTestUtils.createLocalRepositoryForTests(
+        sessionCoordinate,
+        dependencies = None,
+        rootDir = Some(dir.toPath.resolve("repository").toFile))
+      val sessionIvySettings = dir.toPath.resolve("session-ivysettings.xml")
+      Files.writeString(
+        sessionIvySettings,
+        s"""<ivysettings>
+           |  <settings defaultResolver="session"/>
+           |  <resolvers>
+           |    <ibiblio name="session" m2compatible="true" 
root="${sessionRepository.toURI}"/>
+           |  </resolvers>
+           |</ivysettings>""".stripMargin)
+      val session = spark.newSession()
+      try {
+        session.sessionState.conf.setConfString(
+          "spark.test.artifact.ivySettingsDir", dir.toString)
+        session.sessionState.conf.setConfString(
+          MavenUtils.JAR_IVY_SETTING_PATH_KEY,
+          "${spark.test.artifact.ivySettingsDir}/session-ivysettings.xml")
+        session.addArtifact(URI.create(s"ivy://$sessionCoordinate"))
+        val jarName =
+          s"${sessionCoordinate.groupId}_${sessionCoordinate.artifactId}-" +
+            s"${sessionCoordinate.version}.jar"
+        
assert(Files.exists(session.artifactManager.artifactPath.resolve("jars").resolve(jarName)))
+        assert(spark.conf.get("spark.test.artifact.ivySettingsDir") == 
ivySettingsDir.toString)
+      } finally {
+        session.artifactManager.cleanUpResourcesForTesting()
+      }
+    }
+  }
+
+  test("SparkSession artifacts use the session Ivy repository with an isolated 
cache") {
+    withTempDir { dir =>
+      val sessionCoordinate = MavenCoordinate("my.session.local", "mylib", 
"0.1")
+      val localIvyHome = dir.toPath.resolve("ivy")
+      IvyTestUtils.createLocalRepositoryForTests(
+        sessionCoordinate,
+        dependencies = None,
+        rootDir = Some(localIvyHome.resolve("local").toFile),
+        useIvyLayout = true)
+      val session = spark.newSession()
+      try {
+        
session.sessionState.conf.setConfString(MavenUtils.JAR_IVY_SETTING_PATH_KEY, "")
+        session.sessionState.conf.setConfString(JAR_IVY_REPO_PATH.key, 
localIvyHome.toString)
+
+        session.addArtifact(URI.create(s"ivy://$sessionCoordinate"))
+
+        val jarName =
+          s"${sessionCoordinate.groupId}_${sessionCoordinate.artifactId}-" +
+            s"${sessionCoordinate.version}.jar"
+        val artifactPath = session.artifactManager.artifactPath
+        assert(Files.exists(artifactPath.resolve("jars").resolve(jarName)))
+        
assert(Files.exists(artifactPath.resolve(".ivy-cache").resolve("jars").resolve(jarName)))
+        assert(!Files.exists(localIvyHome.resolve("cache")))
+        assert(!Files.exists(localIvyHome.resolve("jars")))
+      } finally {
+        session.artifactManager.cleanUpResourcesForTesting()
+      }
+    }
+  }
+
   test("SPARK-60012: cloning skips the Ivy cache and creates a fresh cache on 
resolution") {
     val ivyUri = URI.create(s"ivy://${coordinate.toString}")
     val jarName = 
s"${coordinate.groupId}_${coordinate.artifactId}-${coordinate.version}.jar"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to