Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
throw new SparkException("An application name must be set in your configuration")
}

// Thread name has been set to "Driver" if user code ran by AM on a YARN cluster
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things here:

  • Should also check for yarn-standalone since the code still accepts that as an alias for yarn-cluster.
  • I think the check for Driver is too brittle. I think checking for spark.yarn.app.id in SparkConf is slightly better. Both are not 100% fool-proof since users can muck with them, but at least the latter is an internal API (i.e. the YARN code depends on that property to exist for other things).

if (master == "yarn-cluster" &&
Thread.currentThread().getName != "Driver") {
throw new SparkException("Detected yarn-cluster mode, but isn't running on a cluster. " +
"Deployment to YARN is not supported directly by SparkContext. Please use spark-submit.")
}

if (_conf.getBoolean("spark.logConf", false)) {
logInfo("Spark configuration:\n" + _conf.toDebugString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,16 @@ object ApplicationMaster extends Logging {
}

private[spark] def sparkContextInitialized(sc: SparkContext): Unit = {
if (master == null){
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you can ever get into this situation in the real world.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vanzin We thought we can't get into this situation, but we are defending against one right now. I will remove it if you will, but I think this helps more than hurts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you could reach this, but the NPE at that point was just a side effect of a different bug. Fix that bug, NPE is gone. Remove the NPE, but leave the bug in, something else will blow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vanzin Okay.

throw new SparkException("ApplicationMaster is not initialized!")
}
master.sparkContextInitialized(sc)
}

private[spark] def sparkContextStopped(sc: SparkContext): Boolean = {
if (master == null){
throw new SparkException("ApplicationMaster is not initialized!")
}
master.sparkContextStopped(sc)
}

Expand Down