gengliangwang commented on code in PR #60681:
URL: https://github.com/apache/spark/pull/60681#discussion_r4621417927
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala:
##########
@@ -128,6 +128,16 @@ 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.
+ */
+ private[sql] lazy val scanLimitListener: ScanLimitListener = {
+ val listener = new ScanLimitListener(sparkContext.cancelJobsWithTag(_, _))
+ sparkContext.listenerBus.addToStatusQueue(listener)
Review Comment:
Done in 5eccf93f1cc7: Moved the listener to a queue of its own
(`listenerBus.addToQueue(listener, "scanLimit")`). It no longer adds work to
the appStatus queue, and the UI listeners can't delay or drop its events. The
SharedState scaladoc says that events dropped by its own queue still weaken the
limit.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -2690,6 +2690,25 @@ 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 " +
+ "SCAN_BYTES_LIMIT_EXCEEDED. This is a best-effort guard rather than a
hard cap. Spark " +
+ "learns how much the tasks of a query have read from the executor
heartbeats " +
+ "(spark.executor.heartbeatInterval) and when a task ends, so a query can
read more " +
+ "than the limit before it is cancelled. Only data sources that report
the bytes they " +
+ "read are limited: file-based sources report the bytes they read from
storage, while " +
+ "sources such as JDBC report none. Reading cached data counts the size
of the cached " +
+ "blocks. Jobs that run outside the execution of a query are not limited,
such as the " +
+ "jobs that infer the schema of a file source while the query is
analyzed, and the jobs " +
+ "that Dataset.toLocalIterator runs as the iterator it returns is
consumed. Streaming " +
Review Comment:
Done in 5eccf93f1cc7: Good catch: `Dataset.rdd` (and `javaToPython`, which
PySpark's `df.rdd` uses) wraps only the creation of the RDD in
`withNewRDDExecutionId`. The doc keeps the general rule (jobs that run outside
the execution of a query are not limited) and now lists the jobs that run on
the RDD `Dataset.rdd` returns as an example, next to schema inference and
`toLocalIterator`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -2690,6 +2690,25 @@ 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 " +
+ "SCAN_BYTES_LIMIT_EXCEEDED. This is a best-effort guard rather than a
hard cap. Spark " +
+ "learns how much the tasks of a query have read from the executor
heartbeats " +
+ "(spark.executor.heartbeatInterval) and when a task ends, so a query can
read more " +
+ "than the limit before it is cancelled. Only data sources that report
the bytes they " +
+ "read are limited: file-based sources report the bytes they read from
storage, while " +
+ "sources such as JDBC report none. Reading cached data counts the size
of the cached " +
Review Comment:
Done in 5eccf93f1cc7: Reworded the doc. Only bytes a task reads through a
Hadoop FileSystem count, as its thread statistics report them: both
`FileScanRDD` and `DataSourceRDD` use `getFSBytesReadOnThreadCallback`. So
connectors with their own storage client report none, and reads on threads a
source starts itself can be missed. On cache hits: counting them isn't the
goal. It is what the task input metric does (`RDD.getOrCompute` adds the cached
block size to `bytesRead`), and the metric can't tell the two apart. The doc
now says a cache read counts even though it reads no storage. Leaving cache
reads out needs a scan-level bytes metric, which I kept out of this PR. I kept
"from its data sources" in the error message because it fits the case the limit
is for, and so does the partition-filter hint.
--
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]