You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "thejdeep (via GitHub)" <gi...@apache.org> on 2023/04/25 17:34:27 UTC

[GitHub] [spark] thejdeep opened a new pull request, #40949: [DRAFT][SPARK-23607][CORE] Use HDFS extended attributes to store application summary information in SHS

thejdeep opened a new pull request, #40949:
URL: https://github.com/apache/spark/pull/40949

    ### What changes were proposed in this pull request?
   Previously, #34829 was raised which was auto closed due to staleness. This is a rework of that by addressing comments raised.
   
    This PR seeks to improve the performance of serving the application list in History Server by storing the required information of the application as part of HDFS extended attributes instead of parsing the log file each time.
   
    ### Why are the changes needed?
   
    Improves the performance of the History Server listing page
   
   Below is the comparison of the  time taken to complete `mergeApplicationListing` call [in FsHistoryProvider](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala#L584) that is called for every log file that is updated in the event log directory : 
   
   | Event log size  | Extended Attributes disabled (in ms) | Extended Attributes enabled (in ms) |
   | ------------- | ------------- | ------------- |
   | 122MB  | 1340 | 137  |
   | 10.2MB  | 866 | 135  |
   | 5.5MB  | 645  | 136 |
   |  0.6MB | 505 | 134 |
   | 0.8MB  | 525 | 137  |
   
   As we can see in the comparison above, irrespective of the event log size, the time to build the application listing for the app remains the same. This is hugely beneficial in clusters that have very large event log sizes.
   
    ### Does this PR introduce _any_ user-facing change?
   
    No.
   
    ### How was this patch tested?
    Will add unit tests


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] github-actions[bot] commented on pull request #40949: [DRAFT][SPARK-23607][CORE] Use HDFS extended attributes to store application summary information in SHS

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40949:
URL: https://github.com/apache/spark/pull/40949#issuecomment-1668735341

   We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
   If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] mridulm commented on a diff in pull request #40949: [DRAFT][SPARK-23607][CORE] Use HDFS extended attributes to store application summary information in SHS

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on code in PR #40949:
URL: https://github.com/apache/spark/pull/40949#discussion_r1180986821


