Skip to content
Closed
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,23 @@ private[spark] class ApplicationMaster(
// been set by the Thread executing the user class.
val sc = waitForSparkContextInitialized()

// If there is no SparkContext at this point, just fail the app.
if (sc == null) {
finish(FinalApplicationStatus.FAILED,
ApplicationMaster.EXIT_SC_NOT_INITED,
"Timed out waiting for SparkContext.")
} else {
rpcEnv = sc.env.rpcEnv
val driverRef = runAMEndpoint(
sc.getConf.get("spark.driver.host"),
sc.getConf.get("spark.driver.port"),
isClusterMode = true)
registerAM(rpcEnv, driverRef, sc.ui.map(_.appUIAddress).getOrElse(""), securityMgr)
userClassThread.join()
if (!finished) {
// If there is no SparkContext at this point, just fail the app.
if (!sc.isDefined) {
finish(FinalApplicationStatus.FAILED,
ApplicationMaster.EXIT_SC_NOT_INITED,
"Timed out waiting for SparkContext.")
} else {
val sparkContext = sc.get
rpcEnv = sparkContext.env.rpcEnv
val driverRef = runAMEndpoint(
sparkContext.getConf.get("spark.driver.host"),
sparkContext.getConf.get("spark.driver.port"),
isClusterMode = true)
registerAM(rpcEnv, driverRef, sparkContext.ui.map(_.appUIAddress).getOrElse(""),
securityMgr)
userClassThread.join()
}
}
}

Expand Down Expand Up @@ -503,7 +507,7 @@ private[spark] class ApplicationMaster(
}
}

private def waitForSparkContextInitialized(): SparkContext = {
private def waitForSparkContextInitialized(): Option[SparkContext] = {
logInfo("Waiting for spark context initialization")
sparkContextRef.synchronized {
val totalWaitTime = sparkConf.get(AM_MAX_WAIT_TIME)
Expand All @@ -513,13 +517,16 @@ private[spark] class ApplicationMaster(
logInfo("Waiting for spark context initialization ... ")
sparkContextRef.wait(10000L)
}

val sparkContext = sparkContextRef.get()
if (sparkContext == null) {
logError(("SparkContext did not initialize after waiting for %d ms. Please check earlier"
+ " log output for errors. Failing the application.").format(totalWaitTime))
if (!finished) {
val sparkContext = sparkContextRef.get()
if (sparkContext == null) {
logError(("SparkContext did not initialize after waiting for %d ms. Please check earlier"
+ " log output for errors. Failing the application.").format(totalWaitTime))
} else {
Some(sparkContext)
}
}
sparkContext
None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always return None?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @jerryshao
I am not so good in Scala coding, infact this is the first or second time I am touching scala code :)
I expected the previous line Some(sparkContext) is going to do the trick but, looks like I need to fix that.

}
}

Expand Down