Skip to content

[SPARK-2460] Optimize SparkContext.hadoopFile api - #1385

Closed
scwf wants to merge 9 commits into
apache:masterfrom
scwf:kasi
Closed

scwf wants to merge 9 commits into
apache:masterfrom
scwf:kasi

Conversation

@scwf

@scwf scwf commented Jul 12, 2014

Copy link
Copy Markdown
Contributor

1 use SparkContext.hadoopRDD() instead of instantiate HadoopRDD directly in SparkContext.hadoopFile.
SparkContext.hadoopRDD() Add necessary security credentials to the JobConf before broadcasting it.

2 broadcast jobConf in HadoopRDD, not Configuration. this will resolve the dead lock issue----
now HadoopRDD broadcast Configuration and in each task (compute method) to get jobConf
then the lock of
conf.synchronized {
val newJobConf = new JobConf(conf)
initLocalJobConfFuncOpt.map(f => f(newJobConf))
HadoopRDD.putCachedMetadata(jobConfCacheKey, newJobConf)
newJobConf
}
will conflict with hadoop version fix Hadoop-10456:

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
synchronized(Configuration.class) {
REGISTRY.put(this, null);
}

we can reproduce the bug like this:
hadoop version 2.4.1
spark master branch

hql("SELECT t1.a, t1.b, t1.c FROM table_A t1 JOIN table_A t2 ON (t1.a = t2.a)")

@scwf scwf changed the title Optimize SparkContext.hadoopFile api [SPARK-2460] Optimize SparkContext.hadoopFile api Jul 12, 2014
@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

@rxin

rxin commented Jul 13, 2014

Copy link
Copy Markdown
Contributor

Thanks for submitting the pull request.

Did I read this correctly? The master branch deadlocks? If yes, we should file a JIRA for that also and make that more clear. If it is simply about optimizing an API to reduce code, it is a much lower priority issue. If it deadlocks, this needs to be a BLOCKER.

@aarondav

Copy link
Copy Markdown
Contributor

Is this related to the other conf-related concurrency issue that was fixed recently? #1273

@scwf

scwf commented Jul 14, 2014

Copy link
Copy Markdown
Contributor Author

@rxin and @aarondav, yeah ,the master branch deadlocks, it seems locks of #1273 and Hadoop-10456 lead to the problem. when run hivesql self join sql--- hql("SELECT t1.a, t1.b, t1.c FROM table_A t1 JOIN table_A t2 ON (t1.a = t2.a)"), the program stucks.

i think clean SparkContext.hadoopFile api is a better way for fix it. in this way, we do not need the lock in
#1273

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.

Do we still need this check? I think this may have been the only place we put the JobConf inside the cache.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, there is no need to cache the jobconf if it is in broadcast

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.

yes,i agree with you. broadcastedConf is cached by blockManager in Broadcast

@scwf scwf closed this Aug 10, 2014
@scwf
scwf deleted the kasi branch August 22, 2014 15:22
kazuyukitanimura added a commit to kazuyukitanimura/spark that referenced this pull request Aug 10, 2022
…dd/drop partition command' (apache#1385)

### What changes were proposed in this pull request?
https://github.com/apache/spark/blob/cbffc12f90e45d33e651e38cf886d7ab4bcf96da/sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala#L979
It should be `partDir2` instead of `partDir1`. Looks like it is a copy paste bug.

### Why are the changes needed?
Due to this test bug, the drop command was dropping a wrong (`partDir1`) underlying file in the test.

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

### How was this patch tested?
Added extra underlying file location check.

Closes apache#36075 from kazuyukitanimura/SPARK-38786.

Authored-by: Kazuyuki Tanimura <ktanimura@apple.com>
Signed-off-by: Chao Sun <sunchao@apple.com>
github-actions Bot pushed a commit to MaxGekk/spark that referenced this pull request Nov 7, 2026
…ache#1385)

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

`CAST(l AS DOUBLE)` and `CAST(l AS FLOAT)` over a `BIGINT` now compile into the Varka vector kernel where the emit level assures AVX512DQ. Before, every `BIGINT` source to a floating type declined and Spark's row engine answered it.

