Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ class SparkContext(config: SparkConf) extends Logging {

// Create and start the scheduler
private[spark] var taskScheduler = SparkContext.createTaskScheduler(this, master)
@volatile private[spark] var dagScheduler: DAGScheduler = new DAGScheduler(this)
@volatile private[spark] var dagSchedulerStopped = false
private val dagScheduler: DAGScheduler = new DAGScheduler(this)

// start TaskScheduler after taskScheduler sets DAGScheduler reference in DAGScheduler's
// constructor
Expand Down Expand Up @@ -958,12 +959,13 @@ class SparkContext(config: SparkConf) extends Logging {
ui.stop()
// Do this only if not stopped already - best case effort.
// prevent NPE if stopped more than once.
val dagSchedulerCopy = dagScheduler
dagScheduler = null
if (dagSchedulerCopy != null) {
if (dagSchedulerStopped) {
logInfo("SparkContext already stopped")
} else {
metadataCleaner.cancel()
cleaner.foreach(_.stop())
dagSchedulerCopy.stop()
dagSchedulerStopped = true
dagScheduler.stop()
taskScheduler = null
// TODO: Cache.stop()?
env.stop()
Expand All @@ -973,8 +975,6 @@ class SparkContext(config: SparkConf) extends Logging {
listenerBus.stop()
eventLogger.foreach(_.stop())
logInfo("Successfully stopped SparkContext")
} else {
logInfo("SparkContext already stopped")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class DAGSchedulerSuite extends TestKit(ActorSystem("DAGSchedulerSuite")) with F
watch(child)
child ! "hi"
expectMsgPF(){ case Terminated(child) => () }
assert(scheduler.sc.dagScheduler === null)
assert(scheduler.sc.dagSchedulerStopped === true)
}

/**
Expand Down