Skip to content

Commit afc9ed8

Browse files
committed
Cleaning up line limits and two compile errors.
1 parent b08893b commit afc9ed8

File tree

9 files changed

+91
-25
lines changed

9 files changed

+91
-25
lines changed

conf/spark-env.sh.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
# - SPARK_MASTER_PORT / SPARK_MASTER_WEBUI_PORT, to use non-default ports
3333
# - SPARK_MASTER_OPTS, to set config properties only for the master (e.g. "-Dx=y")
3434
# - SPARK_WORKER_CORES, to set the number of cores to use on this machine
35-
# - SPARK_WORKER_MEMORY, to set how much total memory to workers have to give executors (e.g. 1000m, 2g)
35+
# - SPARK_WORKER_MEMORY, to set how much total memory workers have to give executors (e.g. 1000m, 2g)
3636
# - SPARK_WORKER_PORT / SPARK_WORKER_WEBUI_PORT
3737
# - SPARK_WORKER_INSTANCES, to set the number of worker processes per node
3838
# - SPARK_WORKER_DIR, to set the working directory of worker processes
3939
# - SPARK_WORKER_OPTS, to set config properties only for the worker (e.g. "-Dx=y")
4040
# - SPARK_HISTORY_OPTS, to set config properties only for the history server (e.g. "-Dx=y")
4141
# - SPARK_DAEMON_OPTS, to set config properties for all daemons (e.g. "-Dx=y")
42-
# - SPARK_PUBLIC_DNS, to set the public dns name of the master or workers
42+
# - SPARK_PUBLIC_DNS, to set the public dns name of the master or workers

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

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
5252
}
5353
}
5454

55-
validateSettings()
56-
5755
/** Set a configuration variable. */
5856
def set(key: String, value: String): SparkConf = {
5957
if (key == null) {
@@ -210,25 +208,79 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
210208
new SparkConf(false).setAll(settings)
211209
}
212210

213-
/** Checks for illegal or deprecated config settings. Throws an exception for the former. */
214-
private def validateSettings() {
211+
/** Checks for illegal or deprecated config settings. Throws an exception for the former. Not
212+
* idempotent - may mutate this conf object to convert deprecated settings to supported ones. */
213+
private[spark] def validateSettings() {
215214
if (settings.contains("spark.local.dir")) {
216215
val msg = "In Spark 1.0 and later spark.local.dir will be overridden by the value set by " +
217216
"the cluster manager (via SPARK_LOCAL_DIRS in mesos/standalone and LOCAL_DIRS in YARN)."
218217
logWarning(msg)
219218
}
219+
220220
val executorOptsKey = "spark.executor.extraJavaOptions"
221+
val executorClasspathKey = "spark.executor.extraClassPath"
222+
val driverOptsKey = "spark.driver.extraJavaOptions"
223+
val driverClassPathKey = "spark.driver.extraClassPath"
224+
225+
// Validate spark.executor.extraJavaOptions
221226
settings.get(executorOptsKey).map { javaOpts =>
222227
if (javaOpts.contains("-Dspark")) {
223228
val msg = s"$executorOptsKey is not allowed to set Spark options. Was '$javaOpts'"
224229
throw new Exception(msg)
225230
}
226231
if (javaOpts.contains("-Xmx") || javaOpts.contains("-Xms")) {
227-
val msg = s"$executorOptsKey is not allowed to alter memory settings (was '$javaOpts'). Use " +
228-
"spark.executor.memory instead."
232+
val msg = s"$executorOptsKey is not allowed to alter memory settings (was '$javaOpts'). " +
233+
"Use spark.executor.memory instead."
229234
throw new Exception(msg)
230235
}
231236
}
237+
238+
// Check for legacy configs
239+
sys.env.get("SPARK_JAVA_OPTS").foreach { value =>
240+
val error =
241+
s"""
242+
|SPARK_JAVA_OPTS was detected (set to '$value').
243+
|This has undefined behavior when running on a cluster and is deprecated in Spark 1.0+.
244+
|
245+
|Please instead use:
246+
| - ./spark-submit with conf/spark-defaults.conf to set properties for an application
247+
| - ./spark-submit with --driver-java-options to set -X options for a driver
248+
| - spark.executor.executor.extraJavaOptions to set -X options for executors
249+
| - SPARK_DAEMON_OPTS to set java options for standalone daemons (i.e. master, worker)
250+
""".stripMargin
251+
logError(error)
252+
253+
for (key <- Seq(executorOptsKey, driverOptsKey)) {
254+
if (getOption(key).isDefined) {
255+
throw new SparkException(s"Found both $key and SPARK_JAVA_OPTS. Use only the former.")
256+
} else {
257+
logWarning(s"Setting '$key' to '$value' as a work-around.")
258+
set(key, value)
259+
}
260+
}
261+
}
262+
263+
sys.env.get("SPARK_CLASSPATH").foreach { value =>
264+
val error =
265+
s"""
266+
|SPARK_CLASSPATH was detected (set to '$value').
267+
| This has undefined behavior when running on a cluster and is deprecated in Spark 1.0+.
268+
|
269+
|Please instead use:
270+
| - ./spark-submit with --driver-class-path to augment the driver classpath
271+
| - spark.executor.executor.extraClassPath to augment the executor classpath
272+
""".stripMargin
273+
logError(error)
274+
275+
for (key <- Seq(executorClasspathKey, driverClassPathKey)) {
276+
if (getOption(key).isDefined) {
277+
throw new SparkException(s"Found both $key and SPARK_CLASSPATH. Use only the former.")
278+
} else {
279+
logWarning(s"Setting '$key' to '$value' as a work-around.")
280+
set(key, value)
281+
}
282+
}
283+
}
232284
}
233285

234286
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class SparkContext(config: SparkConf) extends Logging {
147147
this(master, appName, sparkHome, jars, Map(), Map())
148148

149149
private[spark] val conf = config.clone()
150+
conf.validateSettings()
150151

151152
/**
152153
* Return a copy of this SparkContext's configuration. The configuration ''cannot'' be

core/src/main/scala/org/apache/spark/deploy/Client.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ private class ClientActor(driverArgs: ClientArguments, conf: SparkConf) extends
5454
System.getenv().foreach{case (k, v) => env(k) = v}
5555

5656
val mainClass = "org.apache.spark.deploy.worker.DriverWrapper"
57-
val classPathEntries = sys.props.get("spark.driver.extraClassPath").toSeq.flatMap { cp =>
57+
58+
val classPathConf = "spark.driver.extraClassPath"
59+
val classPathEntries = sys.props.get(classPathConf).toSeq.flatMap { cp =>
5860
cp.split(java.io.File.pathSeparator)
5961
}
60-
val libraryPathEntries = sys.props.get("spark.driver.extraLibraryPath").toSeq.flatMap { cp =>
62+
63+
val libraryPathConf = "spark.driver.extraLibraryPath"
64+
val libraryPathEntries = sys.props.get(libraryPathConf).toSeq.flatMap { cp =>
6165
cp.split(java.io.File.pathSeparator)
6266
}
63-
val javaOpts = sys.props.get("spark.driver.extraJavaOptions")
67+
68+
val javaOptionsConf = "spark.driver.extraJavaOptions"
69+
val javaOpts = sys.props.get(javaOptionsConf)
6470
val command = new Command(mainClass, Seq("{{WORKER_URL}}", driverArgs.mainClass) ++
6571
driverArgs.driverOptions, env, classPathEntries, libraryPathEntries, javaOpts)
6672

core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ object SparkSubmit {
146146
new OptionAssigner(appArgs.driverExtraClassPath, STANDALONE | YARN, true,
147147
sysProp = "spark.driver.extraClassPath"),
148148
new OptionAssigner(appArgs.driverExtraJavaOptions, STANDALONE | YARN, true,
149-
sysProp = "spark.driver.extraJavaOptions"),
149+
sysProp = "spark.driver.extraJavaOpts"),
150150
new OptionAssigner(appArgs.driverExtraLibraryPath, STANDALONE | YARN, true,
151151
sysProp = "spark.driver.extraLibraryPath"),
152152

@@ -259,7 +259,9 @@ object SparkSubmit {
259259
try {
260260
properties.load(inputStream)
261261
} catch {
262-
case e: IOException => throw new SparkException(s"Failed when loading Spark properties file ${file.getName}", e)
262+
case e: IOException =>
263+
val message = s"Failed when loading Spark properties file ${file.getName}"
264+
throw new SparkException(message, e)
263265
}
264266
properties.stringPropertyNames().toSeq.map(k => (k, properties(k)))
265267
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,13 @@ private[spark] class CoarseMesosSchedulerBackend(
113113
val environment = Environment.newBuilder()
114114
val extraClassPath = conf.getOption("spark.executor.extraClassPath")
115115
extraClassPath.foreach { cp =>
116-
envrionment.addVariables(Environment.Variable.newBuilder().setName("SPARK_CLASSPATH").setValue(cp).build())
116+
environment.addVariables(
117+
Environment.Variable.newBuilder().setName("SPARK_CLASSPATH").setValue(cp).build())
117118
}
118-
val extraJavaOpts = conf.getOption("spark.executor.extraJavaOptions", "")
119-
val extraLibraryPath = conf.getOption("spark.executor.extraLibraryPath").map(p => s"-Djava.library.path=$p")
119+
val extraJavaOpts = conf.getOption("spark.executor.extraJavaOptions")
120+
121+
val libraryPathOption = "spark.executor.extraLibraryPath"
122+
val extraLibraryPath = conf.getOption(libraryPathOption).map(p => s"-Djava.library.path=$p")
120123
val extraOpts = Seq(extraJavaOpts, extraLibraryPath).flatten.mkString(" ")
121124

122125
sc.testExecutorEnvs.foreach { case (key, value) =>

docs/configuration.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ Apart from these, the following properties are also available, and may be useful
652652
<td>
653653
A string of extra JVM options to pass to executors. For instance, GC settings or other
654654
logging. Note that it is illegal to set Spark properties or heap size settings with this
655-
option.
655+
option. Spark properties should be set using a SparkConf object or the
656+
spark-defaults.conf file used with the spark-submit script. Heap size settings can be set
657+
with spark.executor.memory.
656658
</td>
657659
</tr>
658660
<tr>
@@ -694,9 +696,6 @@ The following variables can be set in `spark-env.sh`:
694696
* `JAVA_HOME`, the location where Java is installed (if it's not on your default `PATH`)
695697
* `PYSPARK_PYTHON`, the Python binary to use for PySpark
696698
* `SPARK_LOCAL_IP`, to configure which IP address of the machine to bind to.
697-
* `SPARK_CLASSPATH`, to add elements to Spark's classpath that you want to be present for _all_ applications.
698-
Note that applications can also add dependencies for themselves through `SparkContext.addJar` -- we recommend
699-
doing that when possible.
700699
* `SPARK_PUBLIC_DNS`, the hostname your Spark program will advertise to other machines.
701700
* Options for the Spark [standalone cluster scripts](spark-standalone.html#cluster-launch-scripts), such as number of cores
702701
to use on each machine and maximum memory.

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ import org.apache.spark.{Logging, SparkConf}
4242
* Client submits an application to the YARN ResourceManager.
4343
*
4444
* Depending on the deployment mode this will launch one of two application master classes:
45-
* 1. In standalone mode, it will launch an [[org.apache.spark.deploy.yarn.ApplicationMaster]] which embeds a driver.
46-
* 2. In client mode, it will launch an [[org.apache.spark.deploy.yarn.ExecutorLauncher]].
45+
* 1. In standalone mode, it will launch an [[org.apache.spark.deploy.yarn.ApplicationMaster]]
46+
* which launches a driver program inside of the cluster.
47+
* 2. In client mode, it will launch an [[org.apache.spark.deploy.yarn.ExecutorLauncher]] to
48+
* request executors on behalf of a driver running outside of the cluster.
4749
*/
4850
trait ClientBase extends Logging {
4951
val args: ClientArguments
@@ -263,7 +265,8 @@ trait ClientBase extends Logging {
263265
val env = new HashMap[String, String]()
264266

265267
val extraCp = sparkConf.getOption("spark.driver.extraClassPath")
266-
ClientBase.populateClasspath(yarnConf, sparkConf, localResources.contains(ClientBase.LOG4J_PROP), env, extraCp)
268+
ClientBase.populateClasspath(yarnConf, sparkConf,
269+
localResources.contains(ClientBase.LOG4J_PROP), env, extraCp)
267270
env("SPARK_YARN_MODE") = "true"
268271
env("SPARK_YARN_STAGING_DIR") = stagingDir
269272
env("SPARK_USER") = UserGroupInformation.getCurrentUser().getShortUserName()
@@ -342,7 +345,6 @@ trait ClientBase extends Logging {
342345
for ((k, v) <- sys.props.filterKeys(_.startsWith("spark"))) {
343346
JAVA_OPTS += s"-D$k=$v"
344347
}
345-
// TODO: honor driver classpath here: sys.props.get("spark.driver.classPath")
346348
sys.props.get("spark.driver.extraJavaOptions").foreach(opts => JAVA_OPTS += opts)
347349
sys.props.get("spark.driver.libraryPath").foreach(p => JAVA_OPTS += s"-Djava.library.path=$p")
348350
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ trait ExecutorRunnableUtil extends Logging {
159159
val env = new HashMap[String, String]()
160160

161161
val extraCp = sparkConf.getOption("spark.executor.extraClassPath")
162-
ClientBase.populateClasspath(yarnConf, sparkConf, System.getenv("SPARK_YARN_LOG4J_PATH") != null, env, extraCp)
162+
ClientBase.populateClasspath(yarnConf, sparkConf,
163+
System.getenv("SPARK_YARN_LOG4J_PATH") != null, env, extraCp)
163164

164165
// Allow users to specify some environment variables
165166
Apps.setEnvFromInputString(env, System.getenv("SPARK_YARN_USER_ENV"))

0 commit comments

Comments
 (0)