attilapiros commented on a change in pull request #24178: 
[SPARK-25196][SQL][FOLLOWUP] Add synchronized for 
InMemoryRelation.statsOfPlanToCache
URL: https://github.com/apache/spark/pull/24178#discussion_r268317291
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala
 ##########
 @@ -163,12 +161,15 @@ class CacheManager extends Logging {
     val relation = cachedData.cachedRepresentation
     val (rowCount, newColStats) =
       CommandUtils.computeColumnStats(sparkSession, relation, column)
-    val oldStats = relation.statsOfPlanToCache
-    val newStats = oldStats.copy(
-      rowCount = Some(rowCount),
-      attributeStats = AttributeMap((oldStats.attributeStats ++ 
newColStats).toSeq)
-    )
-    relation.statsOfPlanToCache = newStats
+
+    relation.synchronized {
 
 Review comment:
   I would move this logic into the class `InMemoryRelation`. Like:
   
   ```scala
   def updateStats(rowCount: Long, newColStats: Map[Attribute, ColumnStat]): 
Unit = synchronized {
       val newStats = statsOfPlanToCache.copy(
         rowCount = Some(rowCount),
         attributeStats = AttributeMap((statsOfPlanToCache.attributeStats ++ 
newColStats).toSeq)
       )
       statsOfPlanToCache = newStats
     }
   ```
   
   This way both the write and the `synchronized` is in the member function of 
the `InMemoryRelation` (I think it is bit more readable). What is your opinion?
   
   

----------------------------------------------------------------
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]

Reply via email to