-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-23894][CORE][SQL] Defensively clear ActiveSession in Executors #21185
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,23 @@ private[spark] class Executor( | |
ManagementFactory.getGarbageCollectorMXBeans.asScala.map(_.getCollectionTime).sum | ||
} | ||
|
||
/** | ||
* Only in local mode, we have to prevent the driver from setting the active SparkSession | ||
* in the executor threads. See SPARK-23894. | ||
*/ | ||
private lazy val clearActiveSparkSessionMethod = if (Utils.isLocalMaster(conf)) { | ||
try { | ||
val cls = Utils.classForName("org.apache.spark.sql.SparkSession") | ||
Some(cls.getMethod("clearActiveSession")) | ||
} catch { | ||
case _: ClassNotFoundException => | ||
// sql not on the classpath, no problem, we don't need to worry about clearing anything | ||
None | ||
} | ||
} else { | ||
None | ||
} | ||
|
||
class TaskRunner( | ||
execBackend: ExecutorBackend, | ||
private val taskDescription: TaskDescription) | ||
|
@@ -299,6 +316,9 @@ private[spark] class Executor( | |
Thread.currentThread.setContextClassLoader(replClassLoader) | ||
val ser = env.closureSerializer.newInstance() | ||
logInfo(s"Running $taskName (TID $taskId)") | ||
// When running in local mode, we might end up with the active session from the driver set on | ||
// this thread, though we never should, so we defensively clear it. See SPARK-23894. | ||
clearActiveSparkSessionMethod.foreach(_.invoke(null)) | ||
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. Can this be done in the thread pool's thread factory instead? 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. ThreadFactories only create threads, they don't start them, so you can't do it directly there, as I need this to run inside the thread. I thought about trying to do something fancier, like having the thread pool also start the thread and submit one runnable to do this, or having threads get promoted to the correct thread pool after this ran, but I felt like it was too error-prone for minimal gain. |
||
execBackend.statusUpdate(taskId, TaskState.RUNNING, EMPTY_BYTE_BUFFER) | ||
var taskStart: Long = 0 | ||
var taskStartCpu: Long = 0 | ||
|
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.
Do we still need to call this if we can resolve the root cause in #21190, and issue an error promptly like what you said in #21185 (comment)?
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.
I've added this check in #21190
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.
agreed, I closed this PR