Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private[sql] class SharedState(
* A status store to query SQL status/metrics of this Spark application, based on SQL-specific
* [[org.apache.spark.scheduler.SparkListenerEvent]]s.
*/
val statusStore: SQLAppStatusStore = {
lazy val statusStore: SQLAppStatusStore = {
val kvStore = sparkContext.statusStore.store.asInstanceOf[ElementTrackingStore]
val listener = new SQLAppStatusListener(conf, kvStore, live = true)
sparkContext.listenerBus.addToStatusQueue(listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,35 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach wit
SparkSession.clearActiveSession()
SparkSession.clearDefaultSession()
assert(postFirstCreation == postSecondCreation)
context.stop()
}

test("SPARK-32165: Ensure Spark only initiates SharedState once across SparkSessions") {
val conf = new SparkConf()
.setMaster("local")
.setAppName("test-app-SPARK-32165-1")
val context = new SparkContext(conf)
SparkSession
.builder()
.master("local")
.getOrCreate()
.sessionState // this touches the sessionState
val postFirstCreation = context.listenerBus.listeners.size()
SparkSession.clearActiveSession()
SparkSession.clearDefaultSession()

SparkSession
.builder()
.sparkContext(context)
.master("local")
.getOrCreate()
.sessionState // this touches the sessionState
val postSecondCreation = context.listenerBus.listeners.size()
SparkSession.clearActiveSession()
SparkSession.clearDefaultSession()

// minus 1 to account for ExecutionListenerBus
assert(postFirstCreation == postSecondCreation - 1)
}

test("SPARK-31532: should not propagate static sql configs to the existing" +
Expand Down