Skip to content

Commit f34b872

Browse files
bersprocketscloud-fan
authored andcommitted
[SPARK-26851][SQL] Fix double-checked locking in CachedRDDBuilder
## What changes were proposed in this pull request? According to Brian Goetz et al in Java Concurrency in Practice, the double checked locking pattern has worked since Java 5, but only if the resource is declared volatile: > Subsequent changes in the JMM (Java 5.0 and later) have enabled DCL to work if resource is made volatile, and the performance impact of this is small since volatile reads are usually only slightly more expensive than nonvolatile reads. CachedRDDBuilder. cachedColumnBuffers and CachedRDDBuilder.clearCache both use DCL to manage the resource ``_cachedColumnBuffers``. The missing ingredient is that ``_cachedColumnBuffers`` is not volatile. Because of this, clearCache may see ``_cachedColumnBuffers`` as null, when in fact it is not, and therefore fail to un-cache the RDD. There may be other, more subtle bugs due to visibility issues. To avoid these issues, this PR makes ``_cachedColumnBuffers`` volatile. ## How was this patch tested? - Existing SQL unit tests - Existing pyspark-sql tests Closes #23768 from bersprockets/SPARK-26851. Authored-by: Bruce Robbins <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 94ab490 commit f34b872

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryRelation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ case class CachedRDDBuilder(
4949
storageLevel: StorageLevel,
5050
@transient cachedPlan: SparkPlan,
5151
tableName: Option[String])(
52-
@transient private var _cachedColumnBuffers: RDD[CachedBatch] = null) {
52+
@transient @volatile private var _cachedColumnBuffers: RDD[CachedBatch] = null) {
5353

5454
val sizeInBytesStats: LongAccumulator = cachedPlan.sqlContext.sparkContext.longAccumulator
5555

0 commit comments

Comments
 (0)