-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14914] Fix Command too long for windows. Especially for test cases. #12694
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2c1b9e2
Fix Executor's Command too long problem
taoli91 79560bc
Fix Spark Launcher Suite
taoli91 d092ef5
Fix another too long
taoli91 6f8671e
Fix Abstract cmd builder
taoli91 efc0df0
Remove normalize path
taoli91 df0f5dd
Minor format fix
taoli91 e26d949
fix spark-submit.cmd
taoli91 4a7fb86
Fix shorten class path
taoli91 d40d61a
Handle null files on create jar
taoli91 41d0003
Scala style fixes
taoli91 a0b3531
Remove the dependency to javafx
taoli91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import java.nio.ByteBuffer | |
| import java.nio.channels.Channels | ||
| import java.nio.charset.StandardCharsets | ||
| import java.nio.file.Files | ||
| import java.util | ||
| import java.util.{Locale, Properties, Random, UUID} | ||
| import java.util.concurrent._ | ||
| import javax.net.ssl.HttpsURLConnection | ||
|
|
@@ -1090,6 +1091,50 @@ private[spark] object Utils extends Logging { | |
| bytesToString(megabytes * 1024L * 1024L) | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Create a jar file at the given path, containing a manifest with a classpath | ||
| * that references all specified entries. | ||
| */ | ||
| def createShortClassPath(tempDir: File, classPath: String) : String = { | ||
| if (isWindows) { | ||
| val env = new util.HashMap[String, String](System.getenv()) | ||
| val javaCps = FileUtil | ||
| .createJarWithClassPath(classPath, new Path(tempDir.getAbsolutePath), env) | ||
| val javaCpStr = javaCps(0) + javaCps(1) | ||
| logInfo("Shorten the class path to: " + javaCpStr) | ||
| javaCpStr | ||
| } else { | ||
| classPath | ||
| } | ||
| } | ||
|
|
||
| def createShortClassPath(classPath: String) : String = { | ||
|
||
| val tempDir = createTempDir("classpaths") | ||
| createShortClassPath(tempDir, classPath) | ||
| } | ||
|
|
||
| /** | ||
| * Create a jar file at the given path, containing a manifest with a classpath | ||
| * that references all specified entries. | ||
| */ | ||
| def shortenClasspath(builder: ProcessBuilder): Unit = { | ||
| if (builder.command.asScala.mkString("\"", "\" \"", "\"").length > 8190) { | ||
| logWarning("Cmd too long, try to shorten the classpath") | ||
| // look for the class path | ||
| // note that environment set in teh ProcessBuilder is process-local. So it | ||
| // won't pollute the environment | ||
| val command = builder.command() | ||
| val idxCp = command.indexOf("-cp") | ||
| if (idxCp > 0 && idxCp + 1 < command.size()) { | ||
| val classPath = command.get(idxCp + 1) | ||
| val shortPath = createShortClassPath(classPath) | ||
| command.set(idxCp + 1, shortPath) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Execute a command and return the process running the command. | ||
| */ | ||
|
|
@@ -1103,6 +1148,11 @@ private[spark] object Utils extends Logging { | |
| for ((key, value) <- extraEnvironment) { | ||
| environment.put(key, value) | ||
| } | ||
|
|
||
| if (Utils.isWindows) { | ||
| Utils.shortenClasspath(builder) | ||
| } | ||
|
|
||
| val process = builder.start() | ||
| if (redirectStderr) { | ||
| val threadName = "redirect stderr for command " + command(0) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,13 @@ | |
|
|
||
| package org.apache.spark.launcher; | ||
|
|
||
| import java.io.File; | ||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.commons.lang.SystemUtils; | ||
| import org.apache.spark.util.Utils; | ||
|
||
| import org.junit.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -99,15 +102,28 @@ public void testChildProcLauncher() throws Exception { | |
| String.format("%s=-Dfoo=ShouldBeOverriddenBelow", SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS)) | ||
| .setConf(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS, | ||
| "-Dfoo=bar -Dtest.appender=childproc") | ||
| .setConf(SparkLauncher.DRIVER_EXTRA_CLASSPATH, System.getProperty("java.class.path")) | ||
| .addSparkArg(opts.CLASS, "ShouldBeOverriddenBelow") | ||
| .setMainClass(SparkLauncherTestApp.class.getName()) | ||
| .addAppArgs("proc"); | ||
| final Process app = launcher.launch(); | ||
|
|
||
| new OutputRedirector(app.getInputStream(), TF); | ||
| new OutputRedirector(app.getErrorStream(), TF); | ||
| assertEquals(0, app.waitFor()); | ||
| File tempDir = Utils.createTempDir(System.getProperty("java.io.tmpdir"), "spark"); | ||
| try { | ||
| if (SystemUtils.IS_OS_WINDOWS) { | ||
| launcher.setConf(SparkLauncher.DRIVER_EXTRA_CLASSPATH, | ||
| Utils.createShortClassPath(tempDir, System.getProperty("java.class.path"))); | ||
| } else { | ||
| launcher.setConf(SparkLauncher.DRIVER_EXTRA_CLASSPATH, System.getProperty("java.class.path")); | ||
| } | ||
| final Process app = launcher.launch(); | ||
|
|
||
| new OutputRedirector(app.getInputStream(), TF); | ||
| new OutputRedirector(app.getErrorStream(), TF); | ||
| assertEquals(0, app.waitFor()); | ||
| } finally { | ||
| if(tempDir.exists()) { | ||
| Utils.deleteRecursively(tempDir); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static class SparkLauncherTestApp { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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,
def createShortClassPath(tempDir: File, classPath: String): String = {