Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-26586][SS] Fix race condition that causes streams to run with unexpected confs #23513

Closed
wants to merge 3 commits into from
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 @@ -181,6 +181,9 @@ abstract class StreamExecution(
lazy val streamMetrics = new MetricsReporter(
this, s"spark.streaming.${Option(name).getOrElse(id)}")

/** Isolated spark session to run the batches with. */
private val sparkSessionForStream = sparkSession.cloneSession()

/**
* The thread that runs the micro-batches of this stream. Note that this thread must be
* [[org.apache.spark.util.UninterruptibleThread]] to workaround KAFKA-1894: interrupting a
Expand Down Expand Up @@ -270,8 +273,6 @@ abstract class StreamExecution(
// force initialization of the logical plan so that the sources can be created
logicalPlan

// Isolated spark session to run the batches with.
val sparkSessionForStream = sparkSession.cloneSession()
// Adaptive execution can change num shuffle partitions, disallow
sparkSessionForStream.conf.set(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key, "false")
// Disable cost-based join optimization as we do not want stateful operations to be rearranged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.streaming.test

import java.io.File
import java.util.ConcurrentModificationException
import java.util.Locale
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -651,4 +652,27 @@ class DataStreamReaderWriterSuite extends StreamTest with BeforeAndAfter {

LastOptions.clear()
}

test("SPARK-26586: Streams should have isolated confs") {
import testImplicits._
val input = MemoryStream[Int]
input.addData(1 to 10)
spark.conf.set("testKey1", 0)
val queries = (1 to 10).map { i =>
spark.conf.set("testKey1", i)
input.toDF().writeStream
.foreachBatch { (df: Dataset[Row], id: Long) =>
val v = df.sparkSession.conf.get("testKey1").toInt
if (i != v) {
throw new ConcurrentModificationException(s"Stream $i has the wrong conf value $v")
}
}
.start()
}
try {
queries.foreach(_.processAllAvailable())
} finally {
queries.foreach(_.stop())
}
}
}