-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-44246][CONNECT][FOLLOW-UP] Miscellaneous cleanups for Spark Connect Jar/Classfile Isolation #41789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-44246][CONNECT][FOLLOW-UP] Miscellaneous cleanups for Spark Connect Jar/Classfile Isolation #41789
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.executor | ||
|
|
||
| import org.apache.spark.{JobArtifactSet, LocalSparkContext, SparkConf, SparkContext, SparkFunSuite} | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| class ClassLoaderIsolationSuite extends SparkFunSuite with LocalSparkContext { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vicennial The new test failed with Scala 2.13:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should upload both
Sorry, I found the source code in commnets
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try fix #41852
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @LuciferYang |
||
| val jar1 = Thread.currentThread().getContextClassLoader.getResource("TestUDTF.jar").toString | ||
|
|
||
| // package com.example | ||
| // object Hello { def test(): Int = 2 } | ||
| // case class Hello(x: Int, y: Int) | ||
| val jar2 = Thread.currentThread().getContextClassLoader.getResource("TestHelloV2.jar").toString | ||
|
|
||
| // package com.example | ||
| // object Hello { def test(): Int = 3 } | ||
| // case class Hello(x: String) | ||
| val jar3 = Thread.currentThread().getContextClassLoader.getResource("TestHelloV3.jar").toString | ||
|
|
||
| test("Executor classloader isolation with JobArtifactSet") { | ||
| sc = new SparkContext(new SparkConf().setAppName("test").setMaster("local")) | ||
| sc.addJar(jar1) | ||
| sc.addJar(jar2) | ||
| sc.addJar(jar3) | ||
|
|
||
| // TestHelloV2's test method returns '2' | ||
| val artifactSetWithHelloV2 = new JobArtifactSet( | ||
| uuid = Some("hello2"), | ||
| replClassDirUri = None, | ||
| jars = Map(jar2 -> 1L), | ||
| files = Map.empty, | ||
| archives = Map.empty | ||
| ) | ||
|
|
||
| JobArtifactSet.withActive(artifactSetWithHelloV2) { | ||
| sc.parallelize(1 to 1).foreach { i => | ||
| val cls = Utils.classForName("com.example.Hello$") | ||
| val module = cls.getField("MODULE$").get(null) | ||
| val result = cls.getMethod("test").invoke(module).asInstanceOf[Int] | ||
| if (result != 2) { | ||
| throw new RuntimeException("Unexpected result: " + result) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TestHelloV3's test method returns '3' | ||
| val artifactSetWithHelloV3 = new JobArtifactSet( | ||
| uuid = Some("hello3"), | ||
| replClassDirUri = None, | ||
| jars = Map(jar3 -> 1L), | ||
| files = Map.empty, | ||
| archives = Map.empty | ||
| ) | ||
|
|
||
| JobArtifactSet.withActive(artifactSetWithHelloV3) { | ||
| sc.parallelize(1 to 1).foreach { i => | ||
| val cls = Utils.classForName("com.example.Hello$") | ||
| val module = cls.getField("MODULE$").get(null) | ||
| val result = cls.getMethod("test").invoke(module).asInstanceOf[Int] | ||
| if (result != 3) { | ||
| throw new RuntimeException("Unexpected result: " + result) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Should not be able to see any "Hello" class if they're excluded from the artifact set | ||
| val artifactSetWithoutHello = new JobArtifactSet( | ||
| uuid = Some("Jar 1"), | ||
| replClassDirUri = None, | ||
| jars = Map(jar1 -> 1L), | ||
| files = Map.empty, | ||
| archives = Map.empty | ||
| ) | ||
|
|
||
| JobArtifactSet.withActive(artifactSetWithoutHello) { | ||
| sc.parallelize(1 to 1).foreach { i => | ||
| try { | ||
| Utils.classForName("com.example.Hello$") | ||
| throw new RuntimeException("Import should fail") | ||
| } catch { | ||
| case _: ClassNotFoundException => | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HyukjinKwon With directly fetching the Python Includes, I've removed the
private lazy val pythonIncludesandSessionHolder#withSessionBasedPythonPathssince we don't need to propagate them via confs anymoreThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotya. This is exactly the change I planned to made this week :-). Thank you for doing this here.