Skip to content

[WIP] SPARK-2157 Ability to write tight firewall rules for Spark - #1107

Closed
ash211 wants to merge 14 commits into
apache:masterfrom
ash211:SPARK-2157
Closed

ash211 wants to merge 14 commits into
apache:masterfrom
ash211:SPARK-2157

Conversation

@ash211

@ash211 ash211 commented Jun 17, 2014

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SPARK-2157

This pull request adds the ability to specify every port opened by Spark that I could find to configure. Specifically, it adds the following four configuration options:

  • spark.fileserver.port
  • spark.broadcast.port
  • spark.replClassServer.port
  • spark.blockManager.port

Of those options, most will attempt to fall back to the n+1 incremental port if the port is currently in use. This incremental fallback logic is done for :

  • spark.broadcast.port
  • spark.blockManager.port
  • spark.replClassServer.port

But not for spark.fileserver.port

Things still thinking about for this PR:

  • I'm still observing instances of CoarseGrainedExecutorBackend listening on ephemeral ports
  • In earlier documentation spark.driver.port is described as being the way to configure :7077 on Spark Master, and I'm not sure this is the case. If so the same config item is used for multiple things, as it's also the port on which the applications starts listening on Akka.

Many thanks to @epahomov whose work this is based off of.

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished.

@AmplabJenkins

Copy link
Copy Markdown

Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/15851/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"val classServerListenPort: Int" - word "port" make it obvious, that it's Int. There is no need for such specification

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished.

@AmplabJenkins

Copy link
Copy Markdown

Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16258/

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@ash211

ash211 commented Jun 30, 2014

Copy link
Copy Markdown
Contributor Author

With these changes, I think I'm able to make this work for the majority case.

There will still need to be some work done to handle the situation where a Spark application is run on the same machine as a worker though. Currently the application will take the port of an executor and cause the executor on one server to be on port n+1 while all others are on port n. This occurs for spark.fileserver.port and spark.blockManager.port

Fresh cluster, no applications:

$ clear; jps | grep -v ' $' | grep -v 'Jps' | sort ; lsof -i 4tcp -P | grep java | awk '{print "pid", $2, $9}'
85073 Master
85187 Worker
86636 sbt-launch-0.13.2.jar
pid 85073 aash-mbp:7077
pid 85073 *:8080
pid 85073 aash-mbp:7077->aash-mbp:49582
pid 85187 aash-mbp:49581
pid 85187 *:8081
pid 85187 aash-mbp:49582->aash-mbp:7077

The connections can be summarized as:

  • Worker -> Master:7077

After starting spark-shell like this:
./bin/spark-shell --master spark://aash-mbp.local:7077 --driver-java-options "-Dspark.fileserver.port=40010 -Dspark.broadcast.port=40020 -Dspark.replClassServer.port=40030 -Dspark.blockManager.port=40040 -Dspark.driver.port=40050"

$ clear; jps | grep -v ' $' | grep -v 'Jps' | sort ; lsof -i 4tcp -P | grep java | awk '{print "pid", $2, $9}'
85073 Master
85187 Worker
86247 SparkSubmit
86325 CoarseGrainedExecutorBackend
pid 85073 aash-mbp:7077
pid 85073 *:8080
pid 85073 aash-mbp:7077->aash-mbp:49582
pid 85073 aash-mbp:7077->aash-mbp:49932
pid 85187 aash-mbp:49581
pid 85187 *:8081
pid 85187 aash-mbp:49582->aash-mbp:7077
pid 85187 aash-mbp:49581->aash-mbp:49935
pid 86247 *:40030
pid 86247 aash-mbp:40050
pid 86247 *:40040
pid 86247 *:40020
pid 86247 *:40010
pid 86247 *:4040
pid 86247 aash-mbp:49932->aash-mbp:7077
pid 86247 aash-mbp:40050->aash-mbp:49934
pid 86247 aash-mbp:40050->aash-mbp:49937
pid 86325 aash-mbp:49933
pid 86325 aash-mbp:49934->aash-mbp:40050
pid 86325 aash-mbp:49935->aash-mbp:49581
pid 86325 aash-mbp:49936
pid 86325 aash-mbp:49937->aash-mbp:40050
pid 86325 *:40041
pid 86325 *:40011

