Skip to content

Commit 41dc598

Browse files
committed
[SPARK-3264] Allow users to set executor Spark home in Mesos
The executors and the driver may not share the same Spark home. There is currently one way to set the executor side Spark home in Mesos, through setting `spark.home`. However, this is neither documented nor intuitive. This PR adds a more specific config `spark.mesos.executor.home` and exposes this to the user. liancheng tnachen Author: Andrew Or <[email protected]> Closes #2166 from andrewor14/mesos-spark-home and squashes the following commits: b87965e [Andrew Or] Merge branch 'master' of github.com:apache/spark into mesos-spark-home f6abb2e [Andrew Or] Document spark.mesos.executor.home ca7846d [Andrew Or] Add more specific configuration for executor Spark home in Mesos
1 parent 6d392b3 commit 41dc598

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/CoarseMesosSchedulerBackend.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ private[spark] class CoarseMesosSchedulerBackend(
7171
val taskIdToSlaveId = new HashMap[Int, String]
7272
val failuresBySlaveId = new HashMap[String, Int] // How many times tasks on each slave failed
7373

74-
val sparkHome = sc.getSparkHome().getOrElse(throw new SparkException(
75-
"Spark home is not set; set it through the spark.home system " +
76-
"property, the SPARK_HOME environment variable or the SparkContext constructor"))
74+
val executorSparkHome = conf.getOption("spark.mesos.executor.home")
75+
.orElse(sc.getSparkHome())
76+
.getOrElse {
77+
throw new SparkException("Executor Spark home `spark.mesos.executor.home` is not set!")
78+
}
7779

7880
val extraCoresPerSlave = conf.getInt("spark.mesos.extra.cores", 0)
7981

@@ -144,7 +146,7 @@ private[spark] class CoarseMesosSchedulerBackend(
144146

145147
val uri = conf.get("spark.executor.uri", null)
146148
if (uri == null) {
147-
val runScript = new File(sparkHome, "./bin/spark-class").getCanonicalPath
149+
val runScript = new File(executorSparkHome, "./bin/spark-class").getCanonicalPath
148150
command.setValue(
149151
"\"%s\" org.apache.spark.executor.CoarseGrainedExecutorBackend %s %s %s %d".format(
150152
runScript, driverUrl, offer.getSlaveId.getValue, offer.getHostname, numCores))

core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosSchedulerBackend.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ private[spark] class MesosSchedulerBackend(
8686
}
8787

8888
def createExecutorInfo(execId: String): ExecutorInfo = {
89-
val sparkHome = sc.getSparkHome().getOrElse(throw new SparkException(
90-
"Spark home is not set; set it through the spark.home system " +
91-
"property, the SPARK_HOME environment variable or the SparkContext constructor"))
89+
val executorSparkHome = sc.conf.getOption("spark.mesos.executor.home")
90+
.orElse(sc.getSparkHome()) // Fall back to driver Spark home for backward compatibility
91+
.getOrElse {
92+
throw new SparkException("Executor Spark home `spark.mesos.executor.home` is not set!")
93+
}
9294
val environment = Environment.newBuilder()
9395
sc.conf.getOption("spark.executor.extraClassPath").foreach { cp =>
9496
environment.addVariables(
@@ -114,7 +116,7 @@ private[spark] class MesosSchedulerBackend(
114116
.setEnvironment(environment)
115117
val uri = sc.conf.get("spark.executor.uri", null)
116118
if (uri == null) {
117-
command.setValue(new File(sparkHome, "/sbin/spark-executor").getCanonicalPath)
119+
command.setValue(new File(executorSparkHome, "/sbin/spark-executor").getCanonicalPath)
118120
} else {
119121
// Grab everything to the first '.'. We'll use that and '*' to
120122
// glob the directory "correctly".

docs/configuration.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ Apart from these, the following properties are also available, and may be useful
214214
process. The user can specify multiple of these and to set multiple environment variables.
215215
</td>
216216
</tr>
217+
<tr>
218+
<td><code>spark.mesos.executor.home</code></td>
219+
<td>driver side <code>SPARK_HOME</code></td>
220+
<td>
221+
Set the directory in which Spark is installed on the executors in Mesos. By default, the
222+
executors will simply use the driver's Spark home directory, which may not be visible to
223+
them. Note that this is only relevant if a Spark binary package is not specified through
224+
<code>spark.executor.uri</code>.
225+
</td>
226+
</tr>
217227
</table>
218228

219229
#### Shuffle Behavior

0 commit comments

Comments
 (0)