Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/5636#discussion_r35720546
--- Diff:
core/src/test/scala/org/apache/spark/scheduler/DAGSchedulerSuite.scala ---
@@ -473,6 +473,322 @@ class DAGSchedulerSuite
assertDataStructuresEmpty()
}
+ // Helper function to validate state when creating tests for task
failures
+ def checkStageId(stageId: Int, attempt: Int, stageAttempt: TaskSet) {
+ assert(stageAttempt.stageId === stageId)
+ assert(stageAttempt.stageAttemptId == attempt)
+ }
+
+ def makeCompletions(stageAttempt: TaskSet): Seq[(Success.type,
MapStatus)] = {
+ stageAttempt.tasks.zipWithIndex.map { case (task, idx) =>
+ (Success, makeMapStatus("host" + ('A' + idx).toChar,
stageAttempt.tasks.size))
+ }.toSeq
+ }
+
+ /**
+ * In this test we simulate a job failure where the first stage
completes successfully and
+ * the second stage fails due to a fetch failure. Multiple successive
fetch failures of a stage
+ * trigger an overall stage abort to avoid endless retries.
+ */
+ test("Multiple consecutive stage failures should lead to task being
aborted.") {
+ // Create a new Listener to confirm that the listenerBus sees the
JobEnd message
+ // when we abort the stage. This message will also be consumed by the
EventLoggingListener
+ // so this will propagate up to the user.
+ var ended = false
+ var jobResult : JobResult = null
+ class EndListener extends SparkListener {
+ override def onJobEnd(jobEnd: SparkListenerJobEnd): Unit = {
+ jobResult = jobEnd.jobResult
+ ended = true
+ }
+ }
+
+ sc.listenerBus.addListener(new EndListener())
+
+ val shuffleMapRdd = new MyRDD(sc, 2, Nil)
+ val shuffleDep = new ShuffleDependency(shuffleMapRdd, null)
+ val shuffleId = shuffleDep.shuffleId
+ val reduceRdd = new MyRDD(sc, 2, List(shuffleDep))
+ submit(reduceRdd, Array(0, 1))
+
+ for (attempt <- 0 until Stage.MAX_STAGE_FAILURES) {
+ // Complete all the tasks for the current attempt of stage 0
successfully
+ val stage0Attempt = taskSets.last
+
+ // Confirm that this is the next attempt for stage 0
+ checkStageId(0, attempt, stage0Attempt)
+
+ // Make each task in stage 0 success
+ val completions = makeCompletions(stage0Attempt)
+
+ // Run stage 0
+ complete(stage0Attempt, completions)
+
+ // Now we should have a new taskSet, for a new attempt of stage 1.
+ // We will have one fetch failure for this task set
+ val stage1Attempt = taskSets.last
+ checkStageId(1, attempt, stage1Attempt)
+
+ val stage1Successes = stage1Attempt.tasks.tail.map { _ => (Success,
42)}
+
+ // Run Stage 1, this time with a task failure
+ complete(stage1Attempt,
+ Seq((FetchFailed(makeBlockManagerId("hostA"), shuffleId, 0, 0,
"ignored"), null))
+ ++ stage1Successes
+ )
+
+ // this will (potentially) trigger a resubmission of stage 0, since
we've lost some of its
+ // map output, for the next iteration through the loop
+ scheduler.resubmitFailedStages()
+
+ if (attempt < Stage.MAX_STAGE_FAILURES-1) {
+ assert(scheduler.runningStages.nonEmpty)
+ assert(!ended)
+ } else {
+ // Stage has been aborted and removed from running stages
+ assertDataStructuresEmpty()
+ sc.listenerBus.waitUntilEmpty(1000)
+ assert(ended)
+ assert(jobResult.isInstanceOf[JobFailed])
+ }
+ }
+ }
+
+ /**
+ * In this test we simulate a job failure where there are two failures
in two different stages.
+ * Specifically, stage0 fails twice, and then stage1 twice. In total,
the job has had four
+ * failures overall but not four failures for a particular stage, and as
such should not be
+ * aborted.
+ */
+ test("Failures in different stages should not trigger an overall abort")
{
+ val shuffleMapRdd = new MyRDD(sc, 2, Nil)
+ val shuffleDep = new ShuffleDependency(shuffleMapRdd, null)
+ val shuffleId = shuffleDep.shuffleId
+ val reduceRdd = new MyRDD(sc, 2, List(shuffleDep))
+ submit(reduceRdd, Array(0, 1))
+
+ // In the first two iterations, Stage 0 succeeds and stage 1 fails. In
the next two iterations,
+ // stage 0 fails.
+ for (attempt <- 0 until Stage.MAX_STAGE_FAILURES) {
+ // Complete all the tasks for the current attempt of stage 0
successfully
+ val stage0Attempt = taskSets.last
+
+ // Confirm that this is the next attempt for stage 0
+ checkStageId(0, attempt, stage0Attempt)
+
+ if (attempt < Stage.MAX_STAGE_FAILURES/2) {
+ // Make each task in stage 0 success
+ val completions = makeCompletions(stage0Attempt)
+
+ // Run stage 0
+ complete(stage0Attempt, completions)
+
+ // Now we should have a new taskSet, for a new attempt of stage 1.
+ // We will have one fetch failure for this task set
+ val stage1Attempt = taskSets.last
+ checkStageId(1, attempt, stage1Attempt)
+
+ val stage1Successes = stage1Attempt.tasks.tail.map { _ =>
(Success, 42)}
+
+ // Run Stage 1, this time with a task failure
+ complete(stage1Attempt,
+ Seq((FetchFailed(makeBlockManagerId("hostA"), shuffleId, 0, 0,
"ignored"), null))
+ ++ stage1Successes
+ )
+ } else {
+ val stage0Successes = stage0Attempt.tasks.tail.map { _ =>
(Success, 42)}
+
+ // Run stage 0 and fail
+ complete(stage0Attempt,
+ Seq((FetchFailed(makeBlockManagerId("hostA"), shuffleId, 0, 0,
"ignored"), null))
+ ++ stage0Successes
+ )
+ }
+
+ // this will (potentially) trigger a resubmission of stage 0, since
we've lost some of its
+ // map output, for the next iteration through the loop
+ scheduler.resubmitFailedStages()
+ }
+
+ val stage0Attempt = taskSets.last
+ val completions = stage0Attempt.tasks.zipWithIndex.map{ case (task,
idx) =>
+ (Success, makeMapStatus("host" + ('A' + idx).toChar, 2))
+ }.toSeq
+
+ // Complete first task
+ complete(taskSets.last, completions)
+
+ // Complete second task
+ complete(taskSets.last, Seq((Success, 42)))
+
+ // The first success is from the success we append in stage 1, the
second is the one we add here
+ assert(results === Map(1 -> 42, 0 -> 42))
+ }
+
+ /**
+ * In this test we simulate a job failure where a stage may have many
tasks, many of which fail.
+ * We want to show that many fetch failures inside a single stage do not
trigger an abort on
+ * their own, but only when the stage fails enough times.
+ */
+ test("Multiple task failures in same stage should not abort the stage.")
{
+ // Create a new Listener to confirm that the listenerBus sees the
JobEnd message
+ // when we abort the stage. This message will also be consumed by the
EventLoggingListener
+ // so this will propagate up to the user.
+ var ended = false
+ var jobResult : JobResult = null
+ class EndListener extends SparkListener {
+ override def onJobEnd(jobEnd: SparkListenerJobEnd): Unit = {
+ jobResult = jobEnd.jobResult
+ ended = true
+ }
+ }
+
+ sc.listenerBus.addListener(new EndListener())
+
+ val parts = 8
+ val shuffleMapRdd = new MyRDD(sc, parts, Nil)
+ val shuffleDep = new ShuffleDependency(shuffleMapRdd, null)
+ val shuffleId = shuffleDep.shuffleId
+ val reduceRdd = new MyRDD(sc, parts, List(shuffleDep))
+ submit(reduceRdd, (0 until parts).toArray)
+
+ val stage0Attempt = taskSets.last
+
+ // Make each task in stage 0 success, then fail all of stage 1
+ val completions = makeCompletions(stage0Attempt)
+ complete(stage0Attempt, completions)
+
+ val stage1Attempt = taskSets.last
+ val failures = stage1Attempt.tasks.zipWithIndex.map{ case (task, idx)
=>
+ (FetchFailed(makeBlockManagerId("hostA"), shuffleId, 0, idx,
"ignored"), null)
+ }.toSeq
+
+ // Run Stage 1, this time with all fetchs failing
+ complete(stage1Attempt, failures)
+
+ // Resubmit and confirm that now all is well
+ scheduler.resubmitFailedStages()
+
+ assert(scheduler.runningStages.nonEmpty)
+ assert(!ended)
+
+ // Confirm job finished succesfully
+ val stage1Attempt2 = taskSets.last
+ val completions_1_2 = stage1Attempt2.tasks.zipWithIndex.map(_ =>
(Success, 42)).toSeq
--- End diff --
the issue here is that you've actually got to first finish another attempt
for stage 0.
Maybe I should back up a bit and explain what is going on at a higher level
with these fetch failures and retries. When stage 1 fails with a fetch
failure, spark is basically assuming that whatever executor it was trying to
read data from is gone. So stage 1 has no chance of succeeding, because its
input data doesn't exist anymore. But that means we've got to recreate its
input data. So spark looks at its dependency (stage 0), and figures out what
output from that stage was on the node that is gone ("hostA" in our case). One
of the outputs of stage 0 was one that executor, so spark reruns a task for
stage 0 to regenerate that output. Similarly, in our 3 stage case, when stage
2 fails with a fetch failed, spark goes back to stage 1 to regenerate the stage
2 input -- only to discover that stage 1 also requires some input on "hostA",
so in fact it goes back to stage 0 to regenerate the input for stage 1.
Its really easy to get confused in all of this, so my advice for writing
these tests is to *always* call `checkStageId()` everytime to look at
`taskSets`, just to make sure you are getting what you think you are. (And
helping future readers as well).
so long story short -- it should look like:
```scala
// Confirm job finished succesfully
val stage0Attempt2 = taskSets.last
checkStageId(0, 2, stage0Attempt2)
complete(stage0Attempt2, makeCompletions(stage0Attempt2, 8))
val stage1Attempt2 = taskSets.last
checkStageId(1, 2, stage1Attempt2)
val completions_1_2 = stage1Attempt2.tasks.zipWithIndex.map(_ => (Success,
42)).toSeq
```
---
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]