ganeshashree commented on code in PR #60681:
URL: https://github.com/apache/spark/pull/60681#discussion_r4624402394
##########
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:
**Blocking (P1):** After the first limited root execution forces this lazy
listener, the queue stays on LiveListenerBus even after `unregister` removes
the execution from the listener. From then on, unrelated jobs in the same
SparkContext still post every scheduler event to the scanLimit queue even when
no execution is being tracked, so disabled or unset workloads keep paying
overhead that scales with job, task, and heartbeat traffic.
**Recommended change:** Make the scan-limit listener-bus subscription active
only while at least one root execution is registered with a non-negative
maxScanBytes value, removing the listener from the scanLimit queue when the
last limited execution unregisters and re-adding it before a later limited
execution starts.
**Why this works:** Centralize the listener lifecycle behind a synchronized
owner, such as SharedState or the listener wrapper, that pairs registration
with listener-bus add/remove and tracks active registrations so a concurrent
new registration cannot race with last-unregister removal.
**Scope:** Change the scan-limit listener lifecycle and its root-execution
registration path so the dedicated queue exists only for active limited
executions while preserving the existing best-effort accounting semantics.
**Compatibility:** The repair must keep the current best-effort scope: late
or dropped listener events can still weaken the limit, streaming queries remain
excluded, and nested batch executions continue to count against the root
execution.
**Risks:** Removing the listener too early could drop in-flight overage
events beyond the PR's accepted best-effort boundary, so the lifecycle owner
must remove the queue only after the corresponding root execution has completed
its accepted cleanup. Re-adding an existing listener object must avoid
duplicate queue registration if two enabled root executions start concurrently.
**Constraints:** The repair must preserve the dedicated queue isolation
while at least one limited execution is active. The disabled path must retain
the base behavior: no scanLimit queue should receive later scheduler events
when there are no active limited executions.
**Exclusions:**
- This repair does not make the guard a hard cap, wait for all queued task
metrics before a successful query returns, or add a planning-time file-size
check.
**Success:** After the last limited root execution unregisters, later jobs
in the same SparkContext with maxScanBytes unset or negative do not dispatch
scheduler events to a scanLimit listener queue. A later root execution that
enables maxScanBytes can activate the listener again and still cancel
over-limit jobs with the existing nested, retry, and shared-stage accounting
behavior.
**Verification:**
- **Regression:** Exercise one SparkContext that first runs an enabled
maxScanBytes query and then runs later unguarded work; verify that the
scan-limit listener is no longer subscribed to receive the later workload's
scheduler events.
- **Behavior:** Verify that an enabled over-limit batch query still fails
with SCAN_BYTES_LIMIT_EXCEEDED and that a later enabled query after an idle
period can activate the listener again.
- **Inspection:** Inspect the lifecycle owner and confirm listener-bus
add/remove operations are paired with active registration count changes under
one synchronization boundary.
##########
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:
**Nit (P3):** This wording promises SCAN_BYTES_LIMIT_EXCEEDED for any
over-limit query, but the error mapping is narrower: SQLExecution only emits
that condition when the over-limit execution fails through job cancellation,
and it intentionally preserves unrelated failures after an overage. Users
reading the config text could rely on an error condition the implementation
does not always provide.
**Verification:**
- **Inspection:** Inspect the MAX_SCAN_BYTES documentation and confirm the
SCAN_BYTES_LIMIT_EXCEEDED wording is conditional on cancellation by the
scan-limit guard rather than on every over-limit read.
- **Compatibility:** Confirm the repair changes only public documentation
wording and does not change SQLExecution's existing behavior of preserving
unrelated failures after a recorded overage.
--
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]