These are summarized as:

  • Worker:eph -> Master:7077
  • SparkSubmit:eph -> Master:7077
  • Executor:eph -> SparkSubmit:40050
  • Executor:eph -> SparkSubmit:40050 (again?)
  • Worker:eph -> Executor:eph

The outstanding things I'd like to do for this still are:

  • figure out a way to get the conflict of app vs executor on the same server figured out. I think the right way to do this might be to have separate config settings: spark.fileserver.app.port and spark.fileserver.executor.port, and the same for spark.blockManager.port. This would allow ops teams to configure the network activity on the cluster and executor ports separately from dev teams running jobs on the cluster.
  • better logging for port failover, ideally specific to the service name (turn "failed to start service on port X" into "failed to start block manager on port X")

And lower priority:

  • figure out why two connections are made from executor -> app on the app's spark.driver.port rather than just one

Because all the ports being listened on ("*:40010" etc) are specified now though I think this is moving closer to being ready.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished.

@AmplabJenkins

Copy link
Copy Markdown

Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16259/

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. All automated tests passed.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16261/

@pwendell

Copy link
Copy Markdown
Contributor

@ash211 do you mind bringing this up to date? I'd like to do a review and merge in the next few days.

ash211 added 9 commits July 24, 2014 23:08
Fails when running master+worker+executor+shell on the same machine.  I think
the issue is that both the shell and the executor attempt to start a
ConnectionManager, which causes port conflicts.  Solution is to attempt and
increment on BindExceptions
- spark.fileserver.port
- spark.broadcast.port
- spark.replClassServer.port
- spark.blockManager.port

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be called requestedPort to make it a bit more clear?

@pwendell

Copy link
Copy Markdown
Contributor

@ash211 made some small comments but overall looks good. One thing - have you tested this on a cluster? I want to make sure we cover every possible connection here (I wonder if there are some we might have missed). I think the only real way to do it is to totally lock down a cluster and see if Spark can run.

@ash211

ash211 commented Aug 1, 2014

Copy link
Copy Markdown
Contributor Author

I haven't tested this on an actual locked down cluster yet -- it's just
been looking at netstat output so far
On Jul 30, 2014 10:22 PM, "Patrick Wendell" notifications@github.com
wrote:

@ash211 https://github.com/ash211 made some small comments but overall
looks good. One thing - have you tested this on a cluster? I want to make
sure we cover every possible connection here (I wonder if there are some we
might have missed). I think the only real way to do it is to totally lock
down a cluster and see if Spark can run.

—
Reply to this email directly or view it on GitHub
#1107 (comment).

@ash211

ash211 commented Aug 2, 2014

Copy link
Copy Markdown
Contributor Author

Looking at netstat more closely, we realized that there is still a port that's not configurable: the port that the driver connects to the executor on with Akka. The worker connects to its executor on this port as well, but because that's a local connection it's not as important from the firewall perspective. Looking at the master branch now, it also looks like the driverPropsFetcher right before needs a configurable port as well.

https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala#L129

@pwendell

pwendell commented Aug 2, 2014

Copy link
Copy Markdown
Contributor

Yeah good call, we need to cover that one as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do anything I believe

@pwendell

pwendell commented Aug 4, 2014

Copy link
Copy Markdown
Contributor

Hey @ash211 I think @andrewor14 is gonna take a stab at fixing these issues so we can get it merged today. We're passed the window on this release and I want to make sure it goes in so people can test it. We'll include all of your comitts and just add a few changes on top of them.

@ash211

ash211 commented Aug 4, 2014

Copy link
Copy Markdown
Contributor Author

Sounds great -- my apologies for not being on top of responding to the code
review

On Mon, Aug 4, 2014 at 6:31 PM, Patrick Wendell notifications@github.com
wrote:

Hey @ash211 https://github.com/ash211 I think @andrewor14
https://github.com/andrewor14 is gonna take a stab at fixing these
issues so we can get it merged today. We're passed the window on this
release and I want to make sure it goes in so people can test it. We'll
include all of your comitts and just add a few changes on top of them.

