Skip to content

Commit 186b497

Browse files
aarondavandrewor14
authored andcommitted
[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. Author: Aaron Davidson <[email protected]> Closes #2779 from aarondav/fix-standalone and squashes the following commits: 725227a [Aaron Davidson] Fix ExecutorRunnerTest 9d703fe [Aaron Davidson] [SPARK-3921] Fix CoarseGrainedExecutorBackend's arguments for Standalone mode
1 parent 4d26aca commit 186b497

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
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()

core/src/test/scala/org/apache/spark/deploy/worker/ExecutorRunnerTest.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ import org.apache.spark.SparkConf
2626

2727
class ExecutorRunnerTest extends FunSuite {
2828
test("command includes appId") {
29-
def f(s:String) = new File(s)
29+
val appId = "12345-worker321-9876"
3030
val sparkHome = sys.props.getOrElse("spark.test.home", fail("spark.test.home is not set!"))
3131
val appDesc = new ApplicationDescription("app name", Some(8), 500,
32-
Command("foo", Seq(), Map(), Seq(), Seq(), Seq()), "appUiUrl")
33-
val appId = "12345-worker321-9876"
34-
val er = new ExecutorRunner(appId, 1, appDesc, 8, 500, null, "blah", "worker321", f(sparkHome),
35-
f("ooga"), "blah", new SparkConf, ExecutorState.RUNNING)
36-
32+
Command("foo", Seq(appId), Map(), Seq(), Seq(), Seq()), "appUiUrl")
33+
val er = new ExecutorRunner(appId, 1, appDesc, 8, 500, null, "blah", "worker321",
34+
new File(sparkHome), new File("ooga"), "blah", new SparkConf, ExecutorState.RUNNING)
3735
assert(er.getCommandSeq.last === appId)
3836
}
3937
}

0 commit comments

Comments
 (0)