**Why a level.** On x86, the Vector API's `L2D` and `L2F` become instructions only with AVX512DQ; without it they run as a scalar Java loop inside the vector kernel, slower than the row path. HotSpot clears AVX512DQ below `UseAVX=3`, so the emit level `useAVX` decides. The kernel plan now declines these two conversions where `VarkaEmitOptions.convertsMayFallBack()` holds: a level below 3, and the unknown level that the defaults and an unset session carry. `convertsFallBack()`, which picks the 64-bit division's form, stays optimistic at the unknown level, because a wrong guess there costs nothing. Here a wrong guess costs speed, so the new predicate is pessimistic. A cast from a floating type to an integral one still declines at every level.

**The session.** `spark.sql.codegen.varka.emit.useAVX=-2` (the default) now resolves an x86 host whose CPU feature list holds AVX512DQ to level 3, so those hosts fuse the casts with no setting. A host without it resolves to level 2 as before; aarch64 and an unreadable feature list keep the unknown level, which declines them, unless the session names level 3. Level 3 lowers every other node as the unknown level does, so the same shapes emit the same bytes; the level is part of the shape key, so such a session caches its classes apart.

**Tests.** `VarkaMatrixRuns.emissionKey` now has three classes and the option matrix runs `useAVX=3` as its own configuration, the only one whose answer tests reach this kernel. `VarkaEmitterFloatingCastSuite` checks five `BIGINT` shapes at every width, plus the refusals at the unknown level and below 3. `VarkaDifferentialHarnessSuite` compares eighteen rows of extremes and rounding cells with the row engine at level 3. `VarkaTypeConformance` takes the `BIGINT` pairs from the level, since the cast register is written at the unknown level. The generated records do not move: no coverage, census or emitted-bytes entry holds one of these casts at the defaults.

### Why are the changes needed?

A `BIGINT` column converted to a double is common (averages, ratios, `x - l` through type coercion), and it forced the whole expression onto the row engine even on hosts where the conversion is a single instruction.

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

No. Answers are unchanged; more expressions run in the kernel on hosts with AVX512DQ.

### How was this patch tested?

`VarkaEmitterFloatingCastSuite`, `VarkaMatrixSuite`, `VarkaEmittedBytesSuite`, `VarkaCoverageSuite`, `VarkaCastMatrixSuite`, the float, double and bigint conformance suites and `VarkaDifferentialHarnessSuite` pass locally. The option matrix, which exercises level 3 and the other configurations, is not yet taken.

