Skip to content

Commit b890949

Browse files
committed
Abstract usages of converting spark opts to java opts
1 parent 79f63a3 commit b890949

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

core/src/main/scala/org/apache/spark/SparkConf.scala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import scala.collection.mutable.HashMap
4040
*/
4141
class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
4242

43+
import SparkConf._
44+
4345
/** Create a SparkConf that loads defaults from system properties and the classpath */
4446
def this() = this(true)
4547

@@ -198,7 +200,7 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
198200
*
199201
* E.g. spark.akka.option.x.y.x = "value"
200202
*/
201-
getAll.filter {case (k, v) => k.startsWith("akka.")}
203+
getAll.filter { case (k, _) => isAkkaConf(k) }
202204

203205
/** Does the configuration contain a given parameter? */
204206
def contains(key: String): Boolean = settings.contains(key)
@@ -292,3 +294,22 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
292294
settings.toArray.sorted.map{case (k, v) => k + "=" + v}.mkString("\n")
293295
}
294296
}
297+
298+
private[spark] object SparkConf {
299+
/**
300+
* Return whether the given config is an akka config (e.g. akka.actor.provider).
301+
* Note that this does not include spark-specific akka configs (e.g. spark.akka.timeout).
302+
*/
303+
def isAkkaConf(name: String): Boolean = name.startsWith("akka.")
304+
305+
/**
306+
* Return whether the given config should be passed to an executor on start-up.
307+
*
308+
* When connecting to the scheduler, the executor backend needs certain akka and authentication
309+
* settings to connect to the scheduler, while the rest of the spark configs can be inherited
310+
* from the driver later.
311+
*/
312+
def isExecutorStartupConf(name: String): Boolean = {
313+
isAkkaConf(name) || name.startsWith("spark.akka") || name.startsWith("spark.auth")
314+
}
315+
}

core/src/main/scala/org/apache/spark/scheduler/cluster/SparkDeploySchedulerBackend.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.scheduler.cluster
1919

20-
import org.apache.spark.{Logging, SparkContext}
20+
import org.apache.spark.{Logging, SparkConf, SparkContext}
2121
import org.apache.spark.deploy.{ApplicationDescription, Command}
2222
import org.apache.spark.deploy.client.{AppClient, AppClientListener}
2323
import org.apache.spark.scheduler.{ExecutorExited, ExecutorLossReason, SlaveLost, TaskSchedulerImpl}
@@ -55,9 +55,7 @@ private[spark] class SparkDeploySchedulerBackend(
5555
}
5656

5757
// Start executors with a few necessary configs for registering with the scheduler
58-
val sparkJavaOpts = Utils.sparkJavaOpts(conf, (key: String) =>
59-
key.startsWith("spark.akka") || key.startsWith("spark.auth")
60-
)
58+
val sparkJavaOpts = Utils.sparkJavaOpts(conf, SparkConf.isExecutorStartupConf)
6159
val javaOpts = sparkJavaOpts ++ extraJavaOpts
6260
val command = Command("org.apache.spark.executor.CoarseGrainedExecutorBackend",
6361
args, sc.executorEnvs, classPathEntries, libraryPathEntries, javaOpts)

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/ClientBase.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ import org.apache.hadoop.yarn.api.protocolrecords._
3737
import org.apache.hadoop.yarn.api.records._
3838
import org.apache.hadoop.yarn.conf.YarnConfiguration
3939
import org.apache.hadoop.yarn.util.Records
40+
4041
import org.apache.spark.{SparkException, Logging, SparkConf, SparkContext}
42+
import org.apache.spark.util.Utils
4143

4244
/**
4345
* The entry point (starting in Client#main() and Client#run()) for launching Spark on YARN. The
@@ -383,9 +385,7 @@ trait ClientBase extends Logging {
383385
// Forward the Spark configuration to the application master / executors.
384386
// TODO: it might be nicer to pass these as an internal environment variable rather than
385387
// as Java options, due to complications with string parsing of nested quotes.
386-
for ((k, v) <- sparkConf.getAll) {
387-
javaOpts += "-D" + k + "=" + "\\\"" + v + "\\\""
388-
}
388+
javaOpts ++= Utils.sparkJavaOpts(sparkConf)
389389

390390
if (args.amClass == classOf[ApplicationMaster].getName) {
391391
sparkConf.getOption("spark.driver.extraJavaOptions")

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnableUtil.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration
3131
import org.apache.hadoop.yarn.util.{ConverterUtils, Records}
3232

3333
import org.apache.spark.{Logging, SparkConf}
34+
import org.apache.spark.util.Utils
3435

3536
trait ExecutorRunnableUtil extends Logging {
3637

@@ -66,12 +67,7 @@ trait ExecutorRunnableUtil extends Logging {
6667
// registers with the Scheduler and transfers the spark configs. Since the Executor backend
6768
// uses Akka to connect to the scheduler, the akka settings are needed as well as the
6869
// authentication settings.
69-
sparkConf.getAll.
70-
filter { case (k, v) => k.startsWith("spark.auth") || k.startsWith("spark.akka") }.
71-
foreach { case (k, v) => javaOpts += "-D" + k + "=" + "\\\"" + v + "\\\"" }
72-
73-
sparkConf.getAkkaConf.
74-
foreach { case (k, v) => javaOpts += "-D" + k + "=" + "\\\"" + v + "\\\"" }
70+
javaOpts ++= Utils.sparkJavaOpts(sparkConf, SparkConf.isExecutorStartupConf)
7571

7672
// Commenting it out for now - so that people can refer to the properties if required. Remove
7773
// it once cpuset version is pushed out.

0 commit comments

Comments
 (0)