zhouyifan279 commented on code in PR #41105:
URL: https://github.com/apache/spark/pull/41105#discussion_r1191865529


##########
core/src/main/scala/org/apache/spark/deploy/history/ApplicationCache.scala:
##########
@@ -48,11 +48,28 @@ private[history] class ApplicationCache(
     val retainedApplications: Int,
     val clock: Clock) extends Logging {
 
+  /**
+   * Keep track of SparkUIs in [[ApplicationCache#appCache]] and SparkUIs 
removed from
+   * [[ApplicationCache#appCache]] but not detached yet.
+   */
+  private val loadedApps = new ConcurrentHashMap[CacheKey, CountDownLatch]()
+
   private val appLoader = new CacheLoader[CacheKey, CacheEntry] {
 
     /** the cache key doesn't match a cached entry, or the entry is 
out-of-date, so load it. */
     override def load(key: CacheKey): CacheEntry = {
-      loadApplicationEntry(key.appId, key.attemptId)
+      // Ensure old SparkUI has been detached before loading new one.
+      val removalLatch = loadedApps.get(key)
+      if (removalLatch != null) {
+        // Old SparkUI is in the middle of detaching.
+        // Waiting 10 seconds should be enough since detaching usually takes 
less than 1 second.
+        if (!removalLatch.await(10, TimeUnit.SECONDS)) {

Review Comment:
   > removal essentially can be held up by a few synchronized blocks
   
   Can you provide an example? From what I know, removal are mostly triggered 
by `ApplicationCache#withSparkUI`, which only causes http requests to the same 
<appId, attemptId> being blocked.
   
   > do we have any stats on how long this takes ? How did we end up with < 1 s 
estimate ?
   
   There is no heavy operation in the code path of 
`ApplicationCache#removalListener#onRemoval`.
   The most heavy operation is deleting app data directory on disk.
   I created 10,000 files in a directory and use `rm -rf` to delete it. 
Deletion takes 0.339s.
   So I think 1 seconds should be enough.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to