##########
core/src/main/scala/org/apache/spark/internal/config/History.scala:
##########
@@ -202,6 +202,11 @@ private[spark] object History {
     .stringConf
     .createOptional
 
+  val EVENT_LOG_XATTR_ENABLED = ConfigBuilder("spark.history.fs.eventLog.xattr.enabled")
+    .version("3.3.0")

Review Comment:
   version `3.5.0`



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&
+        attemptId.isDefined) {
+        val oldApp: Option[ApplicationInfoWrapper] = try {
+          Some(listing.read(classOf[ApplicationInfoWrapper], appId.get))
+        } catch {
+          case _: NoSuchElementException => None
+        }
+        if (oldApp.isDefined) {
+          val oldAppAttemptList = oldApp.get.attempts.filter(_.info.attemptId == attemptId)
+          if (oldAppAttemptList.size == 1) {
+            appListingFromXAttr.applicationInfoFromDB(oldApp.get.info.id,
+              oldApp.get.info.name, oldAppAttemptList.last)
+          }
+        }
+      }
+      if (appStartInfo.isDefined) {
+        appListingFromXAttr.applicationStartFromXAttr(appStartInfo.get)
+      }
+      if (envUpdateInfo.isDefined) {
+        appListingFromXAttr.applicationEnvUpdateFromXAttr(envUpdateInfo.get)
+      }
+      if(appEndInfo.isDefined) {
+        appListingFromXAttr.applicationEndFromXAttr(appEndInfo.get)
+      }
+      appListingFromXAttr.applicationInfo match {
+        case Some(app) =>
+          invalidateUI(app.info.id, app.attempts.head.info.attemptId)
+          addListing(app)
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            Some(app.info.id), app.attempts.head.info.attemptId, reader.fileSizeForLastIndex,
+            reader.lastIndex, None, reader.completed, xAttrStatus))
+          if (isCompleted(reader.rootPath.toString)) {
+            removeInProgressEntry(reader.rootPath)
+          }
+        case _ =>
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            None, None, reader.fileSizeForLastIndex, reader.lastIndex, None,
+          reader.completed, xAttrStatus))
+      }
+    }
+    logInfo(s"Finished reading extended attributes for file : ${reader.rootPath}")
+    endProcessing(reader.rootPath)
+    pendingReplayTasksCount.decrementAndGet()
+  }
+
+  /**
+   * For a finished log, remove the corresponding "in progress" entry from the listing DB if
+   * the file is really gone.
+   * @param logPath in progress log file path to be removed
+   */
+  private def removeInProgressEntry(logPath: Path): Unit = {
+    if (isCompleted(logPath.getName())) {
+      val inProgressLog = logPath.toString() + EventLogFileWriter.IN_PROGRESS
+      try {
+        // Fetch the entry first to avoid an RPC when it's already removed.
+        listing.read(classOf[LogInfo], inProgressLog)
+        val fileStatus = fs.getFileStatus(new Path(inProgressLog))
+        if (!fileStatus.isFile) {
+          listing.delete(classOf[LogInfo], inProgressLog)
+        }
+      } catch {
+        case _: NoSuchElementException =>
+      }
+    }
+  }
+
+  /**
+   * @param name of the log file
+   * @return true if log file ends with inprogress
+   */
+  private def isCompleted(name: String): Boolean = {
+    !name.endsWith(EventLogFileWriter.IN_PROGRESS)
+  }
+
+  private def getXAttrs(path: Path, nameList: List[String]): Option[Map[String, String]] = {
+    try {
+      val valueMap = fs.getXAttrs(path, nameList.asJava)
+      if(valueMap != null) {
+        Some(valueMap.asScala.toMap.map(value => value._1 -> new String(value._2)))
+      } else {
+        None
+      }
+    } catch {
+      case _: IOException =>
+        logWarning(s"Unable to get extended attributes ${nameList}")
+        None
+    }
+  }
+
+  /**
+   * Get the value of a single attribute from HDFS
+   * @param path path to HDFS
+   * @param name Key of extended attribute
+   * @return Value of extended attribute
+   */
+  private def getXAttr(path: Path, name: String): Option[String] = {
+      val valueMap = getXAttrs(path, List(name))
+      if (!valueMap.isEmpty) {
+        Some(valueMap.get(name))
+      } else {
+        None
+      }
+  }
+
+  /**
+   * For a new file, update listing entry with whether extended attributes
+   * are enabled or disabled on this log file
+   *
+   * @param reader event log file reader
+   * @param scanTime current scan timestamp
+   * @return
+   */
+  private def handleNewLogFile(reader: EventLogFileReader, scanTime: Long): Boolean = {
+    var xAttrStatus = LogXAttrStatus.XATTR_DISABLED
+    if(HISTORY_LOG_USE_XATTR) {
+      val isXAttrEnabled = getXAttr(reader.rootPath, EventLoggingListener.USER_XATTR_ENABLED)

Review Comment:
   nit: `isXAttrEnabled` -> `xattrEnabled`



##########
core/src/main/scala/org/apache/spark/deploy/history/EventLogFileWriters.scala:
##########
@@ -154,6 +154,9 @@ abstract class EventLogFileWriter(
   /** writes JSON format of event to file */
   def writeEvent(eventJson: String, flushLogger: Boolean = false): Unit
 
+  /** Writes key/value pair to HDFS Extended attribute */
+  def writeToXAttr(attrName: String, attrValue: String): Unit = {}

Review Comment:
   No one is calling this method ?



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&
+        attemptId.isDefined) {
+        val oldApp: Option[ApplicationInfoWrapper] = try {
+          Some(listing.read(classOf[ApplicationInfoWrapper], appId.get))
+        } catch {
+          case _: NoSuchElementException => None
+        }
+        if (oldApp.isDefined) {
+          val oldAppAttemptList = oldApp.get.attempts.filter(_.info.attemptId == attemptId)
+          if (oldAppAttemptList.size == 1) {
+            appListingFromXAttr.applicationInfoFromDB(oldApp.get.info.id,
+              oldApp.get.info.name, oldAppAttemptList.last)
+          }
+        }
+      }
+      if (appStartInfo.isDefined) {
+        appListingFromXAttr.applicationStartFromXAttr(appStartInfo.get)
+      }
+      if (envUpdateInfo.isDefined) {
+        appListingFromXAttr.applicationEnvUpdateFromXAttr(envUpdateInfo.get)
+      }
+      if(appEndInfo.isDefined) {
+        appListingFromXAttr.applicationEndFromXAttr(appEndInfo.get)
+      }
+      appListingFromXAttr.applicationInfo match {
+        case Some(app) =>
+          invalidateUI(app.info.id, app.attempts.head.info.attemptId)
+          addListing(app)
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            Some(app.info.id), app.attempts.head.info.attemptId, reader.fileSizeForLastIndex,
+            reader.lastIndex, None, reader.completed, xAttrStatus))
+          if (isCompleted(reader.rootPath.toString)) {
+            removeInProgressEntry(reader.rootPath)
+          }
+        case _ =>
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            None, None, reader.fileSizeForLastIndex, reader.lastIndex, None,
+          reader.completed, xAttrStatus))
+      }
+    }
+    logInfo(s"Finished reading extended attributes for file : ${reader.rootPath}")
+    endProcessing(reader.rootPath)
+    pendingReplayTasksCount.decrementAndGet()
+  }
+
+  /**
+   * For a finished log, remove the corresponding "in progress" entry from the listing DB if
+   * the file is really gone.
+   * @param logPath in progress log file path to be removed
+   */
+  private def removeInProgressEntry(logPath: Path): Unit = {
+    if (isCompleted(logPath.getName())) {
+      val inProgressLog = logPath.toString() + EventLogFileWriter.IN_PROGRESS
+      try {
+        // Fetch the entry first to avoid an RPC when it's already removed.
+        listing.read(classOf[LogInfo], inProgressLog)
+        val fileStatus = fs.getFileStatus(new Path(inProgressLog))
+        if (!fileStatus.isFile) {
+          listing.delete(classOf[LogInfo], inProgressLog)
+        }
+      } catch {
+        case _: NoSuchElementException =>
+      }
+    }
+  }
+
+  /**
+   * @param name of the log file
+   * @return true if log file ends with inprogress
+   */
+  private def isCompleted(name: String): Boolean = {
+    !name.endsWith(EventLogFileWriter.IN_PROGRESS)
+  }
+
+  private def getXAttrs(path: Path, nameList: List[String]): Option[Map[String, String]] = {
+    try {
+      val valueMap = fs.getXAttrs(path, nameList.asJava)
+      if(valueMap != null) {
+        Some(valueMap.asScala.toMap.map(value => value._1 -> new String(value._2)))
+      } else {
+        None
+      }
+    } catch {
+      case _: IOException =>
+        logWarning(s"Unable to get extended attributes ${nameList}")
+        None
+    }
+  }
+
+  /**
+   * Get the value of a single attribute from HDFS
+   * @param path path to HDFS
+   * @param name Key of extended attribute
+   * @return Value of extended attribute
+   */
+  private def getXAttr(path: Path, name: String): Option[String] = {
+      val valueMap = getXAttrs(path, List(name))
+      if (!valueMap.isEmpty) {
+        Some(valueMap.get(name))

Review Comment:
   nit: `Option` instead of `Some`



##########
core/src/main/scala/org/apache/spark/deploy/history/EventLogFileWriters.scala:
##########
@@ -229,6 +232,17 @@ class SingleEventLogFileWriter(
     writeLine(eventJson, flushLogger)
   }
 
+  override def writeToXAttr(attrName: String, attrValue: String): Unit = {
+    try {
+      fileSystem.setXAttr(new Path(inProgressPath), attrName, attrValue.getBytes())
+    } catch {
+      case _: IOException =>
+        logWarning(s"Failed to set extended attribute ${attrName}")
+      case _: UnsupportedOperationException =>
+        logWarning("setXAttr not supported by filesystem")

Review Comment:
   Make these `INFO` ?



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -920,6 +918,23 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     }
   }
 
+  private def updateApplicationInfoFromLog(reader: EventLogFileReader, scanTime: Long): Unit = {
+    if (!HISTORY_LOG_USE_XATTR) {
+      mergeApplicationListing(reader, scanTime, true)
+    } else {
+      try {
+        val log = listing.read(classOf[LogInfo], reader.rootPath.toString)
+        if (log.logXAttrStatus != LogXAttrStatus.XATTR_DISABLED) {
+          updateAppInfoFromXAttrs(log, reader, scanTime)
+        } else {
+          mergeApplicationListing(reader, scanTime, true)
+        }
+      } catch {
+        case _: NoSuchElementException => None

Review Comment:
   Remove `None` ?
   Also, if `NoSuchElementException`, do we want to fall back to `mergeApplicationListing` ?



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -550,11 +552,7 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
                   listing.delete(classOf[LogInfo], reader.rootPath.toString)
                   false
                 } else if (count < conf.get(UPDATE_BATCHSIZE)) {
-                  listing.write(LogInfo(reader.rootPath.toString(), newLastScanTime,
-                    LogType.EventLogs, None, None, reader.fileSizeForLastIndex, reader.lastIndex,
-                    None, reader.completed))
-                  count = count + 1
-                  reader.fileSizeForLastIndex > 0
+                  handleNewLogFile(reader, newLastScanTime)

Review Comment:
   increment `count`



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&
+        attemptId.isDefined) {
+        val oldApp: Option[ApplicationInfoWrapper] = try {
+          Some(listing.read(classOf[ApplicationInfoWrapper], appId.get))
+        } catch {
+          case _: NoSuchElementException => None
+        }
+        if (oldApp.isDefined) {
+          val oldAppAttemptList = oldApp.get.attempts.filter(_.info.attemptId == attemptId)
+          if (oldAppAttemptList.size == 1) {
+            appListingFromXAttr.applicationInfoFromDB(oldApp.get.info.id,
+              oldApp.get.info.name, oldAppAttemptList.last)
+          }
+        }
+      }
+      if (appStartInfo.isDefined) {
+        appListingFromXAttr.applicationStartFromXAttr(appStartInfo.get)
+      }
+      if (envUpdateInfo.isDefined) {
+        appListingFromXAttr.applicationEnvUpdateFromXAttr(envUpdateInfo.get)
+      }
+      if(appEndInfo.isDefined) {
+        appListingFromXAttr.applicationEndFromXAttr(appEndInfo.get)
+      }
+      appListingFromXAttr.applicationInfo match {
+        case Some(app) =>
+          invalidateUI(app.info.id, app.attempts.head.info.attemptId)
+          addListing(app)
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            Some(app.info.id), app.attempts.head.info.attemptId, reader.fileSizeForLastIndex,
+            reader.lastIndex, None, reader.completed, xAttrStatus))
+          if (isCompleted(reader.rootPath.toString)) {
+            removeInProgressEntry(reader.rootPath)
+          }
+        case _ =>
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            None, None, reader.fileSizeForLastIndex, reader.lastIndex, None,
+          reader.completed, xAttrStatus))
+      }
+    }
+    logInfo(s"Finished reading extended attributes for file : ${reader.rootPath}")
+    endProcessing(reader.rootPath)
+    pendingReplayTasksCount.decrementAndGet()
+  }
+
+  /**
+   * For a finished log, remove the corresponding "in progress" entry from the listing DB if
+   * the file is really gone.
+   * @param logPath in progress log file path to be removed
+   */
+  private def removeInProgressEntry(logPath: Path): Unit = {
+    if (isCompleted(logPath.getName())) {
+      val inProgressLog = logPath.toString() + EventLogFileWriter.IN_PROGRESS
+      try {
+        // Fetch the entry first to avoid an RPC when it's already removed.
+        listing.read(classOf[LogInfo], inProgressLog)
+        val fileStatus = fs.getFileStatus(new Path(inProgressLog))
+        if (!fileStatus.isFile) {
+          listing.delete(classOf[LogInfo], inProgressLog)
+        }
+      } catch {
+        case _: NoSuchElementException =>
+      }
+    }
+  }
+
+  /**
+   * @param name of the log file
+   * @return true if log file ends with inprogress
+   */
+  private def isCompleted(name: String): Boolean = {
+    !name.endsWith(EventLogFileWriter.IN_PROGRESS)
+  }
+
+  private def getXAttrs(path: Path, nameList: List[String]): Option[Map[String, String]] = {
+    try {
+      val valueMap = fs.getXAttrs(path, nameList.asJava)
+      if(valueMap != null) {
+        Some(valueMap.asScala.toMap.map(value => value._1 -> new String(value._2)))
+      } else {
+        None
+      }
+    } catch {
+      case _: IOException =>
+        logWarning(s"Unable to get extended attributes ${nameList}")
+        None
+    }
+  }
+
+  /**
+   * Get the value of a single attribute from HDFS
+   * @param path path to HDFS
+   * @param name Key of extended attribute
+   * @return Value of extended attribute
+   */
+  private def getXAttr(path: Path, name: String): Option[String] = {
+      val valueMap = getXAttrs(path, List(name))
+      if (!valueMap.isEmpty) {
+        Some(valueMap.get(name))
+      } else {
+        None
+      }
+  }
+
+  /**
+   * For a new file, update listing entry with whether extended attributes
+   * are enabled or disabled on this log file
+   *
+   * @param reader event log file reader
+   * @param scanTime current scan timestamp
+   * @return
+   */
+  private def handleNewLogFile(reader: EventLogFileReader, scanTime: Long): Boolean = {
+    var xAttrStatus = LogXAttrStatus.XATTR_DISABLED
+    if(HISTORY_LOG_USE_XATTR) {
+      val isXAttrEnabled = getXAttr(reader.rootPath, EventLoggingListener.USER_XATTR_ENABLED)
+      if (isXAttrEnabled.isDefined && new String(isXAttrEnabled.get) == "true") {

Review Comment:
   Encode/decode bytes explicitly using `UTF-8`, and not platform default.
   
   nit: Also, use something like 
   `xattrEnabled.exists(data => new String(data, StandardCharsets.UTF_8) == "true")` instead of the current condition



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {

Review Comment:
   Fix indentation



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))

Review Comment:
   Use `Option` instead of `Some` - in case any of them end up being unspecified/missing.
   (Right now, no one is setting xattr - so it is unclear to me what can end up happening)



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&
+        attemptId.isDefined) {

Review Comment:
   In general, attemptId need not be always present - it is optional, unlike appId (for client deploy mode).
   So this condition looks overly restrictive.



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&

Review Comment:
   Do we need the `info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED ` check here ?



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1453,6 +1642,11 @@ private[history] object LogType extends Enumeration {
   val DriverLogs, EventLogs = Value
 }
 
+private[history] object LogXAttrStatus extends Enumeration {
+  val XATTR_DISABLED, XATTR_ENABLED, APP_STARTED, APP_ENV_UPDATED, APP_END = Value

Review Comment:
   Add documentation on what each of these states is capturing (in the lifecycle of a spark application)



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&
+        attemptId.isDefined) {
+        val oldApp: Option[ApplicationInfoWrapper] = try {
+          Some(listing.read(classOf[ApplicationInfoWrapper], appId.get))
+        } catch {
+          case _: NoSuchElementException => None
+        }
+        if (oldApp.isDefined) {
+          val oldAppAttemptList = oldApp.get.attempts.filter(_.info.attemptId == attemptId)
+          if (oldAppAttemptList.size == 1) {
+            appListingFromXAttr.applicationInfoFromDB(oldApp.get.info.id,
+              oldApp.get.info.name, oldAppAttemptList.last)
+          }
+        }
+      }
+      if (appStartInfo.isDefined) {
+        appListingFromXAttr.applicationStartFromXAttr(appStartInfo.get)
+      }
+      if (envUpdateInfo.isDefined) {
+        appListingFromXAttr.applicationEnvUpdateFromXAttr(envUpdateInfo.get)
+      }
+      if(appEndInfo.isDefined) {
+        appListingFromXAttr.applicationEndFromXAttr(appEndInfo.get)
+      }
+      appListingFromXAttr.applicationInfo match {
+        case Some(app) =>
+          invalidateUI(app.info.id, app.attempts.head.info.attemptId)
+          addListing(app)
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            Some(app.info.id), app.attempts.head.info.attemptId, reader.fileSizeForLastIndex,
+            reader.lastIndex, None, reader.completed, xAttrStatus))
+          if (isCompleted(reader.rootPath.toString)) {
+            removeInProgressEntry(reader.rootPath)
+          }
+        case _ =>
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            None, None, reader.fileSizeForLastIndex, reader.lastIndex, None,
+          reader.completed, xAttrStatus))
+      }
+    }
+    logInfo(s"Finished reading extended attributes for file : ${reader.rootPath}")
+    endProcessing(reader.rootPath)
+    pendingReplayTasksCount.decrementAndGet()
+  }
+
+  /**
+   * For a finished log, remove the corresponding "in progress" entry from the listing DB if
+   * the file is really gone.
+   * @param logPath in progress log file path to be removed
+   */
+  private def removeInProgressEntry(logPath: Path): Unit = {
+    if (isCompleted(logPath.getName())) {
+      val inProgressLog = logPath.toString() + EventLogFileWriter.IN_PROGRESS
+      try {
+        // Fetch the entry first to avoid an RPC when it's already removed.
+        listing.read(classOf[LogInfo], inProgressLog)
+        val fileStatus = fs.getFileStatus(new Path(inProgressLog))
+        if (!fileStatus.isFile) {
+          listing.delete(classOf[LogInfo], inProgressLog)
+        }
+      } catch {
+        case _: NoSuchElementException =>
+      }
+    }
+  }

