Skip to content
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

Detect multiple jars on the classpath when init plugin [databricks] #9654

Merged
merged 35 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2f1fae2
Detect multiple jars on the classpath when init plugin
thirtiseven Nov 7, 2023
0c5df62
clean up
thirtiseven Nov 7, 2023
742b508
Apply suggestions from code review
thirtiseven Nov 8, 2023
47ef387
print version info and also check jni/cudf
thirtiseven Nov 8, 2023
171c016
print version info and also check jni/cudf
thirtiseven Nov 8, 2023
e29e37d
add config for allowing multiple jars
thirtiseven Nov 8, 2023
0441f53
keep jar path in error messages
thirtiseven Nov 8, 2023
ded091e
address comments
thirtiseven Nov 9, 2023
42fc474
Update sql-plugin/src/main/scala/com/nvidia/spark/rapids/Plugin.scala
thirtiseven Nov 9, 2023
6bbedfb
Update sql-plugin/src/main/scala/com/nvidia/spark/rapids/Plugin.scala
thirtiseven Nov 9, 2023
d9264d8
address comments
thirtiseven Nov 9, 2023
5c108bb
Merge branch 'NVIDIA:branch-23.12' into detect_multiple_jars
thirtiseven Nov 13, 2023
c2a0402
Use unique properties for intermediate jars
thirtiseven Nov 13, 2023
14c536d
clean up
thirtiseven Nov 13, 2023
b099358
address comment
thirtiseven Nov 13, 2023
74010e0
Apply suggestions from code review
thirtiseven Nov 14, 2023
fd129c9
address comments
thirtiseven Nov 14, 2023
5e292c4
add the project.artifactId to build-info and check it
thirtiseven Nov 14, 2023
15022d7
remove unnecessary copyright update
thirtiseven Nov 14, 2023
28c8dcd
remove log
thirtiseven Nov 14, 2023
3dc12e4
Add 2.13 support
thirtiseven Nov 14, 2023
14fe6fc
use revision to check duplicate jars
thirtiseven Nov 15, 2023
5dcc15f
fix 2.13 build
thirtiseven Nov 15, 2023
08f4088
support both SAME_REVISION and NEVER mode
thirtiseven Nov 22, 2023
0ca06b5
Avoid CI change and filter out test
thirtiseven Nov 22, 2023
c7ca0ad
check values for config
thirtiseven Nov 23, 2023
a833c73
use enum
thirtiseven Nov 23, 2023
f5bd0c9
fix two nits
thirtiseven Nov 24, 2023
405bf05
Merge branch 'branch-23.12' into detect_multiple_jars
thirtiseven Nov 24, 2023
7d11a4f
Do not print log if no multiple jar
thirtiseven Nov 24, 2023
c4eef25
ignore subdir when checking multiple jars
thirtiseven Nov 27, 2023
bf4477a
Update sql-plugin/src/main/scala/com/nvidia/spark/rapids/Plugin.scala
thirtiseven Nov 28, 2023
39e0b56
wip ut
thirtiseven Nov 27, 2023
c3279f4
address comment
thirtiseven Nov 28, 2023
70b1247
Merge branch 'branch-24.02' into detect_multiple_jars
thirtiseven Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sql-plugin/src/main/scala/com/nvidia/spark/rapids/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ object RapidsPluginUtils extends Logging {
}
}

private def detectMultipleJar(propName: String, jarName: String,
complainFun: (Boolean, String) => Unit): Unit = {
val classloader = ShimLoader.getShimClassLoader()
val rapidsJarURLs = classloader.getResources(propName).asScala.toSet
lazy val rapidsJars = rapidsJarURLs.map(_.toString.split("!").head).mkString(",")
lazy val rapidsJarsVers = rapidsJarURLs.map {
url => scala.io.Source.fromInputStream(url.openStream()).mkString("")
}.mkString(",")
complainFun(rapidsJarURLs.size <= 1,
s"Multiple $jarName jars found in the classpath: $rapidsJars, please make sure there " +
firestarman marked this conversation as resolved.
Show resolved Hide resolved
s"is only one $jarName jar in the classpath. If it is impossible to fix the classpath " +
s"you can suppress the error by setting ${RapidsConf.ALLOW_MULTIPLE_JARS.key} to true. " +
s"Version info: \n$rapidsJarsVers")
}