—
Reply to this email directly or view it on GitHub
#1107 (comment).

@andrewor14

Copy link
Copy Markdown
Contributor

No problem, thanks for working on this @ash211

asfgit pushed a commit that referenced this pull request Aug 6, 2014
The goal of this PR is to allow users of Spark to write tight firewall rules for their clusters. This is currently not possible because Spark uses random ports in many places, notably the communication between executors and drivers. The changes in this PR are based on top of ash211's changes in #1107.

The list covered here may or may not be the complete set of port needed for Spark to operate perfectly. However, as of the latest commit there are no known sources of random ports (except in tests). I have not documented a few of the more obscure configs.

My spark-env.sh looks like this:
```
export SPARK_MASTER_PORT=6060
export SPARK_WORKER_PORT=7070
export SPARK_MASTER_WEBUI_PORT=9090
export SPARK_WORKER_WEBUI_PORT=9091
```
and my spark-defaults.conf looks like this:
```
spark.master spark://andrews-mbp:6060
spark.driver.port 5001
spark.fileserver.port 5011
spark.broadcast.port 5021
spark.replClassServer.port 5031
spark.blockManager.port 5041
spark.executor.port 5051
```

Author: Andrew Or <andrewor14@gmail.com>
Author: Andrew Ash <andrew@andrewash.com>

Closes #1777 from andrewor14/configure-ports and squashes the following commits:

