-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24446][yarn] Properly quote library path for YARN. #21476
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -899,7 +899,8 @@ private[spark] class Client( | |
| val libraryPaths = Seq(sparkConf.get(DRIVER_LIBRARY_PATH), | ||
| sys.props.get("spark.driver.libraryPath")).flatten | ||
| if (libraryPaths.nonEmpty) { | ||
| prefixEnv = Some(getClusterPath(sparkConf, Utils.libraryPathEnvPrefix(libraryPaths))) | ||
| prefixEnv = Some(createLibraryPathPrefix(libraryPaths.mkString(File.pathSeparator), | ||
| sparkConf)) | ||
| } | ||
| if (sparkConf.get(AM_JAVA_OPTIONS).isDefined) { | ||
| logWarning(s"${AM_JAVA_OPTIONS.key} will not take effect in cluster mode") | ||
|
|
@@ -921,7 +922,7 @@ private[spark] class Client( | |
| .map(YarnSparkHadoopUtil.escapeForShell) | ||
| } | ||
| sparkConf.get(AM_LIBRARY_PATH).foreach { paths => | ||
| prefixEnv = Some(getClusterPath(sparkConf, Utils.libraryPathEnvPrefix(Seq(paths)))) | ||
| prefixEnv = Some(createLibraryPathPrefix(paths, sparkConf)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1485,6 +1486,22 @@ private object Client extends Logging { | |
| YarnAppReport(report.getYarnApplicationState(), report.getFinalApplicationStatus(), diagsOpt) | ||
| } | ||
|
|
||
| /** | ||
| * Create a properly quoted library path string to be added as a prefix to the command executed by | ||
| * YARN. This is different from plain quoting due to YARN executing the command through "bash -c". | ||
| */ | ||
| def createLibraryPathPrefix(libpath: String, conf: SparkConf): String = { | ||
| val cmdPrefix = if (Utils.isWindows) { | ||
| Utils.libraryPathEnvPrefix(Seq(libpath)) | ||
| } else { | ||
| val envName = Utils.libraryPathEnvName | ||
| // For quotes, escape both the quote and the escape character when encoding in the command | ||
| // string. | ||
| val quoted = libpath.replace("\"", "\\\\\\\"") | ||
|
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. Dumb question i think escaping """ => "\"". Not sure why we have so many escapes otherwise. Trying to understand, else PR looks good
Contributor
Author
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. This needs to be double escaped because it goes through two rounds of bash interpreting the value. |
||
| envName + "=\\\"" + quoted + File.pathSeparator + "$" + envName + "\\\"" | ||
| } | ||
| getClusterPath(conf, cmdPrefix) | ||
| } | ||
| } | ||
|
|
||
| private[spark] class YarnClusterApplication extends SparkApplication { | ||
|
|
||
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.
maybe pull this into a util class and have unit tests?
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.
This is so specific to the way YARN runs things that I don't think it would be useful anywhere else. If at some point it becomes useful, the code can be moved.
I think the tests I added are better than just unit testing this function, since that way the code is actually being run through YARN and bash.
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.
k