def detectMultipleJars(conf: RapidsConf): Unit = {
val complainFun: (Boolean, String) => Unit = conf.allowMultipleJars match {
firestarman marked this conversation as resolved.
Show resolved Hide resolved
case true => (request: Boolean, msg: String) => if (!request) logWarning(msg)
case false => (request: Boolean, msg: String) => require(request, msg)
}
detectMultipleJar(PLUGIN_PROPS_FILENAME, "rapids4spark", complainFun)
detectMultipleJar(JNI_PROPS_FILENAME, "spark-rapids-jni", complainFun)
detectMultipleJar(CUDF_PROPS_FILENAME, "cudf", complainFun)
}

// This assumes Apache Spark logic, if CSPs are setting defaults differently, we may need
// to handle.
def estimateCoresOnExec(conf: SparkConf): Int = {
Expand Down Expand Up @@ -309,6 +334,7 @@ class RapidsDriverPlugin extends DriverPlugin with Logging {
val sparkConf = pluginContext.conf
RapidsPluginUtils.fixupConfigsOnDriver(sparkConf)
val conf = new RapidsConf(sparkConf)
RapidsPluginUtils.detectMultipleJars(conf)
RapidsPluginUtils.logPluginMode(conf)
GpuCoreDumpHandler.driverInit(sc, conf)

Expand Down Expand Up @@ -352,6 +378,7 @@ class RapidsExecutorPlugin extends ExecutorPlugin with Logging {
pluginContext: PluginContext,
extraConf: java.util.Map[String, String]): Unit = {
try {

if (Cuda.getComputeCapabilityMajor < 6) {
throw new RuntimeException(s"GPU compute capability ${Cuda.getComputeCapabilityMajor}" +
" is unsupported, requires 6.0+")
Expand All @@ -363,6 +390,9 @@ class RapidsExecutorPlugin extends ExecutorPlugin with Logging {
val numCores = RapidsPluginUtils.estimateCoresOnExec(sparkConf)
val conf = new RapidsConf(extraConf.asScala.toMap)

// Fail if there are multiple plugin jars in the classpath.
RapidsPluginUtils.detectMultipleJars(conf)

// Compare if the cudf version mentioned in the classpath is equal to the version which
// plugin expects. If there is a version mismatch, throw error. This check can be disabled
// by setting this config spark.rapids.cudfVersionOverride=true
Expand Down
10 changes: 10 additions & 0 deletions sql-plugin/src/main/scala/com/nvidia/spark/rapids/RapidsConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,14 @@ object RapidsConf {
.booleanConf
.createWithDefault(false)

val ALLOW_MULTIPLE_JARS = conf("spark.rapids.sql.allowMultipleJars")
.internal()
.startupOnly()
.doc("Allow multiple rapids-4-spark, spark-rapids-jni, and cudf jars on the classpath. " +
"Spark will take the first one it finds, so the version may not be expected. ")
.booleanConf
.createWithDefault(false)

val ALLOW_DISABLE_ENTIRE_PLAN = conf("spark.rapids.allowDisableEntirePlan")
.internal()
.doc("The plugin has the ability to detect possibe incompatibility with some specific " +
Expand Down Expand Up @@ -2634,6 +2642,8 @@ class RapidsConf(conf: Map[String, String]) extends Logging {

lazy val cudfVersionOverride: Boolean = get(CUDF_VERSION_OVERRIDE)

lazy val allowMultipleJars: Boolean = get(ALLOW_MULTIPLE_JARS)

lazy val allowDisableEntirePlan: Boolean = get(ALLOW_DISABLE_ENTIRE_PLAN)

lazy val useArrowCopyOptimization: Boolean = get(USE_ARROW_OPT)
Expand Down