gengliangwang commented on code in PR #60681:
URL: https://github.com/apache/spark/pull/60681#discussion_r4624455852
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala:
##########
@@ -128,6 +128,18 @@ private[sql] class SharedState(
statusStore
}
+ /**
+ * The listener that enforces `spark.sql.execution.maxScanBytes`. It is
created, and starts to
+ * receive events, when the first query with a limit runs. It has a queue of
its own on the
+ * listener bus, so that it does not slow down the listeners of the UI and
they do not delay or
+ * drop its events. The events that its own queue drops when it is full
still weaken the limit.
+ */
+ private[sql] lazy val scanLimitListener: ScanLimitListener = {
+ val listener = new ScanLimitListener(sparkContext.cancelJobsWithTag(_, _))
+ sparkContext.listenerBus.addToQueue(listener, "scanLimit")
Review Comment:
I'd rather keep the subscription. Apps that never set the limit don't create
the queue at all, because it's a lazy val. Once it exists, the idle cost per
event is one enqueue plus a dispatch that returns at `if (executions.isEmpty)
return` at the top of every handler in ScanLimitListener. The `streams` queue
already works this way: StreamingQueryListenerBus joins it when a session's
StreamingQueryManager is created (StreamingQueryListenerBus.scala:48) and never
leaves, whether or not any streaming query is running. Adding and removing the
listener per execution would cost more than it saves.
LiveListenerBus.removeListener stops a queue once it is empty
(LiveListenerBus.scala:110-123). AsyncEventQueue.stop then joins the dispatch
thread until the queue drains, with no timeout by default
(spark.scheduler.listenerbus.exitTimeout = 0; AsyncEventQueue.scala:139-166).
So the last limited query would block in its finally block until that queue
drains, and the next limited query would sta
rt a new dispatch thread. A session that sets the limit for every query would
pay that on each one, plus a lock that ties register/unregister to the bus
calls. I've updated the SharedState comment to say the listener stays
subscribed until the SparkContext stops and that its handlers return at once
while no query has a limit.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -2690,6 +2690,32 @@ object SQLConf {
.booleanConf
.createWithDefault(true)
+ val MAX_SCAN_BYTES = buildConf("spark.sql.execution.maxScanBytes")
+ .doc("The maximum number of bytes a query may read from its data sources,
including in " +
+ "its subqueries. A query that reads more is cancelled and fails with " +
Review Comment:
Done in 169f95a45904: Reworded the doc: once Spark learns a query read more,
it cancels the query's jobs, and the query fails with SCAN_BYTES_LIMIT_EXCEEDED
unless it has already finished or it fails with another error.
--
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]