Github user kayousterhout commented on a diff in the pull request:
https://github.com/apache/spark/pull/6750#discussion_r34860791
--- Diff:
core/src/test/scala/org/apache/spark/scheduler/TaskSchedulerImplSuite.scala ---
@@ -128,4 +128,113 @@ class TaskSchedulerImplSuite extends SparkFunSuite
with LocalSparkContext with L
assert(taskDescriptions.map(_.executorId) === Seq("executor0"))
}
+ test("refuse to schedule concurrent attempts for the same stage
(SPARK-8103)") {
+ sc = new SparkContext("local", "TaskSchedulerImplSuite")
+ val taskScheduler = new TaskSchedulerImpl(sc)
+ taskScheduler.initialize(new FakeSchedulerBackend)
+ // Need to initialize a DAGScheduler for the taskScheduler to use for
callbacks.
+ val dagScheduler = new DAGScheduler(sc, taskScheduler) {
+ override def taskStarted(task: Task[_], taskInfo: TaskInfo) {}
+ override def executorAdded(execId: String, host: String) {}
+ }
+ taskScheduler.setDAGScheduler(dagScheduler)
+ val attempt1 = FakeTask.createTaskSet(1, 0)
+ val attempt2 = FakeTask.createTaskSet(1, 1)
+ taskScheduler.submitTasks(attempt1)
+ intercept[IllegalStateException] { taskScheduler.submitTasks(attempt2)
}
+
+ // OK to submit multiple if previous attempts are all zombie
+ taskScheduler.taskSetManagerForAttempt(attempt1.stageId,
attempt1.stageAttemptId)
+ .get.isZombie = true
+ taskScheduler.submitTasks(attempt2)
+ val attempt3 = FakeTask.createTaskSet(1, 2)
+ intercept[IllegalStateException] { taskScheduler.submitTasks(attempt3)
}
+ taskScheduler.taskSetManagerForAttempt(attempt2.stageId,
attempt2.stageAttemptId)
+ .get.isZombie = true
+ taskScheduler.submitTasks(attempt3)
+ }
+
+ test("don't schedule more tasks after a taskset is zombie") {
+ sc = new SparkContext("local", "TaskSchedulerImplSuite")
+ val taskScheduler = new TaskSchedulerImpl(sc)
+ taskScheduler.initialize(new FakeSchedulerBackend)
+ // Need to initialize a DAGScheduler for the taskScheduler to use for
callbacks.
+ new DAGScheduler(sc, taskScheduler) {
+ override def taskStarted(task: Task[_], taskInfo: TaskInfo) {}
+ override def executorAdded(execId: String, host: String) {}
+ }
+
+ val numFreeCores = 1
+ val workerOffers = Seq(new WorkerOffer("executor0", "host0",
numFreeCores))
+ val attempt1 = FakeTask.createTaskSet(10)
+
+ // submit attempt 1, offer some resources, some tasks get scheduled
+ taskScheduler.submitTasks(attempt1)
+ val taskDescriptions =
taskScheduler.resourceOffers(workerOffers).flatten
+ assert(1 === taskDescriptions.length)
+
+ // now mark attempt 1 as a zombie
+ taskScheduler.taskSetManagerForAttempt(attempt1.stageId,
attempt1.stageAttemptId)
+ .get.isZombie = true
+
+ // don't schedule anything on another resource offer
+ val taskDescriptions2 =
taskScheduler.resourceOffers(workerOffers).flatten
+ assert(0 === taskDescriptions2.length)
+
+ // if we schedule another attempt for the same stage, it should get
scheduled
+ val attempt2 = FakeTask.createTaskSet(10, 1)
+
+ // submit attempt 2, offer some resources, some tasks get scheduled
+ taskScheduler.submitTasks(attempt2)
+ val taskDescriptions3 =
taskScheduler.resourceOffers(workerOffers).flatten
+ assert(1 === taskDescriptions3.length)
+ val mgr =
taskScheduler.taskSetManagerForTask(taskDescriptions3(0).taskId).get
+ assert(mgr.taskSet.stageAttemptId === 1)
+ }
+
+ test("if a zombie attempt finishes, continue scheduling tasks for
non-zombie attempts") {
+ sc = new SparkContext("local", "TaskSchedulerImplSuite")
+ val taskScheduler = new TaskSchedulerImpl(sc)
+ taskScheduler.initialize(new FakeSchedulerBackend)
+ // Need to initialize a DAGScheduler for the taskScheduler to use for
callbacks.
+ new DAGScheduler(sc, taskScheduler) {
+ override def taskStarted(task: Task[_], taskInfo: TaskInfo) {}
+ override def executorAdded(execId: String, host: String) {}
+ }
+
+ val numFreeCores = 10
+ val workerOffers = Seq(new WorkerOffer("executor0", "host0",
numFreeCores))
+ val attempt1 = FakeTask.createTaskSet(10)
+
+ // submit attempt 1, offer some resources, some tasks get scheduled
+ taskScheduler.submitTasks(attempt1)
+ val taskDescriptions =
taskScheduler.resourceOffers(workerOffers).flatten
+ assert(10 === taskDescriptions.length)
+
+ // now mark attempt 1 as a zombie
+ val mgr1 = taskScheduler.taskSetManagerForAttempt(attempt1.stageId,
attempt1.stageAttemptId).get
+ mgr1.isZombie = true
+
+ // don't schedule anything on another resource offer
+ val taskDescriptions2 =
taskScheduler.resourceOffers(workerOffers).flatten
+ assert(0 === taskDescriptions2.length)
+
+ // submit attempt 2
+ val attempt2 = FakeTask.createTaskSet(10, 1)
+ taskScheduler.submitTasks(attempt2)
+
+ // attempt 1 finished (this can happen even if it was marked zombie
earlier -- all tasks were
+ // already submitted, and then they finish)
+ taskScheduler.taskSetFinished(mgr1)
+
+ // now with another resource offer, we should still schedule all the
tasks in attempt2
+ val taskDescriptions3 =
taskScheduler.resourceOffers(workerOffers).flatten
+ assert(10 === taskDescriptions3.length)
+
+ taskDescriptions3.foreach{ task =>
--- End diff --
super nit: space before "{"
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]