Skip to content

Commit 247a089

Browse files
juliuszsompolskicloud-fan
authored andcommitted
[SPARK-22938] Assert that SQLConf.get is accessed only on the driver.
## What changes were proposed in this pull request? Assert if code tries to access SQLConf.get on executor. This can lead to hard to detect bugs, where the executor will read fallbackConf, falling back to default config values, ignoring potentially changed non-default configs. If a config is to be passed to executor code, it needs to be read on the driver, and passed explicitly. ## How was this patch tested? Check in existing tests. Author: Juliusz Sompolski <[email protected]> Closes #20136 from juliuszsompolski/SPARK-22938.
1 parent a6fc300 commit 247a089

File tree

1 file changed

+9
-1
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/internal

1 file changed

+9
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import scala.util.matching.Regex
2727

2828
import org.apache.hadoop.fs.Path
2929

30+
import org.apache.spark.{SparkContext, SparkEnv}
3031
import org.apache.spark.internal.Logging
3132
import org.apache.spark.internal.config._
3233
import org.apache.spark.network.util.ByteUnit
3334
import org.apache.spark.sql.catalyst.analysis.Resolver
3435
import org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator
36+
import org.apache.spark.util.Utils
3537

3638
////////////////////////////////////////////////////////////////////////////////////////////////////
3739
// This file defines the configuration options for Spark SQL.
@@ -70,7 +72,7 @@ object SQLConf {
7072
* Default config. Only used when there is no active SparkSession for the thread.
7173
* See [[get]] for more information.
7274
*/
73-
private val fallbackConf = new ThreadLocal[SQLConf] {
75+
private lazy val fallbackConf = new ThreadLocal[SQLConf] {
7476
override def initialValue: SQLConf = new SQLConf
7577
}
7678

@@ -1087,6 +1089,12 @@ object SQLConf {
10871089
class SQLConf extends Serializable with Logging {
10881090
import SQLConf._
10891091

1092+
if (Utils.isTesting && SparkEnv.get != null) {
1093+
// assert that we're only accessing it on the driver.
1094+
assert(SparkEnv.get.executorId == SparkContext.DRIVER_IDENTIFIER,
1095+
"SQLConf should only be created and accessed on the driver.")
1096+
}
1097+
10901098
/** Only low degree of contention is expected for conf, thus NOT using ConcurrentHashMap. */
10911099
@transient protected[spark] val settings = java.util.Collections.synchronizedMap(
10921100
new java.util.HashMap[String, String]())

0 commit comments

Comments
 (0)