Skip to content

Commit

Permalink
Clone properties only for SQL for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Or committed Sep 14, 2015
1 parent 0b7e5ab commit 4435db7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,12 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
protected[spark] val localProperties = new InheritableThreadLocal[Properties] {
override protected def childValue(parent: Properties): Properties = {
// Note: make a clone such that changes in the parent properties aren't reflected in
// the those of the children threads, which has confusing semantics (SPARK-10564).
SerializationUtils.clone(parent).asInstanceOf[Properties]
// the those of the children threads, which has confusing semantics (SPARK-10563).
if (conf.get("spark.localProperties.clone", "false").toBoolean) {
SerializationUtils.clone(parent).asInstanceOf[Properties]
} else {
new Properties(parent)
}
}
override protected def initialValue(): Properties = new Properties()
}
Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/org/apache/spark/ThreadingSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class ThreadingSuite extends SparkFunSuite with LocalSparkContext with Logging {

test("mutation in parent local property does not affect child (SPARK-10563)") {
sc = new SparkContext("local", "test")
sc.conf.set("spark.localProperties.clone", "true")
val originalTestValue: String = "original-value"
var threadTestValue: String = null
sc.setLocalProperty("test", originalTestValue)
Expand Down
6 changes: 6 additions & 0 deletions sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class SQLContext(@transient val sparkContext: SparkContext)
sparkContext.addSparkListener(listener)
sparkContext.ui.foreach(new SQLTab(this, _))

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

/**
* Set Spark SQL configuration properties.
*
Expand Down

0 comments on commit 4435db7

Please sign in to comment.