LuciferYang commented on code in PR #56662:
URL: https://github.com/apache/spark/pull/56662#discussion_r3457315158
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/FlowAnalysis.scala:
##########
@@ -44,17 +44,19 @@ object FlowAnalysis {
confs: Map[String, String],
queryContext: QueryContext,
queryOrigin: QueryOrigin) => {
+ // Flows are resolved in parallel on a shared session, so applying
per-flow confs by mutating
+ // that session would race across flows. Resolve each flow against its
own cloned session
+ // instead, which keeps its confs isolated from other flows and from the
session the pipeline
+ // is run from.
val ctx = FlowAnalysisContext(
allInputs = allInputs,
availableInputs = availableInputs,
queryContext = queryContext,
- spark = SparkSession.active
+ spark = SparkSession.active.cloneSession()
Review Comment:
Good catch - and cloning the whole session turned out to be wrong too: the
resolved DataFrames carried the clone into execution, so e.g. a memory sink
registered its temp view on the clone instead of the run session, which broke
several pipeline suites in CI. I dropped `cloneSession` entirely. Each flow now
clones just the session's `SQLConf` and installs it on the analyzing thread via
`SQLConf.withExistingConf`; analysis runs on the shared session. So there's no
per-flow SessionState/catalog clone anymore - the only per-flow cost is copying
the conf map, which is negligible.
##########
sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/graph/ConnectValidPipelineSuite.scala:
##########
@@ -561,4 +562,43 @@ class ConnectValidPipelineSuite extends PipelineTest with
SharedSparkSession {
s"Flow ${identifier.unquotedString} has the wrong schema"
)
}
+
+ test("per-flow confs are isolated to a per-flow session during analysis") {
Review Comment:
Added one. The new "per-flow confs stay isolated when flows are resolved in
parallel" test resolves several flows concurrently, each setting a different
value for the same conf, with a barrier so they're all mid-analysis at once,
and asserts each flow observes its own value. That's the interleaving that
fails against the old shared-session approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]