Skip to content

Commit f7cacff

Browse files
author
Marcelo Vanzin
committed
Remove "launch Spark in new thread" feature.
1 parent 7ed8859 commit f7cacff

File tree

2 files changed

+3
-157
lines changed

2 files changed

+3
-157
lines changed

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

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919

2020
import java.io.File;
2121
import java.io.IOException;
22-
import java.lang.reflect.Method;
23-
import java.net.URL;
24-
import java.net.URLClassLoader;
2522
import java.util.ArrayList;
2623
import java.util.HashMap;
2724
import java.util.List;
2825
import java.util.Map;
2926
import java.util.Properties;
30-
import java.util.concurrent.atomic.AtomicLong;
3127

3228
/**
3329
* Launcher for Spark applications.
@@ -43,8 +39,6 @@
4339
*/
4440
public class SparkLauncher extends AbstractLauncher<SparkLauncher> {
4541

46-
private static final AtomicLong THREAD_ID = new AtomicLong();
47-
4842
protected boolean verbose;
4943
protected String appName;
5044
protected String master;
@@ -139,78 +133,6 @@ public SparkLauncher setVerbose(boolean verbose) {
139133
return this;
140134
}
141135

142-
/**
143-
* Starts a new thread that will run the Spark application.
144-
* <p/>
145-
* The application will run on a separate thread and use a separate, isolated class loader.
146-
* No classes or resources from the current thread's class loader will be visible to the app.
147-
* <p/>
148-
* This mode does not support certain configuration parameters, like configuring the amount of
149-
* driver memory or custom driver command line options. If such configuration is detected, an
150-
* exception will be thrown.
151-
* <p/>
152-
* This is extremely experimental and should not be used in production environments.
153-
* <p/>
154-
* NOTE: SparkSubmit uses system properties to propagate some configuration value to the app
155-
* are run concurrently, they may affect each other's configurations.
156-
* <p/>
157-
* NOTE: for users running JDK versions older than 8, this option can add a lot of overhead
158-
* to the VM's perm gen.
159-
*
160-
* @param exceptionHandler Optional handler for handling exceptions in the app thread.
161-
* @param daemon Whether to start a daemon thread.
162-
* @return A non-daemon thread that will run the application using SparkSubmit. The thread will
163-
* already be started.
164-
*/
165-
public Thread start(Thread.UncaughtExceptionHandler handler, boolean daemon) throws IOException {
166-
// Do some sanity checking that incompatible driver options are not used, because they
167-
// cannot be set in this mode.
168-
Properties props = loadPropertiesFile();
169-
String extraClassPath = null;
170-
if (isClientMode(props)) {
171-
checkState(
172-
find(DRIVER_EXTRA_JAVA_OPTIONS, conf, props) == null,
173-
"Cannot set driver VM options when running in-process.");
174-
checkState(
175-
find(DRIVER_EXTRA_LIBRARY_PATH, conf, props) == null,
176-
"Cannot set native library path when running in-process.");
177-
checkState(
178-
find(DRIVER_MEMORY, conf, props) == null,
179-
"Cannot set driver memory when running in-process.");
180-
extraClassPath = find(DRIVER_EXTRA_CLASSPATH, conf, props);
181-
}
182-
183-
List<String> cp = buildClassPath(extraClassPath);
184-
URL[] cpUrls = new URL[cp.size()];
185-
int idx = 0;
186-
for (String entry : cp) {
187-
cpUrls[idx++] = new File(entry).toURI().toURL();
188-
}
189-
190-
URLClassLoader cl = new URLClassLoader(cpUrls, null);
191-
192-
Thread appThread;
193-
try {
194-
Class<?> sparkSubmit = cl.loadClass("org.apache.spark.deploy.SparkSubmit");
195-
Method main = sparkSubmit.getDeclaredMethod("main", String[].class);
196-
List<String> args = buildSparkSubmitArgs();
197-
appThread = new Thread(new SparkSubmitRunner(main, args));
198-
} catch (ClassNotFoundException cnfe) {
199-
throw new IOException(cnfe);
200-
} catch (NoSuchMethodException nsme) {
201-
throw new IOException(nsme);
202-
}
203-
204-
appThread.setName("SparkLauncher-Submit-" + THREAD_ID.incrementAndGet());
205-
appThread.setContextClassLoader(cl);
206-
if (handler != null) {
207-
appThread.setUncaughtExceptionHandler(handler);
208-
}
209-
appThread.setDaemon(daemon);
210-
appThread.start();
211-
return appThread;
212-
}
213-
214136
/**
215137
* Launches a sub-process that will start the configured Spark application.
216138
*
@@ -340,27 +262,4 @@ private boolean isClientMode(Properties userProps) {
340262
(deployMode == null && !userMaster.startsWith("yarn-"));
341263
}
342264

343-
private static class SparkSubmitRunner implements Runnable {
344-
345-
private final Method main;
346-
private final Object args;
347-
348-
SparkSubmitRunner(Method main, List<String> args) {
349-
this.main = main;
350-
this.args = args.toArray(new String[args.size()]);
351-
}
352-
353-
@Override
354-
public void run() {
355-
try {
356-
main.invoke(null, args);
357-
} catch (RuntimeException re) {
358-
throw re;
359-
} catch (Exception e) {
360-
throw new RuntimeException(e);
361-
}
362-
}
363-
364-
}
365-
366265
}

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

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -68,39 +68,6 @@ public void testChildProcLauncher() throws Exception {
6868
assertEquals(0, app.waitFor());
6969
}
7070

71-
@Test
72-
public void testThreadAppLauncher() throws Exception {
73-
// Do this to avoid overwriting the main test log file.
74-
System.setProperty("test.name", "-testThreadAppLauncher");
75-
76-
SparkLauncher launcher = new SparkLauncher()
77-
.setSparkHome(System.getProperty("spark.test.home"))
78-
.setMaster("local")
79-
.setAppResource("spark-internal")
80-
.setConf(SparkLauncher.DRIVER_EXTRA_CLASSPATH, System.getProperty("java.class.path"))
81-
.setMainClass(SparkLauncherTestApp.class.getName())
82-
.addAppArgs("thread");
83-
84-
printArgs(launcher.buildShellCommand());
85-
86-
Thread app = launcher.start(new Thread.UncaughtExceptionHandler() {
87-
@Override
88-
public void uncaughtException(Thread t, Throwable e) {
89-
String msg = "Uncaught exception in app.";
90-
LOG.error(msg, e);
91-
fail(msg);
92-
}
93-
}, true);
94-
app.join();
95-
}
96-
97-
@Test
98-
public void testInProcessDriverArgValidator() throws Exception {
99-
testInvalidDriverConf(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS);
100-
testInvalidDriverConf(SparkLauncher.DRIVER_MEMORY);
101-
testInvalidDriverConf(SparkLauncher.DRIVER_EXTRA_LIBRARY_PATH);
102-
}
103-
10471
private void testCmdBuilder(boolean isDriver) throws Exception {
10572
String deployMode = isDriver ? "client" : "cluster";
10673

@@ -182,22 +149,6 @@ private void testCmdBuilder(boolean isDriver) throws Exception {
182149
assertEquals("foo", conf.get("spark.foo"));
183150
}
184151

185-
private void testInvalidDriverConf(String key) throws Exception {
186-
try {
187-
new SparkLauncher()
188-
.setSparkHome(System.getProperty("spark.test.home"))
189-
.setAppResource("spark-internal")
190-
.setMainClass(SparkLauncherTestApp.class.getName())
191-
.addAppArgs("thread")
192-
.setConf(key, "foo")
193-
.start(null, true);
194-
fail("Should have failed to start app.");
195-
} catch (IllegalStateException e) {
196-
assertTrue("Correct exception should be thrown.",
197-
e.getMessage().indexOf("running in-process") > 0);
198-
}
199-
}
200-
201152
private String findArgValue(List<String> cmd, String name) {
202153
for (int i = 0; i < cmd.size(); i++) {
203154
if (cmd.get(i).equals(name)) {
@@ -252,13 +203,9 @@ private void printArgs(List<String> cmd) {
252203
public static class SparkLauncherTestApp {
253204

254205
public static void main(String[] args) throws Exception {
255-
if (args[0].equals("proc")) {
256-
assertEquals("bar", System.getProperty("foo"));
257-
} else if (args[0].equals("arg")) {
258-
assertEquals("newline=", args[1]);
259-
} else {
260-
assertEquals("thread", args[0]);
261-
}
206+
assertEquals(1, args.length);
207+
assertEquals("proc", args[0]);
208+
assertEquals("bar", System.getProperty("foo"));
262209
assertEquals("local", System.getProperty(SparkLauncher.SPARK_MASTER));
263210
}
264211

0 commit comments

Comments
 (0)