Repository navigation
[SPARK-2715] ExternalAppendOnlyMap adds max limit of times and max limit of disk bytes written for spilling - #1618
YanTangZhai wants to merge 8 commits into
Conversation
…mit of disk bytes written for spilling
|
Can one of the admins verify this patch? |
|
add to whitelist |
|
@YanTangZhai What is the purpose for this? My biggest concern is that this will fail an application that is running perfectly fine unless we set the max for both configs fairly high, at which point we will rarely hit the limit. |
|
QA tests have started for PR 1618. This patch merges cleanly. |
|
QA results for PR 1618: |
|
Hi @andrewor14 The default values of the two max limits are zero, which does not change the original operating mode and does not fail an application that is running perfectly fine. If some application has skew data which we don't expect, it will run for a very long time. In contrast, we want this application fail fast by setting some max limit more than zero. |
…d max limit of disk bytes written for spilling" This reverts commit 3fc6011.
|
QA tests have started for PR 1618. This patch merges cleanly. |
|
QA tests have started for PR 1618. This patch merges cleanly. |
|
QA results for PR 1618: |
|
QA results for PR 1618: |
|
@YanTangZhai Thanks for your PR, but I'm still not sure if we want this feature. If the data has a lot of skew then the user can look at the logs to figure that out, since we log how many times we have spilled so far. Some applications do actually spill many times. Imagine if you have a huge dataset and somewhat beefy nodes. Every time you spill you're actually doing real work, but simply by virtue of the large scale of the data your application might die if you spill too many times. This is an unexpected behavior for these applications, and we may kill them after many hours of execution on false alarm. Do you see my point? |
|
@andrewor14 Yeah, I see. I will close the PR. If needed, it could be reopened. Thank you very much. |
…apache#1626) <!-- title: [VARKA-611] Add a magnitude pre-check for the checked BIGINT multiply --> ### What changes were proposed in this pull request? An ANSI or TRY `BIGINT` multiply declines when the bounds of its operands do not rule out overflow. It then runs on the row engine. This PR adds a pre-check in double lanes, behind an option that is off by default, so we can measure it against the decline on each host. - New IR node `GuardedProduct(left, right)`. A batch declines (status `INT_OVERFLOW`) when a live lane has `|(double) a * (double) b| >= 2^62`. The row engine then raises or returns null on the rows that overflow. - The test is safe: no overflowing row passes. - New emit option `checkedLongMultiply`: `BOUND_ONLY` (default, today's decline), `MAGNITUDE`, `BY_HOST`. - The fuzzer draws the node. The benchmark has a third arm and one new section. <details> <summary>Measured baseline, the node, the option and the other changes</summary> Today, an ANSI or TRY `BIGINT` multiply declines when the bounds of its operands do not rule out overflow (`l * m` over two columns, `try_multiply(l, m)`). It runs on the row engine. Its wrapping twin fuses whole. On the EPYC runner at 256 bits, the checked products tie the row path at 1.0X. In LEGACY, `l * 3` runs 6.6X and `l * m` runs 8.0X (`sql/core/benchmarks/VarkaBigintArithmeticBaselineBenchmark-jdk25-runner-epyc7763-results.txt`). This PR adds the second of the three forms that `VARKA-104.md` 3.3 lists: a pre-check in double lanes. It is an option, off by default, so we can measure it against the decline on each host. - New IR node `GuardedProduct(left, right)` on the long lane. Its value is the wrapping product `a * b`. A batch declines (status `INT_OVERFLOW`) when a live lane has `|(double) a * (double) b| >= 2^62`. The row engine then raises an error under ANSI, or returns null under TRY, on the rows that overflow. - The kernel converts both operands to double (one `convertShape` at emit level 3, the exact `XOR_SPLIT` form below it), multiplies, clears the sign bit, and compares the bits as longs with the bits of `2^62`. - The test is safe: a product that overflows a long is at least `2^63`, far past the bound plus the rounding error. So no overflowing row passes. A batch that declines but held no overflow is only answered by the row engine. - The reference evaluator runs the same double test in Java, so the reference and the kernel decline the same batches. - The node is not a mode of `IntArith`. An `IntArith(MUL, FAIL)` lowered this way would decline batches that its reference (`Math.multiplyExact`) answers. - New emit option `checkedLongMultiply` (reason `MACHINE`): `BOUND_ONLY` (default, today's decline), `MAGNITUDE`, `BY_HOST`. `MAGNITUDE` builds a `GuardedProduct` in a projection where `cannotOverflow` fails, at an emit level that lowers the conversion (`DeclineSink.guardsLongProducts`). `BY_HOST` does this on x86 at levels 2 and 3 only, and keeps the decline elsewhere (Arm included, where it is not measured). A filter condition and the unnamed default level keep the decline. The node is refused at the unnamed level with the reason `CONVERSION`. - Every exhaustive switch over the IR knows the new node. - The fuzzer draws the node on its own seed (`GUARDED_PRODUCT_FUZZ_SEED`) at levels 2 and 3 in turn. It holds the status to `VarkaGuardSpecs` and an answered batch to the reference. - `VarkaBigintArithmeticBaselineBenchmark` has a third arm, `varka on, B (checkedLongMultiply=MAGNITUDE)`, and one new section that prices the decline (`l * m, ANSI, products near 2^62`). </details> ### Why are the changes needed? Whether the pre-check beats the decline depends on the host. The prediction, recorded before the run, is that it loses at 128 bits, and may win at AVX-512 and on the AVX2 of the EPYC at 256 bits. We can choose a default for each host only from the readings of the runners. <details> <summary>More on the reason</summary> Whether the pre-check beats the decline depends on the host. The prediction, recorded before the run, is that it loses at 128 bits, and may win at AVX-512 and on the AVX2 of the EPYC at 256 bits (`VARKA-611.md` 6.1). We can choose a default for each host only from the readings of the runners. For the readings, the form must exist behind an option that changes nothing by default. I built `BY_HOST` now so that one commit can name the winning levels later. It is not the default. </details> ### Does this PR introduce _any_ user-facing change? No. The option is `BOUND_ONLY` by default, so every session compiles and answers as before. No session configuration sets it. ### How was this patch tested? On the laptop (AVX-512, 256-bit datapath), on 22 November 2026, at the head after the merge of `origin/master`: - Regeneration moved nothing. Push check, Error Prone, `lint-scala`, the catalyst suites and the sql queries suite (2 tests) passed. The queries suite first failed on its own expectation, not the node. I fixed the suite. - After a later merge of `origin/master`, I ran only the push check again: 190 ok, 0 failed, 5 cancelled. I did not repeat the other runs. - Not run: the benchmark on any host (the runners must read it), a CI Build, and the option matrix. - Option matrix run 45158540579 failed `VarkaBigIntConformanceSuite` under `useAVX=2` with `checkedLongMultiply=MAGNITUDE` and `BY_HOST`: the registers describe the defaults, so the fused multiply read as drift. The check now asks the options, as the compiler does, and holds each batch to the pre-check's verdict; `dev/varka_matrix.sh` passes both configurations and the defaults (23 November 2026). <details> <summary>Full test record and the queries-suite failure</summary> On the laptop (AVX-512, 256-bit datapath), one sbt at a time, `SPARK_LOCAL_IP=127.0.0.1`, on 22 November 2026, at the head of the branch after the merge of `origin/master`: - `dev/varka_regen_generated.sh --all`: nothing moved. - `python3 dev/varka_push_check.py` passed. Its matrix ran 13 suites with the defaults. - `dev/varka_errorprone.sh` and `dev/lint-scala` passed. - `build/sbt 'catalyst/testOnly *VarkaEmitCostSuite *VarkaEmitterBudgetSuite *VarkaEmitterLongLaneSuite *VarkaIrFuzzSuite *VarkaLaneTypeSuite *VarkaRangeAnalysisSuite *VarkaReproductionSuite *VarkaWithChildrenSuite'` passed. The fuzz suite runs the guarded draw at levels 2 and 3. - `build/sbt 'sql/testOnly *VarkaBigintArithmeticBaselineQueriesSuite'` passed (2 tests). After that, `origin/master` moved to `0378c696c3a` (apache#1618, apache#1620: a fix of the conjunct order rule, and a results-only commit). I merged it without conflict. I ran only the push check again on that merge. It passed (13 suites, the defaults, 190 ok, 0 failed, 5 cancelled). I did not repeat the other runs on it. The queries suite first failed on the B arm of the benchmark. `l * 3, ANSI, no nulls` planned `NONE`, and the suite expected `WHOLE`. The cause was the expectation of the suite, not the node. The shared test sessions pin `spark.sql.codegen.varka.emit.useAVX=-1`, the unnamed level. There, B declines by design, because the kernel plan refuses the long-to-double conversion. The sessions of the benchmark use the named level of the host. The suite now checks both. Under `MAGNITUDE` at the unnamed level, a section keeps its class (B declines like A). At level 2, the B arm plans `WHOLE` (`NONE` where the host declines two-lane checks). Not run: the benchmark on any host (the runners must read it), a CI Build, and the option matrix. </details> ### Review `/code-review high`: 0 important findings. Five nits are left. Two are open limits: the benchmark results files are stale until the runner readings land, and the `BY_HOST` level set is provisional. <details> <summary>Earlier review and the nit list</summary> `/code-review high` ran on 22 November 2026 on `varka-611-guarded-product-r` in `/home/max/proj/varka-611w` (merge base `96f7ff5402b`). It found no important defect. An earlier `/code-review medium` found two defects. I fixed both: - A misplaced brace in the constructor of `VarkaEmitOptions`. - A `longValueExact` in the guard spec over operands whose wrapping value can leave the long range. Five nits are left as they are: - The `PLAN.md` status cell of row 611 still listed the decline section as left. Fixed on 23 November 2026. - The results files of the benchmark are not regenerated for the two new columns and the third arm. The readings of the runners are owed, and the file is stale until they land. - At the unnamed level, the refusal of `GuardedProduct` in the kernel plan only guards hand-built trees, because the compiler never builds one there. - The level set of `BY_HOST` is provisional until the readings narrow it. - The guarded fuzz draw runs level-3 kernels on AVX2 hosts through the Java fallback of the Vector API. This is correct but slow. </details> ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Sonnet 5.5, Claude Opus 5.5)
ExternalAppendOnlyMap adds max limit of times and max limit of disk bytes written for spilling. Therefore, some task could be let fail fast instead of running for a long time if it has data skew.