Review Comment:
   This is mostly duplicated in `doMergeApplicationListingInternal` - and there is some changes between both - please update this method and ensure `doMergeApplicationListingInternal` delegates to this method as well.



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&
+        attemptId.isDefined) {
+        val oldApp: Option[ApplicationInfoWrapper] = try {
+          Some(listing.read(classOf[ApplicationInfoWrapper], appId.get))
+        } catch {
+          case _: NoSuchElementException => None
+        }
+        if (oldApp.isDefined) {
+          val oldAppAttemptList = oldApp.get.attempts.filter(_.info.attemptId == attemptId)
+          if (oldAppAttemptList.size == 1) {
+            appListingFromXAttr.applicationInfoFromDB(oldApp.get.info.id,
+              oldApp.get.info.name, oldAppAttemptList.last)
+          }
+        }
+      }
+      if (appStartInfo.isDefined) {
+        appListingFromXAttr.applicationStartFromXAttr(appStartInfo.get)
+      }
+      if (envUpdateInfo.isDefined) {
+        appListingFromXAttr.applicationEnvUpdateFromXAttr(envUpdateInfo.get)
+      }
+      if(appEndInfo.isDefined) {
+        appListingFromXAttr.applicationEndFromXAttr(appEndInfo.get)
+      }
+      appListingFromXAttr.applicationInfo match {

Review Comment:
   There is some amount of common functionality between `doMergeApplicationListingInternal` and here. 
   We should see what can be done to ensure there is no  future divergence between the two codepaths.



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1177,6 +1192,180 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
     listing.read(classOf[ApplicationInfoWrapper], appId)
   }
 