621267b [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
8a6b820 [Andrew Or] Use a random UI port during tests
7da0493 [Andrew Or] Fix tests
523c30e [Andrew Or] Add test for isBindCollision
b97b02a [Andrew Or] Minor fixes
c22ad00 [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
93d359f [Andrew Or] Executors connect to wrong port when collision occurs
d502e5f [Andrew Or] Handle port collisions when creating Akka systems
a2dd05c [Andrew Or] Patrick's comment nit
86461e2 [Andrew Or] Remove spark.executor.env.port and spark.standalone.client.port
1d2d5c6 [Andrew Or] Fix ports for standalone cluster mode
cb3be88 [Andrew Or] Various doc fixes (broken link, format etc.)
e837cde [Andrew Or] Remove outdated TODOs
bfbab28 [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
de1b207 [Andrew Or] Update docs to reflect new ports
b565079 [Andrew Or] Add spark.ports.maxRetries
2551eb2 [Andrew Or] Remove spark.worker.watcher.port
151327a [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
9868358 [Andrew Or] Add a few miscellaneous ports
6016e77 [Andrew Or] Add spark.executor.port
8d836e6 [Andrew Or] Also document SPARK_{MASTER/WORKER}_WEBUI_PORT
4d9e6f3 [Andrew Or] Fix super subtle bug
3f8e51b [Andrew Or] Correct erroneous docs...
e111d08 [Andrew Or] Add names for UI services
470f38c [Andrew Or] Special case non-"Address already in use" exceptions
1d7e408 [Andrew Or] Treat 0 ports specially + return correct ConnectionManager port
ba32280 [Andrew Or] Minor fixes
6b550b0 [Andrew Or] Assorted fixes
73fbe89 [Andrew Or] Move start service logic to Utils
ec676f4 [Andrew Or] Merge branch 'SPARK-2157' of github.com:ash211/spark into configure-ports
038a579 [Andrew Ash] Trust the server start function to report the port the service started on
7c5bdc4 [Andrew Ash] Fix style issue
0347aef [Andrew Ash] Unify port fallback logic to a single place
24a4c32 [Andrew Ash] Remove type on val to match surrounding style
9e4ad96 [Andrew Ash] Reformat for style checker
5d84e0e [Andrew Ash] Document new port configuration options
066dc7a [Andrew Ash] Fix up HttpServer port increments
cad16da [Andrew Ash] Add fallover increment logic for HttpServer
c5a0568 [Andrew Ash] Fix ConnectionManager to retry with increment
b80d2fd [Andrew Ash] Make Spark's block manager port configurable
17c79bb [Andrew Ash] Add a configuration option for spark-shell's class server
f34115d [Andrew Ash] SPARK-1176 Add port configuration for HttpBroadcast
49ee29b [Andrew Ash] SPARK-1174 Add port configuration for HttpFileServer
1c0981a [Andrew Ash] Make port in HttpServer configurable
(cherry picked from commit 09f7e45)

Signed-off-by: Patrick Wendell <pwendell@gmail.com>
asfgit pushed a commit that referenced this pull request Aug 6, 2014
The goal of this PR is to allow users of Spark to write tight firewall rules for their clusters. This is currently not possible because Spark uses random ports in many places, notably the communication between executors and drivers. The changes in this PR are based on top of ash211's changes in #1107.

The list covered here may or may not be the complete set of port needed for Spark to operate perfectly. However, as of the latest commit there are no known sources of random ports (except in tests). I have not documented a few of the more obscure configs.

My spark-env.sh looks like this:
```
export SPARK_MASTER_PORT=6060
export SPARK_WORKER_PORT=7070
export SPARK_MASTER_WEBUI_PORT=9090
export SPARK_WORKER_WEBUI_PORT=9091
```
and my spark-defaults.conf looks like this:
```
spark.master spark://andrews-mbp:6060
spark.driver.port 5001
spark.fileserver.port 5011
spark.broadcast.port 5021
spark.replClassServer.port 5031
spark.blockManager.port 5041
spark.executor.port 5051
```

Author: Andrew Or <andrewor14@gmail.com>
Author: Andrew Ash <andrew@andrewash.com>

Closes #1777 from andrewor14/configure-ports and squashes the following commits:

621267b [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
8a6b820 [Andrew Or] Use a random UI port during tests
7da0493 [Andrew Or] Fix tests
523c30e [Andrew Or] Add test for isBindCollision
b97b02a [Andrew Or] Minor fixes
c22ad00 [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
93d359f [Andrew Or] Executors connect to wrong port when collision occurs
d502e5f [Andrew Or] Handle port collisions when creating Akka systems
a2dd05c [Andrew Or] Patrick's comment nit
86461e2 [Andrew Or] Remove spark.executor.env.port and spark.standalone.client.port
1d2d5c6 [Andrew Or] Fix ports for standalone cluster mode
cb3be88 [Andrew Or] Various doc fixes (broken link, format etc.)
e837cde [Andrew Or] Remove outdated TODOs
bfbab28 [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
de1b207 [Andrew Or] Update docs to reflect new ports
b565079 [Andrew Or] Add spark.ports.maxRetries
2551eb2 [Andrew Or] Remove spark.worker.watcher.port
151327a [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
9868358 [Andrew Or] Add a few miscellaneous ports
6016e77 [Andrew Or] Add spark.executor.port
8d836e6 [Andrew Or] Also document SPARK_{MASTER/WORKER}_WEBUI_PORT
4d9e6f3 [Andrew Or] Fix super subtle bug
3f8e51b [Andrew Or] Correct erroneous docs...
e111d08 [Andrew Or] Add names for UI services
470f38c [Andrew Or] Special case non-"Address already in use" exceptions
1d7e408 [Andrew Or] Treat 0 ports specially + return correct ConnectionManager port
ba32280 [Andrew Or] Minor fixes
6b550b0 [Andrew Or] Assorted fixes
73fbe89 [Andrew Or] Move start service logic to Utils
ec676f4 [Andrew Or] Merge branch 'SPARK-2157' of github.com:ash211/spark into configure-ports
038a579 [Andrew Ash] Trust the server start function to report the port the service started on
7c5bdc4 [Andrew Ash] Fix style issue
0347aef [Andrew Ash] Unify port fallback logic to a single place
24a4c32 [Andrew Ash] Remove type on val to match surrounding style
9e4ad96 [Andrew Ash] Reformat for style checker
5d84e0e [Andrew Ash] Document new port configuration options
066dc7a [Andrew Ash] Fix up HttpServer port increments
cad16da [Andrew Ash] Add fallover increment logic for HttpServer
c5a0568 [Andrew Ash] Fix ConnectionManager to retry with increment
b80d2fd [Andrew Ash] Make Spark's block manager port configurable
17c79bb [Andrew Ash] Add a configuration option for spark-shell's class server
f34115d [Andrew Ash] SPARK-1176 Add port configuration for HttpBroadcast
49ee29b [Andrew Ash] SPARK-1174 Add port configuration for HttpFileServer
1c0981a [Andrew Ash] Make port in HttpServer configurable
@pwendell

pwendell commented Aug 6, 2014

Copy link
Copy Markdown
Contributor

Hey @ash211 I think this is covered now in #1777. Do you mind closing this issue?

@ash211

ash211 commented Aug 7, 2014

Copy link
Copy Markdown
Contributor Author

Of course. Thanks for getting this in and dealing with the fallout I saw come through

@ash211 ash211 closed this Aug 7, 2014
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
The goal of this PR is to allow users of Spark to write tight firewall rules for their clusters. This is currently not possible because Spark uses random ports in many places, notably the communication between executors and drivers. The changes in this PR are based on top of ash211's changes in apache#1107.

The list covered here may or may not be the complete set of port needed for Spark to operate perfectly. However, as of the latest commit there are no known sources of random ports (except in tests). I have not documented a few of the more obscure configs.

My spark-env.sh looks like this:
```
export SPARK_MASTER_PORT=6060
export SPARK_WORKER_PORT=7070
export SPARK_MASTER_WEBUI_PORT=9090
export SPARK_WORKER_WEBUI_PORT=9091
```
and my spark-defaults.conf looks like this:
```
spark.master spark://andrews-mbp:6060
spark.driver.port 5001
spark.fileserver.port 5011
spark.broadcast.port 5021
spark.replClassServer.port 5031
spark.blockManager.port 5041
spark.executor.port 5051
```

Author: Andrew Or <andrewor14@gmail.com>
Author: Andrew Ash <andrew@andrewash.com>

Closes apache#1777 from andrewor14/configure-ports and squashes the following commits:

621267b [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
8a6b820 [Andrew Or] Use a random UI port during tests
7da0493 [Andrew Or] Fix tests
523c30e [Andrew Or] Add test for isBindCollision
b97b02a [Andrew Or] Minor fixes
c22ad00 [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
93d359f [Andrew Or] Executors connect to wrong port when collision occurs
d502e5f [Andrew Or] Handle port collisions when creating Akka systems
a2dd05c [Andrew Or] Patrick's comment nit
86461e2 [Andrew Or] Remove spark.executor.env.port and spark.standalone.client.port
1d2d5c6 [Andrew Or] Fix ports for standalone cluster mode
cb3be88 [Andrew Or] Various doc fixes (broken link, format etc.)
e837cde [Andrew Or] Remove outdated TODOs
bfbab28 [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
de1b207 [Andrew Or] Update docs to reflect new ports
b565079 [Andrew Or] Add spark.ports.maxRetries
2551eb2 [Andrew Or] Remove spark.worker.watcher.port
151327a [Andrew Or] Merge branch 'master' of github.com:apache/spark into configure-ports
9868358 [Andrew Or] Add a few miscellaneous ports
6016e77 [Andrew Or] Add spark.executor.port
8d836e6 [Andrew Or] Also document SPARK_{MASTER/WORKER}_WEBUI_PORT
4d9e6f3 [Andrew Or] Fix super subtle bug
3f8e51b [Andrew Or] Correct erroneous docs...
e111d08 [Andrew Or] Add names for UI services
470f38c [Andrew Or] Special case non-"Address already in use" exceptions
1d7e408 [Andrew Or] Treat 0 ports specially + return correct ConnectionManager port
ba32280 [Andrew Or] Minor fixes
6b550b0 [Andrew Or] Assorted fixes
73fbe89 [Andrew Or] Move start service logic to Utils
ec676f4 [Andrew Or] Merge branch 'SPARK-2157' of github.com:ash211/spark into configure-ports
038a579 [Andrew Ash] Trust the server start function to report the port the service started on
7c5bdc4 [Andrew Ash] Fix style issue
0347aef [Andrew Ash] Unify port fallback logic to a single place
24a4c32 [Andrew Ash] Remove type on val to match surrounding style
9e4ad96 [Andrew Ash] Reformat for style checker
5d84e0e [Andrew Ash] Document new port configuration options
066dc7a [Andrew Ash] Fix up HttpServer port increments
cad16da [Andrew Ash] Add fallover increment logic for HttpServer
c5a0568 [Andrew Ash] Fix ConnectionManager to retry with increment
b80d2fd [Andrew Ash] Make Spark's block manager port configurable
17c79bb [Andrew Ash] Add a configuration option for spark-shell's class server
f34115d [Andrew Ash] SPARK-1176 Add port configuration for HttpBroadcast
49ee29b [Andrew Ash] SPARK-1174 Add port configuration for HttpFileServer
1c0981a [Andrew Ash] Make port in HttpServer configurable
wangyum added a commit that referenced this pull request May 26, 2023
…ssions (#1107)

* [SPARK-40609][SQL] Casts types according to bucket info for Equality expressions

* Update TypeCoercion.scala
mapr-devops pushed a commit to mapr/spark that referenced this pull request May 8, 2025
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Oct 29, 2026
…ssion (apache#1107)

### What changes were proposed in this pull request?

The date, interval and integer kernels' answer checks now run without a Spark session, through the expression harness that the coverage and TIME suites already use. `VarkaDifferentialSuite` keeps the 27 tests that need a session.

**This PR sits on apache#1106, which sits on apache#1105.** Its own commits are the last two.

- **`VarkaDifferentialHarnessSuite`** holds 68 of the old suite's 94 tests, under their old names, over the same tables. The tables are now SQL `VALUES` with the old nullability: where the old table declared a column nullable that holds no null, an all-null row goes into the `VALUES` and is filtered out again. Without it, Spark would read the column as non-nullable, and the optimizer would rewrite some queries; `coalesce(d, d2)`, for example, would become `d`.
- **`VarkaHarnessCases`** now lets one test run its queries in parts, each with its own table, ANSI mode and emit options, as the old tests set them between queries. Each query states what the old test asserted of the plan and the node's metrics:

  | Expectation | Old assertion |
  |---|---|
  | something fused, and a kernel answered a batch | `checkDifferential(..., expectFused = true)` |
  | something fused | `assertFused` alone |
  | fused whole and served every batch | `numFallbackBatchesDeclined === 0` beside a kernel run |
  | fused whole, and a kernel declined a batch with its own status | `numFallbackBatchesDeclined > 0` |
  | nothing fused | `expectFused = false` |

  Where the old test read verbose `EXPLAIN`, the harness checks the same lines from `VarkaFusionReport`: `"far: residual (day range ["`, `"kernel 2 of 2"` and the others.
- **Two changes to how the harness runs a query:**
  - *Filters:* the filter evaluator is handed only the conjuncts the compiler fuses. That is what `VarkaColumnarRule` hands the Varka node, leaving the rest to a row filter above it. The evaluator compiles only a condition that fuses whole, so without this a filter with one residual conjunct fell back on every batch.
  - *The row consumer:* it now compares only the outputs `projectFused` returns. Projections with residual or forwarded entries therefore run through the row node's path too.
- **`VarkaDifferentialSuite`** keeps what needs a session:
  - the plan around the Varka nodes: a narrowing projection absorbed, a residual conjunct's row filter and the order Spark evaluates conjuncts in, a projection stacked on a filter's compacted batch, the common-expression hoist;
  - the fallback hooks and the metrics they move;
  - AQE, aggregation, the cache's batches, tasks sharing a kernel class, a non-Arrow source, the SQL UI's residual count, Metaspace;
  - the `guardDayProducers=false` test, which asserts only the metric, never the wrong values that configuration produces; the harness compares every answer;
  - the `ILLEGAL_DAY_OF_WEEK` error a user sees. No coverage row raises that condition, so no other session test shows it.
- **`VarkaSharedSessions`** drops the seven fixtures no suite reads any more.
- **`VarkaHarnessParitySuite`** plans every hand-written query of both harness suites in a session, under its part's ANSI mode, and requires each expression to equal the harness's.
- **`skips.tsv`:**
  - 11 lines follow their tests to the new suite.
  - The `arrowBatchSize=1` line for "null-as-false, and the boundary selectivities" is removed. Its reason was the in-memory scan's statistics pruning one-row batches, and the harness has no scan, so the test now passes there.
- **Docs:** `ADDING_AN_EXPRESSION.md` and `docs/sql-varka.md` now point to the harness suite.

### Why are the changes needed?

The suite spent its time on session work. It ran each query through two sessions, sorted the results, and ran the query a second time for the warm cache. It took 66 s at the defaults on the laptop, and 3.66 h of the option matrix's run 40658422887. The checks need only the expressions and the batches.

| Configuration | Before (old suite) | After (harness suite + session suite) |
|---|---|---|
| defaults | 66 s | 4.1 s + 36.7 s |
| `arrowBatchSize=1` | 70 s | 4.6 s + 36.4 s |

Results, with each of the 94 old tests mapped to where its check now lives: `sql/varka/plans/m8/results/VARKA-509-step3b-local.txt`.

### Does this PR introduce _any_ user-facing change?

No. Tests only.

### How was this patch tested?

- All 1,211 tests of the harness and session suites this work touches pass at the defaults, in one JVM. That includes the coverage suites and the 68 new tests.
- I ran the six configurations that have skip lines for these tests locally: `checkIntOverflow=false`, `guardDayProducers=false`, `guardUnderArm=false`, `severalKernels=false`, `arrowBatchSize=1` and `validityByWidth=false`. Each test cancels where its line says, and nothing else fails. The CI matrix covers the other configurations.
- `build/sbt 'sql/testOnly *VarkaDifferentialHarnessSuite'` runs the 68 tests, as `ADDING_AN_EXPRESSION.md` now says.
- The linters pass.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Oct 29, 2026
…aved (apache#1111)

### What changes were proposed in this pull request?

This measures what the previous pull requests saved by checking Varka's answers in a harness without a Spark session instead of through one. The coverage, differential and time-arithmetic suites are measured on the laptop, in the pull request's Build and in the option matrix. The PR also adds the script that reads the CI numbers.

- `sql/varka/plans/m8/results/VARKA-509-step4.txt`:
  - **Laptop, at the defaults:** the suites take 135.8 s where they took 472.2, with 1,211 tests against 1,172.
  - **Pull request's Build:** the Varka jobs spend 399.3 s on them against 1,064.1. The longest sql job takes 24 minutes against 33.
  - **Option matrix:** their configuration-hours fall from 11.96 to 1.61, and the run's suite-hours from 35.30 to 22.61.
  - **Matrix wall time:** it went from 58 minutes to 45, set by the run's longest bin rather than by its total work.
- `dev/varka_matrix_run.py`: one run's cost, from the Actions API and the artifacts the run uploads.
  - For an option-matrix run: its wall time, bins, JVM time, and each suite's hours under the configurations.
  - For a Build: its sql and catalyst test jobs' minutes, and each named suite's seconds, from either the full module jobs or the Varka-scoped jobs.
- The plan marks the task done. The profile after the move, in `VARKA-510-planning-local.txt` (merged with apache#1108), shows where the time goes now.

### Why are the changes needed?

The move had to be measured against the cost it set out to cut, and the measurement found two costs that affect the next steps:
- **The reach recording.** The Build records which configurations change what each test compiles, so the matrix can skip unchanged tests. That recording doubles a harness suite's time in the Build: 45 s plain against 92 s recording for the three harness suites on the laptop. We keep it, because it lets the matrix skip what a configuration doesn't change.
- **Query planning.** With the session gone, the harness's largest cost is Spark's analyzer and optimizer, planning one tiny query at a time.

The two "before" Builds were checked for comparability. The first Build of step 1 predates the reach recording, the three-job split and the sort-page fix, so it isn't used. The before is step 1's last Build, which has all three, like the after.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

- `dev/varka_matrix_run.py --self-test`; ruff check and ruff format.
- `dev/varka_plan_lint.py --check` and `dev/varka_quote_check.py` are clean.
- The Java and Scala linters don't apply: this changes no Java or Scala.
- **No option matrix is dispatched.** This PR changes no code the matrix runs, and apache#1107's matrix (run 40855387471) passed on the same tree of code.

This PR is stacked on apache#1107. Until apache#1107 merges, its diff also shows apache#1107's files.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants