Skip to content

Commit 9d703fe

Browse files
committed
[SPARK-3921] Fix CoarseGrainedExecutorBackend's arguments for Standalone mode
The goal of this patch is to fix the swapped arguments in standalone mode, which was caused by 79e45c9#diff-79391110e9f26657e415aa169a004998R153. More details can be found in the JIRA: [SPARK-3921](https://issues.apache.org/jira/browse/SPARK-3921) Tested in Standalone mode, but not in Mesos.
1 parent d8b8c21 commit 9d703fe

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

core/src/main/scala/org/apache/spark/deploy/worker/ExecutorRunner.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ private[spark] class ExecutorRunner(
111111
case "{{EXECUTOR_ID}}" => execId.toString
112112
case "{{HOSTNAME}}" => host
113113
case "{{CORES}}" => cores.toString
114+
case "{{APP_ID}}" => appId
114115
case other => other
115116
}
116117

117118
def getCommandSeq = {
118119
val command = Command(
119120
appDesc.command.mainClass,
120-
appDesc.command.arguments.map(substituteVariables) ++ Seq(appId),
121+
appDesc.command.arguments.map(substituteVariables),
121122
appDesc.command.environment,
122123
appDesc.command.classPathEntries,
123124
appDesc.command.libraryPathEntries,

core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
152152
"Usage: CoarseGrainedExecutorBackend <driverUrl> <executorId> <hostname> " +
153153
"<cores> <appid> [<workerUrl>] ")
154154
System.exit(1)
155+
156+
// NB: These arguments are provided by SparkDeploySchedulerBackend (for standalone mode)
157+
// and CoarseMesosSchedulerBackend (for mesos mode).
155158
case 5 =>
156159
run(args(0), args(1), args(2), args(3).toInt, args(4), None)
157160
case x if x > 5 =>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private[spark] class SparkDeploySchedulerBackend(
5151
conf.get("spark.driver.host"),
5252
conf.get("spark.driver.port"),
5353
CoarseGrainedSchedulerBackend.ACTOR_NAME)
54-
val args = Seq(driverUrl, "{{EXECUTOR_ID}}", "{{HOSTNAME}}", "{{CORES}}", "{{WORKER_URL}}")
54+
val args = Seq(driverUrl, "{{EXECUTOR_ID}}", "{{HOSTNAME}}", "{{CORES}}", "{{APP_ID}}",
55+
"{{WORKER_URL}}")
5556
val extraJavaOpts = sc.conf.getOption("spark.executor.extraJavaOptions")
5657
.map(Utils.splitCommandString).getOrElse(Seq.empty)
5758
val classPathEntries = sc.conf.getOption("spark.executor.extraClassPath").toSeq.flatMap { cp =>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ private[spark] class CoarseMesosSchedulerBackend(
150150
if (uri == null) {
151151
val runScript = new File(executorSparkHome, "./bin/spark-class").getCanonicalPath
152152
command.setValue(
153-
"\"%s\" org.apache.spark.executor.CoarseGrainedExecutorBackend %s %s %s %d".format(
154-
runScript, driverUrl, offer.getSlaveId.getValue, offer.getHostname, numCores))
153+
"\"%s\" org.apache.spark.executor.CoarseGrainedExecutorBackend %s %s %s %d %s".format(
154+
runScript, driverUrl, offer.getSlaveId.getValue, offer.getHostname, numCores, appId))
155155
} else {
156156
// Grab everything to the first '.'. We'll use that and '*' to
157157
// glob the directory "correctly".
158158
val basename = uri.split('/').last.split('.').head
159159
command.setValue(
160160
("cd %s*; " +
161-
"./bin/spark-class org.apache.spark.executor.CoarseGrainedExecutorBackend %s %s %s %d")
161+
"./bin/spark-class org.apache.spark.executor.CoarseGrainedExecutorBackend %s %s %s %d %s")
162162
.format(basename, driverUrl, offer.getSlaveId.getValue,
163-
offer.getHostname, numCores))
163+
offer.getHostname, numCores, appId))
164164
command.addUris(CommandInfo.URI.newBuilder().setValue(uri))
165165
}
166166
command.build()

0 commit comments

Comments
 (0)