-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-1396] Properly cleanup DAGScheduler on job cancellation. #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Properly cleanup DAGScheduler on job cancellation.
Previously, when jobs were cancelled, not all of the state in the DAGScheduler was cleaned up, leading to a slow memory leak in the DAGScheduler. As we expose easier ways ot cancel jobs, it's more important to fix these issues. This commit adds 3 tests. “run shuffle with map stage failure” is a new test to more thoroughly test this functionality, and passes on both the old and new versions of the code. “trivial job cancellation” fails on the old code because all state wasn’t cleaned up correctly when jobs were cancelled (we didn’t remove the job from resultStageToJob). “failure of stage used by two jobs” fails on the old code because taskScheduler.cancelTasks wasn’t called for one of the stages (see test comments).
- Loading branch information
commit 92170800a842c057e022b3d3ae5b6835d3ba23e7
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| package org.apache.spark.scheduler | ||
|
|
||
| import scala.Tuple2 | ||
| import scala.collection.mutable.{HashMap, Map} | ||
| import scala.collection.mutable.{HashSet, HashMap, Map} | ||
|
|
||
| import org.scalatest.{BeforeAndAfter, FunSuite} | ||
|
|
||
|
|
@@ -43,6 +43,10 @@ class DAGSchedulerSuite extends FunSuite with BeforeAndAfter with LocalSparkCont | |
| val conf = new SparkConf | ||
| /** Set of TaskSets the DAGScheduler has requested executed. */ | ||
| val taskSets = scala.collection.mutable.Buffer[TaskSet]() | ||
|
|
||
| /** Stages for which the DAGScheduler has called TaskScheduler.cancelTasks(). */ | ||
| val cancelledStages = new HashSet[Int]() | ||
|
|
||
| val taskScheduler = new TaskScheduler() { | ||
| override def rootPool: Pool = null | ||
| override def schedulingMode: SchedulingMode = SchedulingMode.NONE | ||
|
|
@@ -53,7 +57,9 @@ class DAGSchedulerSuite extends FunSuite with BeforeAndAfter with LocalSparkCont | |
| taskSet.tasks.foreach(_.epoch = mapOutputTracker.getEpoch) | ||
| taskSets += taskSet | ||
| } | ||
| override def cancelTasks(stageId: Int) {} | ||
| override def cancelTasks(stageId: Int) { | ||
| cancelledStages += stageId | ||
| } | ||
| override def setDAGScheduler(dagScheduler: DAGScheduler) = {} | ||
| override def defaultParallelism() = 2 | ||
| } | ||
|
|
@@ -174,22 +180,28 @@ class DAGSchedulerSuite extends FunSuite with BeforeAndAfter with LocalSparkCont | |
| } | ||
| } | ||
|
|
||
| /** Sends the rdd to the scheduler for scheduling. */ | ||
| /** Sends the rdd to the scheduler for scheduling and returns the job id. */ | ||
| private def submit( | ||
| rdd: RDD[_], | ||
| partitions: Array[Int], | ||
| func: (TaskContext, Iterator[_]) => _ = jobComputeFunc, | ||
| allowLocal: Boolean = false, | ||
| listener: JobListener = listener) { | ||
| listener: JobListener = listener): Int = { | ||
| val jobId = scheduler.nextJobId.getAndIncrement() | ||
| runEvent(JobSubmitted(jobId, rdd, func, partitions, allowLocal, null, listener)) | ||
| return jobId | ||
| } | ||
|
|
||
| /** Sends TaskSetFailed to the scheduler. */ | ||
| private def failed(taskSet: TaskSet, message: String) { | ||
| runEvent(TaskSetFailed(taskSet, message)) | ||
| } | ||
|
|
||
| /** Sends JobCancelled to the DAG scheduler. */ | ||
| private def cancel(jobId: Int) { | ||
| runEvent(JobCancelled(jobId)) | ||
| } | ||
|
|
||
| test("zero split job") { | ||
| val rdd = makeRdd(0, Nil) | ||
| var numResults = 0 | ||
|
|
@@ -248,7 +260,15 @@ class DAGSchedulerSuite extends FunSuite with BeforeAndAfter with LocalSparkCont | |
| test("trivial job failure") { | ||
| submit(makeRdd(1, Nil), Array(0)) | ||
| failed(taskSets(0), "some failure") | ||
| assert(failure.getMessage === "Job aborted: some failure") | ||
| assert(failure.getMessage === "Job aborted due to stage failure: some failure") | ||
| assertDataStructuresEmpty | ||
| } | ||
|
|
||
| test("trivial job cancellation") { | ||
| val rdd = makeRdd(1, Nil) | ||
| val jobId = submit(rdd, Array(0)) | ||
| cancel(jobId) | ||
| assert(failure.getMessage === s"Job $jobId cancelled") | ||
| assertDataStructuresEmpty | ||
| } | ||
|
|
||
|
|
@@ -323,6 +343,68 @@ class DAGSchedulerSuite extends FunSuite with BeforeAndAfter with LocalSparkCont | |
| assertDataStructuresEmpty | ||
| } | ||
|
|
||
| test("run shuffle with map stage failure") { | ||
| val shuffleMapRdd = makeRdd(2, Nil) | ||
| val shuffleDep = new ShuffleDependency(shuffleMapRdd, null) | ||
| val shuffleId = shuffleDep.shuffleId | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used |
||
| val reduceRdd = makeRdd(2, List(shuffleDep)) | ||
| submit(reduceRdd, Array(0, 1)) | ||
|
|
||
| // Fail the map stage. This should cause the entire job to fail. | ||
| val stageFailureMessage = "Exception failure in map stage" | ||
| failed(taskSets(0), stageFailureMessage) | ||
| assert(failure.getMessage === s"Job aborted due to stage failure: $stageFailureMessage") | ||
| assertDataStructuresEmpty | ||
| } | ||
|
|
||
| /** | ||
| * Makes sure that failures of stage used by multiple jobs are correctly handled. | ||
| * | ||
| * This test creates the following dependency graph: | ||
| * | ||
| * shuffleMapRdd1 shuffleMapRDD2 | ||
| * | \ | | ||
| * | \ | | ||
| * | \ | | ||
| * | \ | | ||
| * reduceRdd1 reduceRdd2 | ||
| * | ||
| * We start both shuffleMapRdds and then fail shuffleMapRdd1. As a result, the job listeners for | ||
| * reduceRdd1 and reduceRdd2 should both be informed that the job failed. shuffleMapRDD2 should | ||
| * also be cancelled, because it is only used by reduceRdd2 and reduceRdd2 cannot complete | ||
| * without shuffleMapRdd1. | ||
| */ | ||
| test("failure of stage used by two jobs") { | ||
| val shuffleMapRdd1 = makeRdd(2, Nil) | ||
| val shuffleDep1 = new ShuffleDependency(shuffleMapRdd1, null) | ||
| val shuffleMapRdd2 = makeRdd(2, Nil) | ||
| val shuffleDep2 = new ShuffleDependency(shuffleMapRdd2, null) | ||
|
|
||
| val reduceRdd1 = makeRdd(2, List(shuffleDep1)) | ||
| val reduceRdd2 = makeRdd(2, List(shuffleDep1, shuffleDep2)) | ||
|
|
||
| // We need to make our own listeners for this test, since by default submit uses the same | ||
| // listener for all jobs, and here we want to capture the failure for each job separately. | ||
| class FailureRecordingJobListener() extends JobListener { | ||
| var failureMessage: String = _ | ||
| override def taskSucceeded(index: Int, result: Any) {} | ||
| override def jobFailed(exception: Exception) = { failureMessage = exception.getMessage } | ||
| } | ||
| val listener1 = new FailureRecordingJobListener() | ||
| val listener2 = new FailureRecordingJobListener() | ||
|
|
||
| submit(reduceRdd1, Array(0, 1), listener=listener1) | ||
| submit(reduceRdd2, Array(0, 1), listener=listener2) | ||
|
|
||
| val stageFailureMessage = "Exception failure in map stage" | ||
| failed(taskSets(0), stageFailureMessage) | ||
|
|
||
| assert(cancelledStages.contains(1)) | ||
| assert(listener1.failureMessage === s"Job aborted due to stage failure: $stageFailureMessage") | ||
| assert(listener2.failureMessage === s"Job aborted due to stage failure: $stageFailureMessage") | ||
| assertDataStructuresEmpty | ||
| } | ||
|
|
||
| test("run trivial shuffle with out-of-band failure and retry") { | ||
| val shuffleMapRdd = makeRdd(2, Nil) | ||
| val shuffleDep = new ShuffleDependency(shuffleMapRdd, null) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear in
before?