Skip to content

Commit

Permalink
StreamingContext.stop() should stop SparkContext even if StreamingCon…
Browse files Browse the repository at this point in the history
…text has not been started yet.
  • Loading branch information
JoshRosen committed Nov 6, 2014
1 parent c4d35a2 commit d0437eb
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,20 +487,20 @@ class StreamingContext private[streaming] (
* received data to be completed
*/
def stop(stopSparkContext: Boolean, stopGracefully: Boolean): Unit = synchronized {
// Warn (but not fail) if context is stopped twice,
// or context is stopped before starting
if (state == Initialized) {
logWarning("StreamingContext has not been started yet")
return
}
if (state == Stopped) {
logWarning("StreamingContext has already been stopped")
return
} // no need to throw an exception as its okay to stop twice
scheduler.stop(stopGracefully)
logInfo("StreamingContext stopped successfully")
waiter.notifyStop()
if (stopSparkContext) sc.stop()
} else {
// Even if the streaming context has not been started, we still need to stop the SparkContext:
if (stopSparkContext) sc.stop()
if (state == Initialized) {
logWarning("StreamingContext has not been started yet")
} else {
scheduler.stop(stopGracefully)
logInfo("StreamingContext stopped successfully")
waiter.notifyStop()
}
}
// The state should always be Stopped after calling `stop()`, even if we haven't started yet:
state = Stopped
}
}
Expand Down

0 comments on commit d0437eb

Please sign in to comment.