gatorsmile commented on a change in pull request #23539: [SPARK-26617][SQL] 
Cache manager locks
URL: https://github.com/apache/spark/pull/23539#discussion_r249334042
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala
 ##########
 @@ -136,21 +137,27 @@ class CacheManager extends Logging {
       spark: SparkSession,
       plan: LogicalPlan,
       cascade: Boolean,
-      blocking: Boolean): Unit = writeLock {
+      blocking: Boolean): Unit = {
     val shouldRemove: LogicalPlan => Boolean =
       if (cascade) {
         _.find(_.sameResult(plan)).isDefined
       } else {
         _.sameResult(plan)
       }
-    val it = cachedData.iterator()
-    while (it.hasNext) {
-      val cd = it.next()
-      if (shouldRemove(cd.plan)) {
-        cd.cachedRepresentation.cacheBuilder.clearCache(blocking)
-        it.remove()
+    val toRemove = mutable.Buffer[CachedData]()
+    readLock {
 
 Review comment:
   The first protected block should be something like:
   
   ```Scala
       writeLock {
         val it = cachedData.iterator()
         while (it.hasNext) {
           val cd = it.next()
           if (cd.sessionUuidOpt == sessionUuidOpt && condition(cd.plan)) {
             needToRecache += cd
             it.remove()
           }
         }
       }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to