[ https://issues.apache.org/jira/browse/SPARK-20952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16043710#comment-16043710 ]
Shixiong Zhu commented on SPARK-20952: -------------------------------------- Although I don't know what you plan to do, you can save the TaskContext into a local variable like this: {code} private[parquet] def readParquetFootersInParallel( conf: Configuration, partFiles: Seq[FileStatus], ignoreCorruptFiles: Boolean): Seq[Footer] = { val taskContext = TaskContext.get val parFiles = partFiles.par parFiles.tasksupport = new ForkJoinTaskSupport(new ForkJoinPool(8)) parFiles.flatMap { currentFile => try { // Use `taskContext` rather than `TaskContext.get` // Skips row group information since we only need the schema. // ParquetFileReader.readFooter throws RuntimeException, instead of IOException, // when it can't read the footer. Some(new Footer(currentFile.getPath(), ParquetFileReader.readFooter( conf, currentFile, SKIP_ROW_GROUPS))) } catch { case e: RuntimeException => if (ignoreCorruptFiles) { logWarning(s"Skipped the footer in the corrupted file: $currentFile", e) None } else { throw new IOException(s"Could not read footer for file: $currentFile", e) } } }.seq } {code} > TaskContext should be an InheritableThreadLocal > ----------------------------------------------- > > Key: SPARK-20952 > URL: https://issues.apache.org/jira/browse/SPARK-20952 > Project: Spark > Issue Type: Bug > Components: Spark Core > Affects Versions: 2.1.1 > Reporter: Robert Kruszewski > Priority: Minor > > TaskContext is a ThreadLocal as a result when you fork a thread inside your > executor task you lose the handle on the original context set by the > executor. We should change it to InheritableThreadLocal so we can access it > inside thread pools on executors. > See ParquetFileFormat#readFootersInParallel for example of code that uses > thread pools inside the tasks. -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org