+  private def updateAppInfoFromXAttrs(info: LogInfo, reader: EventLogFileReader,
+                                      scanTime: Long): Unit = {
+    var xAttrStatus: LogXAttrStatus.Value = info.logXAttrStatus
+    var appStartInfo: Option[Map[String, String]] = None
+    var envUpdateInfo: Option[String] = None
+    var appEndInfo: Option[String] = None
+    var appId = info.appId
+    var attemptId = info.attemptId
+
+    pendingReplayTasksCount.incrementAndGet()
+    /**
+     * XATTR_ENABLED means it is a newly detected file
+     * If we are able to successfully get the application start information,
+     * change the status to APP_STARTED
+    */
+    if (xAttrStatus == LogXAttrStatus.XATTR_ENABLED) {
+      appStartInfo = getXAttrs(reader.rootPath, EventLoggingListener.XATTRS_APPLICATION_START_LIST)
+      if(appStartInfo.isDefined) {
+        appId = Some(appStartInfo.get(EventLoggingListener.USER_APP_ID))
+        attemptId = Some(appStartInfo.get(EventLoggingListener.USER_ATTEMPT_ID))
+        xAttrStatus = LogXAttrStatus.APP_STARTED
+      }
+    }
+
+    /**
+     * Try to get application env update information
+     * If we are able to successfully get them, change the status to APP_ENV_UPDATED
+     */
+    if(xAttrStatus == LogXAttrStatus.APP_STARTED) {
+      envUpdateInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ACLS)
+      if(envUpdateInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_ENV_UPDATED
+      }
+    }
+
+    /**
+     * Try to get the application attempt end time
+     * If we are able to successfully get them, change the status to APP_END
+     */
+    if (xAttrStatus == LogXAttrStatus.APP_ENV_UPDATED) {
+      appEndInfo = getXAttr(reader.rootPath, EventLoggingListener.USER_ATTEMPT_ENDTIME)
+      if (appEndInfo.isDefined) {
+        xAttrStatus = LogXAttrStatus.APP_END
+      }
+    }
+
+    // Check if status is updated
+    if(xAttrStatus != info.logXAttrStatus) {
+      val appListingFromXAttr = new AppListingEntryFromXAttr(reader, clock)
+      if (info.logXAttrStatus != LogXAttrStatus.XATTR_ENABLED && appId.isDefined &&
+        attemptId.isDefined) {
+        val oldApp: Option[ApplicationInfoWrapper] = try {
+          Some(listing.read(classOf[ApplicationInfoWrapper], appId.get))
+        } catch {
+          case _: NoSuchElementException => None
+        }
+        if (oldApp.isDefined) {
+          val oldAppAttemptList = oldApp.get.attempts.filter(_.info.attemptId == attemptId)
+          if (oldAppAttemptList.size == 1) {
+            appListingFromXAttr.applicationInfoFromDB(oldApp.get.info.id,
+              oldApp.get.info.name, oldAppAttemptList.last)
+          }
+        }
+      }
+      if (appStartInfo.isDefined) {
+        appListingFromXAttr.applicationStartFromXAttr(appStartInfo.get)
+      }
+      if (envUpdateInfo.isDefined) {
+        appListingFromXAttr.applicationEnvUpdateFromXAttr(envUpdateInfo.get)
+      }
+      if(appEndInfo.isDefined) {
+        appListingFromXAttr.applicationEndFromXAttr(appEndInfo.get)
+      }
+      appListingFromXAttr.applicationInfo match {
+        case Some(app) =>
+          invalidateUI(app.info.id, app.attempts.head.info.attemptId)
+          addListing(app)
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            Some(app.info.id), app.attempts.head.info.attemptId, reader.fileSizeForLastIndex,
+            reader.lastIndex, None, reader.completed, xAttrStatus))
+          if (isCompleted(reader.rootPath.toString)) {
+            removeInProgressEntry(reader.rootPath)
+          }
+        case _ =>
+          listing.write(LogInfo(reader.rootPath.toString, scanTime, LogType.EventLogs,
+            None, None, reader.fileSizeForLastIndex, reader.lastIndex, None,
+          reader.completed, xAttrStatus))
+      }
+    }
+    logInfo(s"Finished reading extended attributes for file : ${reader.rootPath}")
+    endProcessing(reader.rootPath)
+    pendingReplayTasksCount.decrementAndGet()
+  }
+
+  /**
+   * For a finished log, remove the corresponding "in progress" entry from the listing DB if
+   * the file is really gone.
+   * @param logPath in progress log file path to be removed
+   */
+  private def removeInProgressEntry(logPath: Path): Unit = {
+    if (isCompleted(logPath.getName())) {
+      val inProgressLog = logPath.toString() + EventLogFileWriter.IN_PROGRESS
+      try {
+        // Fetch the entry first to avoid an RPC when it's already removed.
+        listing.read(classOf[LogInfo], inProgressLog)
+        val fileStatus = fs.getFileStatus(new Path(inProgressLog))
+        if (!fileStatus.isFile) {
+          listing.delete(classOf[LogInfo], inProgressLog)
+        }
+      } catch {
+        case _: NoSuchElementException =>
+      }
+    }
+  }
+
+  /**
+   * @param name of the log file
+   * @return true if log file ends with inprogress
+   */
+  private def isCompleted(name: String): Boolean = {
+    !name.endsWith(EventLogFileWriter.IN_PROGRESS)
+  }
+
+  private def getXAttrs(path: Path, nameList: List[String]): Option[Map[String, String]] = {
+    try {
+      val valueMap = fs.getXAttrs(path, nameList.asJava)
+      if(valueMap != null) {
+        Some(valueMap.asScala.toMap.map(value => value._1 -> new String(value._2)))

Review Comment:
   As mentioned earlier, use utf-8 when converting bytes to `String`



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1575,53 +1841,53 @@ private[history] class AppListingListener(
     }
   }
 
-  private class MutableApplicationInfo {
-    var id: String = null
-    var name: String = null
+}
 
-    def toView(): ApplicationInfoWrapper = {
-      val apiInfo = ApplicationInfo(id, name, None, None, None, None, Nil)
-      new ApplicationInfoWrapper(apiInfo, List(attempt.toView()))
-    }
+private class MutableApplicationInfo {
+  var id: Option[String] = None
+  var name: String = null
 
+  def toView(attempts: List[AttemptInfoWrapper]): ApplicationInfoWrapper = {
+    val apiInfo = ApplicationInfo(id.get, name, None, None, None, None, Nil)

Review Comment:
   Why are we assuming `id` wont be `None` ?
   If that is not a valid assumption, replace with `id.orNull`
   



##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -1575,53 +1841,53 @@ private[history] class AppListingListener(
     }
   }
 
-  private class MutableApplicationInfo {
-    var id: String = null
-    var name: String = null
+}
 
-    def toView(): ApplicationInfoWrapper = {
-      val apiInfo = ApplicationInfo(id, name, None, None, None, None, Nil)
-      new ApplicationInfoWrapper(apiInfo, List(attempt.toView()))
-    }
+private class MutableApplicationInfo {
+  var id: Option[String] = None
+  var name: String = null
 
+  def toView(attempts: List[AttemptInfoWrapper]): ApplicationInfoWrapper = {
+    val apiInfo = ApplicationInfo(id.get, name, None, None, None, None, Nil)
+    new ApplicationInfoWrapper(apiInfo, attempts)
   }
 
-  private class MutableAttemptInfo(logPath: String, fileSize: Long, lastIndex: Option[Long]) {
-    var attemptId: Option[String] = None
-    var startTime = new Date(-1)
-    var endTime = new Date(-1)
-    var lastUpdated = new Date(-1)
-    var duration = 0L
-    var sparkUser: String = null
-    var completed = false
-    var appSparkVersion = ""
-
-    var adminAcls: Option[String] = None
-    var viewAcls: Option[String] = None
-    var adminAclsGroups: Option[String] = None
-    var viewAclsGroups: Option[String] = None
-
-    def toView(): AttemptInfoWrapper = {
-      val apiInfo = ApplicationAttemptInfo(
-        attemptId,
-        startTime,
-        endTime,
-        lastUpdated,
-        duration,
-        sparkUser,
-        completed,
-        appSparkVersion)
-      new AttemptInfoWrapper(
-        apiInfo,
-        logPath,
-        fileSize,
-        lastIndex,
-        adminAcls,
-        viewAcls,
-        adminAclsGroups,
-        viewAclsGroups)
-    }
+}
 
+private class MutableAttemptInfo(logPath: String, fileSize: Long, lastIndex: Option[Long] = None) {
+  var attemptId: Option[String] = None
+  var startTime = new Date(-1)
+  var endTime = new Date(-1)
+  var lastUpdated = new Date(-1)
+  var duration = 0L
+  var sparkUser: String = null
+  var completed = false
+  var appSparkVersion = ""
+
+  var adminAcls: Option[String] = None
+  var viewAcls: Option[String] = None
+  var adminAclsGroups: Option[String] = None
+  var viewAclsGroups: Option[String] = None
+
+  def toView(): AttemptInfoWrapper = {
+    val apiInfo = ApplicationAttemptInfo(
+      attemptId,
+      startTime,
+      endTime,
+      lastUpdated,
+      duration,
+      sparkUser,
+      completed,
+      appSparkVersion)
+    new AttemptInfoWrapper(
+      apiInfo,
+      logPath,
+      fileSize,
+      lastIndex,
+      adminAcls,
+      viewAcls,
+      adminAclsGroups,
+      viewAclsGroups)
   }

Review Comment:
   What changed in `MutableAttemptInfo` ?
   Also, why did we pull it out ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] github-actions[bot] closed pull request #40949: [DRAFT][SPARK-23607][CORE] Use HDFS extended attributes to store application summary information in SHS

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #40949: [DRAFT][SPARK-23607][CORE] Use HDFS extended attributes to store application summary information in SHS
URL: https://github.com/apache/spark/pull/40949


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org