Skip to content

Commit 9f41dca

Browse files
committed
Client mode fix
1 parent 7402291 commit 9f41dca

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

launcher/src/main/java/org/apache/spark/launcher/SparkSubmitCommandBuilder.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,10 @@ private List<String> buildSparkSubmitCommand(Map<String, String> env)
267267

268268
// We don't want the client to specify Xmx. These have to be set by their corresponding
269269
// memory flag --driver-memory or configuration entry spark.driver.memory
270+
String driverDefaultJavaOptions = config.get(SparkLauncher.DRIVER_DEFAULT_JAVA_OPTIONS);
271+
checkJavaOptions(driverDefaultJavaOptions);
270272
String driverExtraJavaOptions = config.get(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS);
271-
if (!isEmpty(driverExtraJavaOptions) && driverExtraJavaOptions.contains("Xmx")) {
272-
String msg = String.format("Not allowed to specify max heap(Xmx) memory settings through " +
273-
"java options (was %s). Use the corresponding --driver-memory or " +
274-
"spark.driver.memory configuration instead.", driverExtraJavaOptions);
275-
throw new IllegalArgumentException(msg);
276-
}
273+
checkJavaOptions(driverExtraJavaOptions);
277274

278275
if (isClientMode) {
279276
// Figuring out where the memory value come from is a little tricky due to precedence.
@@ -289,6 +286,7 @@ private List<String> buildSparkSubmitCommand(Map<String, String> env)
289286
String memory = firstNonEmpty(tsMemory, config.get(SparkLauncher.DRIVER_MEMORY),
290287
System.getenv("SPARK_DRIVER_MEMORY"), System.getenv("SPARK_MEM"), DEFAULT_MEM);
291288
cmd.add("-Xmx" + memory);
289+
addOptionString(cmd, driverDefaultJavaOptions);
292290
addOptionString(cmd, driverExtraJavaOptions);
293291
mergeEnvPathList(env, getLibPathEnvName(),
294292
config.get(SparkLauncher.DRIVER_EXTRA_LIBRARY_PATH));
@@ -299,6 +297,15 @@ private List<String> buildSparkSubmitCommand(Map<String, String> env)
299297
return cmd;
300298
}
301299

300+
private void checkJavaOptions(String javaOptions) {
301+
if (!isEmpty(javaOptions) && javaOptions.contains("Xmx")) {
302+
String msg = String.format("Not allowed to specify max heap(Xmx) memory settings through " +
303+
"java options (was %s). Use the corresponding --driver-memory or " +
304+
"spark.driver.memory configuration instead.", javaOptions);
305+
throw new IllegalArgumentException(msg);
306+
}
307+
}
308+
302309
private List<String> buildPySparkShellCommand(Map<String, String> env) throws IOException {
303310
// For backwards compatibility, if a script is specified in
304311
// the pyspark command line, then run it using spark-submit.

launcher/src/test/java/org/apache/spark/launcher/SparkSubmitCommandBuilderSuite.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ public void testMissingAppResource() {
251251
}
252252

253253
private void testCmdBuilder(boolean isDriver, boolean useDefaultPropertyFile) throws Exception {
254+
final String DRIVER_DEFAULT_PARAM = "-Ddriver-default";
255+
final String DRIVER_EXTRA_PARAM = "-Ddriver-extra";
254256
String deployMode = isDriver ? "client" : "cluster";
255257

256258
SparkSubmitCommandBuilder launcher =
@@ -270,7 +272,8 @@ private void testCmdBuilder(boolean isDriver, boolean useDefaultPropertyFile) th
270272
launcher.setPropertiesFile(dummyPropsFile.getAbsolutePath());
271273
launcher.conf.put(SparkLauncher.DRIVER_MEMORY, "1g");
272274
launcher.conf.put(SparkLauncher.DRIVER_EXTRA_CLASSPATH, "/driver");
273-
launcher.conf.put(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS, "-Ddriver");
275+
launcher.conf.put(SparkLauncher.DRIVER_DEFAULT_JAVA_OPTIONS, DRIVER_DEFAULT_PARAM);
276+
launcher.conf.put(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS, DRIVER_EXTRA_PARAM);
274277
launcher.conf.put(SparkLauncher.DRIVER_EXTRA_LIBRARY_PATH, "/native");
275278
} else {
276279
launcher.childEnv.put("SPARK_CONF_DIR", System.getProperty("spark.test.home")
@@ -284,6 +287,9 @@ private void testCmdBuilder(boolean isDriver, boolean useDefaultPropertyFile) th
284287

285288
if (isDriver) {
286289
assertTrue("Driver -Xmx should be configured.", cmd.contains("-Xmx1g"));
290+
assertTrue("Driver default options should be configured.",
291+
cmd.contains(DRIVER_DEFAULT_PARAM));
292+
assertTrue("Driver extra options should be configured.", cmd.contains(DRIVER_EXTRA_PARAM));
287293
} else {
288294
boolean found = false;
289295
for (String arg : cmd) {
@@ -293,6 +299,10 @@ private void testCmdBuilder(boolean isDriver, boolean useDefaultPropertyFile) th
293299
}
294300
}
295301
assertFalse("Memory arguments should not be set.", found);
302+
assertFalse("Driver default options should not be configured.",
303+
cmd.contains(DRIVER_DEFAULT_PARAM));
304+
assertFalse("Driver extra options should not be configured.",
305+
cmd.contains(DRIVER_EXTRA_PARAM));
296306
}
297307

298308
String[] cp = findArgValue(cmd, "-cp").split(Pattern.quote(File.pathSeparator));

launcher/src/test/resources/spark-defaults.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717

1818
spark.driver.memory=1g
1919
spark.driver.extraClassPath=/driver
20-
spark.driver.extraJavaOptions=-Ddriver
20+
spark.driver.defaultJavaOptions=-Ddriver-default
21+
spark.driver.extraJavaOptions=-Ddriver-extra
2122
spark.driver.extraLibraryPath=/native

0 commit comments

Comments
 (0)