DaveDeCaprio commented on a change in pull request #23539: [SPARK-26617][SQL]
Cache manager locks
URL: https://github.com/apache/spark/pull/23539#discussion_r249932736
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala
##########
@@ -160,34 +161,46 @@ class CacheManager extends Logging {
/**
* Tries to re-cache all the cache entries that refer to the given plan.
*/
- def recacheByPlan(spark: SparkSession, plan: LogicalPlan): Unit = writeLock {
+ def recacheByPlan(spark: SparkSession, plan: LogicalPlan): Unit = readLock {
recacheByCondition(spark, _.find(_.sameResult(plan)).isDefined)
}
private def recacheByCondition(
spark: SparkSession,
condition: LogicalPlan => Boolean,
clearCache: Boolean = true): Unit = {
- val it = cachedData.iterator()
val needToRecache = scala.collection.mutable.ArrayBuffer.empty[CachedData]
- while (it.hasNext) {
- val cd = it.next()
- if (condition(cd.plan)) {
- if (clearCache) {
- cd.cachedRepresentation.cacheBuilder.clearCache()
+ writeLock {
+ val it = cachedData.iterator()
+ while (it.hasNext) {
+ val cd = it.next()
+ if (condition(cd.plan)) {
+ if (clearCache) {
+ cd.cachedRepresentation.cacheBuilder.clearCache()
Review comment:
I refactored and I think it makes more sense now.
----------------------------------------------------------------
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]