### 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 Nov 10, 2026
…it level (apache#1456)

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

Adds row 594 to milestone 8's plan: `VarkaFloatingCastBaselineBenchmark`'s fusion classes follow the emit level its session resolves from the host.

The benchmark lists its `BIGINT` to `DOUBLE` and `FLOAT` sections as not fused. Since apache#1385 and apache#1424 both casts fuse below emit level 3 by exact forms, at a named emit level the benchmark's session takes from the host. On an AVX-512 host, and under `-XX:UseAVX=2` at 256 bits, they plan as fused, so the benchmark's fuse check stops before timing. Its queries suite cannot see this: the test sessions pin the unnamed level (`spark.sql.codegen.varka.emit.useAVX=-1`, in `TestSQLContext` and `VarkaSharedSessions`), under which the casts decline. The row's done-when asks for the declared classes to follow the resolved level, as row 565 makes them follow the two-lane refusal, and for the suite to check them at the named levels too.

### Why are the changes needed?

The failure was found by row 565's plan-only dry runs of every baseline benchmark. The next EPYC run of this benchmark would fail the same way, and nothing in the Build would say so first.

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

No. A plan row only.

### How was this patch tested?

`dev/varka_plan_lint.py --check` passes. The failure itself is reproduced by the dry run `-Dvarka.bench.dryRun=true` at the default width (fails) and with `-XX:UseAVX=2 -XX:MaxVectorSize=16` (passes).

### 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 Nov 10, 2026
…on refusal (apache#1457)

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

Each Varka baseline benchmark checks every section's plan before timing it. It compares the plan's fusion class with the class the section lists: `NONE` (no Varka node), `NULL_TESTS` (Varka fuses only the inferred null tests) or `WHOLE` (no row operator evaluates any of it). If the classes differ, the run stops. This keeps a row that starts fusing a section from quietly turning a baseline into a fused measurement.

On an x86 host whose 64-bit vector species have two lanes or fewer, the session refuses a filter's condition in a kernel driven at a 64-bit lane and leaves it to the row engine (`spark.sql.codegen.varka.declineTwoLaneConditions`, which defaults to the host's answer). This is the host every benchmark's 128-bit companion runs on (`-XX:MaxVectorSize=16`). Projections are never refused. Two baselines still listed such filters with the classes they have without the refusal, so their 128-bit runs stopped before timing anything:

- **`VarkaTimestampNtzBaselineBenchmark`**: the comparison `ntz < ntz2` as a filter, listed `WHOLE`.
- **`VarkaDayTimeIntervalBaselineBenchmark`**: the filter `extract(HOUR FROM dt) >= 12`, listed `NULL_TESTS`, and the control filter `dt > dt2`, listed `WHOLE`. Under the refusal the inferred `dt IS NOT NULL` is refused along with the rest of the condition, so neither filter plans a Varka node.

Both now build their sections with `sections(boolean declinesLongConditions)` and read the refusal from the Varka session (`VarkaSessionEmit.of(conf).declineTwoLaneConditions()`), as `VarkaFloatingCastBaselineBenchmark` and `VarkaFloatingBaselineBenchmark` already do. Under the refusal those three filter sections are `NONE` at both null densities. Every projection keeps its class. Section titles are unchanged, because they are the results files' labels. The control's title still says "fuses today", which is true everywhere except under the refusal.

The day-time interval benchmark's kernel check runs only for `WHOLE` sections, so under the refusal the filter control left the 128-bit run with no fused control at all. The benchmark now has a second control, the projected blend `CASE WHEN dt > dt2 THEN dt ELSE dt2 END`, at both null densities. A projection is never refused, so the blend is `WHOLE` with its kernel check at both widths. The javadoc now calls the filter the 256-bit control, `NONE` under the refusal. The blend is a fusion control: it checks that the varka on arm times a kernel, and claims nothing about that kernel's speed at two lanes.

**The suites.** Each baseline benchmark has a queries suite that makes the benchmark's fuse check in every build. The shared test sessions turn the refusal off (`VarkaSharedSessions` sets it to `false`, so the 128-bit test step does not test the row engine against itself). As a result, no suite ever checked the classes a 128-bit benchmark run expects. A new helper, `VarkaSharedSessions.forEachTwoLaneRefusal`, runs a body with the refusal off and then on, in both sessions. The fuse tests of the TIMESTAMP_NTZ, day-time interval, floating cast, floating arithmetic, integral cast, math, TIMESTAMP_NTZ arithmetic and TIMESTAMP_NTZ fields suites now check every section under both settings. Before this change the floating cast suite read the refusal from its session, which is always off. In the floating arithmetic, integral cast, math, TIMESTAMP_NTZ arithmetic and TIMESTAMP_NTZ fields suites every section has the same class under both settings, so the loop alone could not fail if the setting never took effect. Each loop now starts with a sentinel: a filter over two 64-bit columns (`x < y` on `DOUBLE`, `l < l_n` on `BIGINT`, an NTZ pair), which must fuse exactly when the refusal is off. With the refusal off it is also the "a Varka node is visible at all" check that used to run once outside the loop. The floating and boolean-output suites already looped both ways, by setting the conf on the Varka session alone; they now use the helper, so both sessions get the same setting. The rounding suite makes no fuse check. The decimal suite is left to the open pull requests that fix the decimal benchmark (apache#1422, apache#1448).

**Limitations.** `forEachTwoLaneRefusal` sets the refusal in a JVM at its own width, with the shared sessions' unnamed emit level pinned. So it does not reproduce the 128-bit runner's host, where the benchmark's session resolves its emit level from the host (the floating cast benchmark's `BIGINT` casts, below, are the case where that matters). The deeper fix is an own-JVM check at `-XX:UseAVX=2 -XX:MaxVectorSize=16`, as `VarkaTwoLaneDefault128Suite` does for the refusal's default. That belongs with row 594.

### Why are the changes needed?

A 128-bit companion run of either benchmark on the EPYC runners fails before timing. Run 41977272181 showed this for the day-time interval benchmark. The TIMESTAMP_NTZ benchmark's committed 128-bit results predate the refusal, so rerunning it fails the same way. No pull request check could see the failure, because the suites ran with the refusal off.

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

No. Only benchmarks and test suites change.

### How was this patch tested?

