kiszk commented on a change in pull request #24028: [SPARK-26917][SQL] Further
reduce locks in CacheManager
URL: https://github.com/apache/spark/pull/24028#discussion_r268476368
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala
##########
@@ -194,46 +167,36 @@ class CacheManager extends Logging {
private def recacheByCondition(
spark: SparkSession,
condition: CachedData => Boolean): Unit = {
- val needToRecache = scala.collection.mutable.ArrayBuffer.empty[CachedData]
- readLock {
- val it = cachedData.iterator()
- while (it.hasNext) {
- val cd = it.next()
- if (condition(cd)) {
- needToRecache += cd
- }
- }
+ val needToRecache = cachedData.filter(condition)
+ this.synchronized {
+ // Remove the cache entry before creating a new ones.
+ cachedData = cachedData.filterNot(cd => needToRecache.exists(_ eq cd))
Review comment:
I talked with @maropu. Since write to a `volatile` reference is
[atomic](https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.7),
I think that we could remove `this.sychronization` if we would allow this
operation `cachedData.filterNot(cd => needToRecache.exists(_ eq cd))` to run on
multiple threads.
Since the performance bottleneck was in read lock, I do not recommend to
apply this change very soon.
----------------------------------------------------------------
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.
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]