Skip to content
Closed
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
23 changes: 17 additions & 6 deletions core/src/main/scala/org/apache/spark/executor/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ private[spark] class Executor(
// finish downloading dependencies.
private val updateDependenciesLock = new ReentrantLock()

private lazy val mdcIsSupported = {
try {
// This tests if any class initialization error is thrown
val testKey = System.nanoTime().toString
MDC.put(testKey, "testValue")
MDC.remove(testKey)

true
} catch {
case t: Throwable =>
logInfo("MDC is not supported.", t)
false
}
}

// No ip or host:port - just hostname
Utils.checkHost(executorHostname)
// must not have port specified.
Expand Down Expand Up @@ -930,21 +945,17 @@ private[spark] class Executor(
}

private def setMDCForTask(taskName: String, mdc: Seq[(String, String)]): Unit = {
try {
if (mdcIsSupported) {
mdc.foreach { case (key, value) => MDC.put(key, value) }
// avoid overriding the takName by the user
MDC.put(taskNameMDCKey, taskName)
} catch {
case _: NoSuchFieldError => logInfo("MDC is not supported.")
}
}

private def cleanMDCForTask(taskName: String, mdc: Seq[(String, String)]): Unit = {
try {
if (mdcIsSupported) {
mdc.foreach { case (key, _) => MDC.remove(key) }
MDC.remove(taskNameMDCKey)
} catch {
case _: NoSuchFieldError => logInfo("MDC is not supported.")
}
}

Expand Down