- **Queries suites**, on the laptop: the ten touched suites pass, 22 tests (`build/sbt "sql/testOnly ..."`). They also pass in a 128-bit JVM (`-XX:MaxVectorSize=16`): 22 tests.
- **Plan-only dry runs** (`-Dvarka.bench.dryRun=true`) of every baseline benchmark with a fuse check, on the laptop (AMD Ryzen AI 9 HX PRO 370, AVX-512) at the preferred width and at `-XX:MaxVectorSize=16`. A dry run plans every section and runs the fuse check but times nothing. The "before" column is master at the merge base, the "after" column is this branch:

| benchmark | before, preferred | before, 128-bit | after, preferred | after, 128-bit |
|---|---|---|---|---|
| `VarkaTimestampNtzBaselineBenchmark` | pass | **fail** (comparison listed `WHOLE`, plans `NONE`) | pass | pass |
| `VarkaDayTimeIntervalBaselineBenchmark` | pass | **fail** (`extract(HOUR FROM dt) >= 12` listed `NULL_TESTS`, plans `NONE`) | pass | pass |
| `VarkaFloatingBaselineBenchmark` | pass | pass | pass | pass |
| `VarkaFloatingArithmeticBaselineBenchmark` | pass | pass | pass | pass |
| `VarkaIntegralCastBaselineBenchmark` | pass | pass | pass | pass |
| `VarkaMathBaselineBenchmark` | not run (sbt's own metaspace ran out) | pass | pass | pass |
| `VarkaRoundingBaselineBenchmark` | pass | pass | pass | pass |
| `VarkaTimestampNtzArithmeticBaselineBenchmark` | pass | pass | pass | pass |
| `VarkaTimestampNtzFieldsBaselineBenchmark` | pass | pass | pass | pass |
| `VarkaDecimalBaselineBenchmark` (unchanged here) | pass | fail (`DECIMAL(9, 2)` comparison, fixed in apache#1422 and apache#1448) | pass | fail, as before |
| `VarkaBooleanOutputBenchmark` (unchanged) | fail (output sections fuse) | fail, the same | fail, the same | fail, the same |
| `VarkaFloatingCastBaselineBenchmark` (unchanged) | fail (`BIGINT` casts listed `NONE`, plan `WHOLE`) | fail, the same | fail, the same | fail, the same; passes under `-XX:UseAVX=2` |

After the second control was added, the day-time interval dry run reports both blend sections as fusing whole at both widths, and they are the only fused sections at `-XX:MaxVectorSize=16`, also under `-XX:UseAVX=2`. The TIMESTAMP_NTZ dry run passes at both widths again.

The runners are AVX2, so the two fixed benchmarks and the floating baseline were also dry-run under `-XX:UseAVX=2`. All three pass at both widths.

Two failures are not about the refusal, and this change leaves them alone:
- `VarkaBooleanOutputBenchmark` stops at both widths because its output sections now fuse ("d < d2 output, no nulls fuses, so it is no longer a baseline"). This is by design. The benchmark exists to time those sections before they fuse, apache#1226 made them fuse, and its javadoc says a later change drops the check and times the same sections.
- `VarkaFloatingCastBaselineBenchmark` lists the `BIGINT` casts as `NONE`, but they plan as `WHOLE` at the preferred width, both at AVX-512 and under `-XX:UseAVX=2` (the runners' AVX2). Under `-XX:UseAVX=2 -XX:MaxVectorSize=16` it passes. A `BIGINT` cast to `FLOAT` or `DOUBLE` fuses only at a named emit level (apache#1385, apache#1424). The benchmark's session resolves that level from the host. The test sessions pin the unnamed default (`spark.sql.codegen.varka.emit.useAVX=-1`, so that results mean the same on every runner), so its queries suite plans the casts as `NONE` and passes. Fixing that classification belongs with the `BIGINT` cast work, not with this change.

- `PATH=$HOME/.venv-ruff/bin:$PATH python3 dev/varka_push_check.py`: passed (344 counted lines against the cap of 1000).

Still owed: regenerating the TIMESTAMP_NTZ and floating 128-bit results files on the EPYC runners, and a first 128-bit run of the day-time interval benchmark. The committed day-time interval results file has no blend control yet, so its 256-bit run is owed too. No workflow was dispatched for this change.

### 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.

5 participants