diff --git a/core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala b/core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala index ec227d40f21ac..a5e78ffc6d0ac 100644 --- a/core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala +++ b/core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala @@ -52,7 +52,7 @@ import org.apache.spark.status._ import org.apache.spark.status.KVUtils._ import org.apache.spark.status.api.v1.{ApplicationAttemptInfo, ApplicationInfo} import org.apache.spark.ui.SparkUI -import org.apache.spark.util.{Clock, SystemClock, ThreadUtils, Utils} +import org.apache.spark.util.{CallerContext, Clock, SystemClock, ThreadUtils, Utils} import org.apache.spark.util.ArrayImplicits._ import org.apache.spark.util.kvstore._ @@ -396,6 +396,7 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) } override def start(): Unit = { + new CallerContext("HISTORY").setCurrentContext() initThread = initialize() } diff --git a/core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala b/core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala index 852f94bda870d..ff1d319c5703c 100644 --- a/core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala +++ b/core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala @@ -29,6 +29,7 @@ import com.google.common.io.{ByteStreams, Files} import org.apache.commons.io.FileUtils import org.apache.hadoop.fs.{FileStatus, FileSystem, FSDataInputStream, Path} import org.apache.hadoop.hdfs.{DFSInputStream, DistributedFileSystem} +import org.apache.hadoop.ipc.{CallerContext => HadoopCallerContext} import org.apache.hadoop.security.AccessControlException import org.mockito.ArgumentMatchers.{any, argThat} import org.mockito.Mockito.{doThrow, mock, spy, verify, when} @@ -1776,6 +1777,18 @@ abstract class FsHistoryProviderSuite extends SparkFunSuite with Matchers with P assert(log2.exists()) } + test("SPARK-51136: FsHistoryProvider start should set Hadoop CallerContext") { + val provider = new FsHistoryProvider(createTestConf()) + provider.start() + + try { + val hadoopCallerContext = HadoopCallerContext.getCurrent() + assert(hadoopCallerContext.getContext() === "SPARK_HISTORY") + } finally { + provider.stop() + } + } + /** * Asks the provider to check for logs and calls a function to perform checks on the updated * app list. Example: