Skip to content

Commit 4435db7

Browse files
author
Andrew Or
committed
Clone properties only for SQL for backward compatibility
1 parent 0b7e5ab commit 4435db7

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,12 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
351351
protected[spark] val localProperties = new InheritableThreadLocal[Properties] {
352352
override protected def childValue(parent: Properties): Properties = {
353353
// Note: make a clone such that changes in the parent properties aren't reflected in
354-
// the those of the children threads, which has confusing semantics (SPARK-10564).
355-
SerializationUtils.clone(parent).asInstanceOf[Properties]
354+
// the those of the children threads, which has confusing semantics (SPARK-10563).
355+
if (conf.get("spark.localProperties.clone", "false").toBoolean) {
356+
SerializationUtils.clone(parent).asInstanceOf[Properties]
357+
} else {
358+
new Properties(parent)
359+
}
356360
}
357361
override protected def initialValue(): Properties = new Properties()
358362
}

core/src/test/scala/org/apache/spark/ThreadingSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class ThreadingSuite extends SparkFunSuite with LocalSparkContext with Logging {
214214

215215
test("mutation in parent local property does not affect child (SPARK-10563)") {
216216
sc = new SparkContext("local", "test")
217+
sc.conf.set("spark.localProperties.clone", "true")
217218
val originalTestValue: String = "original-value"
218219
var threadTestValue: String = null
219220
sc.setLocalProperty("test", originalTestValue)

sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class SQLContext(@transient val sparkContext: SparkContext)
7878
sparkContext.addSparkListener(listener)
7979
sparkContext.ui.foreach(new SQLTab(this, _))
8080

81+
// Execution IDs go through SparkContext's local properties, which are not safe to use with
82+
// fork join pools by default. In particular, even after a child thread is spawned, if the
83+
// parent sets a property the value may be reflected in the child. This leads to undefined
84+
// consequences such as SPARK-10548, so we should just clone the properties instead to be safe.
85+
sparkContext.conf.set("spark.localProperties.clone", "true")
86+
8187
/**
8288
* Set Spark SQL configuration properties.
8389
*

0 commit comments

Comments
 (0)