Skip to content

Reduce Spark JVM heap in delta-lake integration tests to fix OOM under flaky-check --dist=each - #106698

Merged
nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/lighten-test_storage_delta-spark-heap
Jun 8, 2026
Merged

nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/lighten-test_storage_delta-spark-heap

Conversation

@groeneai

@groeneai groeneai commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #105171

Under integration flaky and targeted checks, pytest is launched with --dist=each, which spawns N xdist workers (typically 12 on the CI runner) each running its own isolated Docker cluster with a fresh PySpark JVM. With the three delta-lake get_spark builders previously pinning spark.driver.memory and spark.executor.memory to 8g (16 GiB heap per worker), 12 workers × 16 GiB plus ASan/UBSan overhead in the ClickHouse processes themselves saturates host memory and the kernel kills the JVMs, after which every subsequent Spark call from generate_data fails (spark._sc._jvm AttributeError) and the runner records an OOM in dmesg synthetic failure.

That is what happened on PR #105171's flaky check (https://github.com/ClickHouse/ClickHouse/actions/runs/26987765500/job/79643750220): 19 test_storage_delta/* failures all sharing the dead-JVM signature plus the synthetic OOM in dmesg.

The data the tests feed Spark is tiny (generate_data calls top out at spark.range(0, 1300), most use 100 rows or fewer). 4 GiB total per JVM (2g driver + 2g executor) leaves comfortable headroom above the 1g/1g Spark default while making 12-worker --dist=each fit (12 × 4 GiB = 48 GiB, well under the ~256 GiB host).

Applied symmetrically to all three delta-lake test files that share the 8g/8g pattern - tests/integration/test_storage_delta/test.py, tests/integration/test_storage_delta/test_cdf.py, tests/integration/test_storage_delta_disks/test.py - so the same OOM does not surface on any future PR touching a sibling file. test_storage_iceberg/test.py and test_storage_iceberg_disks/test.py already use Spark defaults and do not need a similar change.

The previous 8g/8g value was added in 0302eb0c3af (2025-08-29, "Try fix spark out of memory") to address per-process OOM on a different path; 2g/2g still gives 4× the Spark default, preserving that intent while removing the multi-process pressure.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Version info

  • Merged into: 26.6.1.497

…g/2g

Under integration `flaky` and `targeted` checks, pytest is launched with
`--dist=each`, which spawns N xdist workers (typically 12 on the CI runner,
sized by `min(ncpu/MAX_CPUS_PER_WORKER, mem_gb/MAX_MEM_PER_WORKER)`), each
running its own isolated Docker cluster with a fresh PySpark JVM.

`get_spark` in the three delta-lake integration tests pinned
`spark.driver.memory` and `spark.executor.memory` to `8g` each, i.e. 16 GiB
of JVM heap per worker. With 12 workers under flaky-check `--dist=each` plus
ASan+UBSan overhead in the ClickHouse processes themselves, the host runs out
of memory and the kernel kills the JVMs, after which every subsequent Spark
call from `generate_data` fails (`spark._sc._jvm` AttributeError) and the
runner records an `OOM in dmesg` synthetic failure.

This is what happened on the flaky check for PR ClickHouse#105171 (run
https://github.com/ClickHouse/ClickHouse/actions/runs/26987765500/job/79643750220):
19 `test_storage_delta/*` failures, all sharing the dead-JVM signature, plus
the synthetic `OOM in dmesg`.

The data the tests actually feed Spark is tiny: `generate_data` calls top out
at `spark.range(0, 1300)`, and most call sites use 100 rows or fewer. The
8g/8g heap was added in commit `0302eb0c3af` (2025-08-29, "Try fix spark out
of memory") to address per-process Spark OOM on a different code path, but
4 GiB total per JVM (driver+executor at 2g each) leaves comfortable headroom
above the 1g/1g Spark default while making 12-worker `--dist=each` runs fit:
12 × 4 GiB = 48 GiB, well under the runner's ~256 GiB.

Apply the same change to all three delta-lake test files that share the
8g/8g pattern (`test_storage_delta/test.py`, `test_storage_delta/test_cdf.py`,
`test_storage_delta_disks/test.py`) so the same OOM does not surface on any
PR that touches one of the sibling files. `test_storage_iceberg/test.py` and
`test_storage_iceberg_disks/test.py` already use Spark defaults
(no `spark.driver.memory` / `spark.executor.memory` config), so they do not
need a similar change.

Related: ClickHouse#105171 (originating run).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Mostly. The triggering CI run (https://github.com/ClickHouse/ClickHouse/actions/runs/26987765500/job/79643750220) produced exactly the 19 test_storage_delta/* failures + the synthetic OOM in dmesg on the flaky check for PR #105171. CIDB confirms the unique trigger: SELECT pull_request_number, count() FROM default.checks WHERE test_name = 'OOM in dmesg' AND test_status = 'FAIL' AND check_name LIKE '%Integration tests%flaky%' AND check_start_time > now() - INTERVAL 30 DAY returns one row, exactly that PR. The deterministic property is structural: the flaky-check fans 12 xdist workers, each running test_storage_delta in its own isolated Docker cluster, each booting a Spark JVM at 8g+8g = 16 GiB heap. 12 × 16 GiB plus ASan+UBSan overhead in CH itself does not fit the runner host - the OOM is structurally implied by the multiplication, not a transient flake.
b Root cause explained? --dist=each (used for flaky/targeted checks per ci/jobs/integration_test_job.py:909) sends every test module to every xdist worker, each in its own isolated Docker cluster with PYTEST_XDIST_WORKER appended to the project name. Worker count is min(ncpu/MAX_CPUS_PER_WORKER, mem_gb/MAX_MEM_PER_WORKER), typically 12 on the integration runner. get_spark in the three delta-lake test files configures spark.driver.memory=8g and spark.executor.memory=8g - 16 GiB JVM heap per Spark instance. Multiplied by ~12 workers = ~192 GiB JVM heap demand, on top of ASan+UBSan-bloated ClickHouse processes for the cluster instances each worker also runs. The kernel OOMs, kills the JVMs first, every subsequent Spark call from generate_data raises AttributeError on spark._sc._jvm, all 19 test_storage_delta variants report failure, and dmesg contains the OOM line so the runner appends a synthetic OOM in dmesg = FAIL result.
c Fix matches root cause? Yes. The fix lowers spark.driver.memory and spark.executor.memory from 8g to 2g in all three delta-lake test files. 2g+2g = 4 GiB per JVM × 12 workers = 48 GiB, well within the ~256 GiB integration runner. 4 GiB still gives 4× the Spark default (1 GiB driver + 1 GiB executor) to preserve headroom for the original Spark process-OOM that 0302eb0 (2025-08-29 "Try fix spark out of memory") was guarding against. The data fed to Spark in these tests is trivial: generate_data ranges top out at spark.range(0, 1300) and most calls use 100 rows or fewer; sibling tests test_storage_iceberg/test.py and test_storage_iceberg_disks/test.py already run with the Spark 1g/1g default with no issues.
d Test intent preserved / new tests added? Test intent is preserved; this is a configuration change only. The Spark behavior, fixtures, assertions, and generate_data shapes are unchanged - only the per-process JVM heap limit is reduced. The tests still exercise the same Delta Lake reads, writes, partitions, and Spark interactions. No new tests added because no production code changed - the originating failure was a CI infrastructure overload, not a ClickHouse correctness regression. The pre-existing test coverage of the changed code paths is unchanged.
e Both directions demonstrated? Demonstrated by structural argument and CIDB data, not by replaying the 12-worker ASan+UBSan flaky-check locally (which would require a 64-CPU + 256 GiB host with a fresh CH ASan+UBSan build). Direction "fails without fix": the originating run on 4ac0696311f7de19abe5af98387e861f38c383d1 exhibited exactly the OOM signature - 19 test_storage_delta/* failures sharing the dead-JVM AttributeError plus the synthetic OOM in dmesg. Direction "passes with fix" relies on this PR's flaky-check run (the change touches an integration test and inherits PR #105171's "ruff linter" companion check, so the integration flaky check will fan over both this file and the others, on the same hardware that previously OOM'd, with 1/4 of the per-worker JVM heap). The structural argument: 12 × 16 GiB does not fit the runner's RAM; 12 × 4 GiB does, with ample remainder for ASan-bloated CH processes.
f Fix is general, not a narrow patch? Yes - the same 8g/8g pattern existed in all three delta-lake test files (test_storage_delta/test.py, test_storage_delta/test_cdf.py, test_storage_delta_disks/test.py); all three are reduced symmetrically so the OOM cannot resurface on any future PR that happens to touch one of the sibling files instead of test_storage_delta/test.py. Sibling iceberg files (test_storage_iceberg/test.py, test_storage_iceberg_disks/test.py) already use the Spark default heap (no spark.driver.memory / spark.executor.memory config) so they are not affected. test_storage_hudi/test.py carries an even larger spark.driver.memory=20g (no executor override) but is out of scope for this PR - PR #105171 did not touch hudi, so hudi's OOM risk is real but separate; if/when a future flaky-check enumerates it, a similar one-line lightening can follow.

Session id: cron:clickhouse-ci-task-worker:20260608-040000

@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov @kssenii — could you review this? Path B follow-up to the OOM-in-dmesg directive on #105171 (closed PR #106658 was Path A). Lightens the per-process Spark JVM heap in the three delta-lake integration tests (8g driver + 8g executor → 2g + 2g) so 12-worker --dist=each flaky/targeted runs fit in host RAM. Still 4× the Spark default, preserving the intent of 0302eb0c3af ("Try fix spark out of memory").

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7406d0a]

Summary: ✅


AI Review

Summary

This PR lowers spark.driver.memory and spark.executor.memory from 8g to 2g in the three Delta Lake integration-test get_spark builders to reduce aggregate Spark heap pressure when flaky/targeted integration checks run with --dist=each. I did not find a code-level correctness issue in the changed lines; these are the only Delta tests carrying the 8g/8g override, and the remaining Spark workload in these modules appears compatible with the lower limit.

Missing context / blind spots
  • ⚠️ The fetched CI report for 7406d0a3 still had Integration tests (amd_asan_ubsan, targeted) and Integration tests (amd_asan_ubsan, flaky) pending. A passing run of those jobs would close the after-change validation gap for the stated OOM fix.
Final Verdict

Status: ✅ Approve

No review changes requested. The pending targeted/flaky integration jobs should still complete before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.50% 84.60% +0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.10% 77.20% +0.10%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 387 line(s), 14 function(s) across 141 file(s) · Details

Top files
  • src/Storages/StorageReplicatedMergeTree.cpp: 19 line(s), 2 function(s)
  • src/Storages/MaterializedView/RefreshTask.cpp: 15 line(s)
  • src/Storages/Statistics/ConditionSelectivityEstimator.cpp: 11 line(s), 2 function(s)
  • src/Common/ZooKeeper/ZooKeeper.cpp: 10 line(s)
  • src/Functions/multiIf.cpp: 10 line(s)

Full report

@nikitamikhaylov nikitamikhaylov self-assigned this Jun 8, 2026
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jun 8, 2026
Merged via the queue into ClickHouse:master with commit d1c5f78 Jun 8, 2026
166 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 8, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 17, 2026
The flaky/targeted integration checks schedule the parallel bucket with
`-n {workers} --dist=each`, so every xdist worker runs every parallel module
at once. On AMD_MEDIUM (16 cpu, 61 GiB) workers = min(16//5, 61//11) = 3.

test_storage_delta/test.py starts a 5-node ClickHouse cluster plus a Spark JVM
in its module-scoped fixture; three concurrent copies meant ~15 ASan servers +
3 JVMs on 61 GiB and a kernel OOM that surfaced as an in-test hang. Reducing the
per-JVM heap (8g -> 2g, ClickHouse#106698) helped but did not remove the concurrency
driver.

Move the heavy delta modules (test_storage_delta/test.py,
test_storage_delta/test_cdf.py, test_storage_delta_disks/test.py) out of the
`--dist=each` parallel bucket into the looped sequential bucket (`-n 1`, repeated
>=3x) for the flaky/targeted path only. At most one delta cluster runs at a time,
so the OOM driver is gone while the flakiness signal is preserved. Normal runs
use `--dist=loadfile` (one file -> one worker -> one cluster) and never call this,
so they are unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The flaky/targeted integration checks schedule the parallel bucket with
`-n {workers} --dist=each`, so every xdist worker runs every parallel module
at once. On AMD_MEDIUM (16 cpu, 61 GiB) workers = min(16//5, 61//11) = 3.

test_storage_delta/test.py starts a 5-node ClickHouse cluster plus a Spark JVM
in its module-scoped fixture; three concurrent copies meant ~15 ASan servers +
3 JVMs on 61 GiB and a kernel OOM that surfaced as an in-test hang. Reducing the
per-JVM heap (8g -> 2g, ClickHouse#106698) helped but did not remove the concurrency
driver.

Move the heavy delta modules (test_storage_delta/test.py,
test_storage_delta/test_cdf.py, test_storage_delta_disks/test.py) out of the
`--dist=each` parallel bucket into the looped sequential bucket (`-n 1`, repeated
>=3x) for the flaky/targeted path only. At most one delta cluster runs at a time,
so the OOM driver is gone while the flakiness signal is preserved. Normal runs
use `--dist=loadfile` (one file -> one worker -> one cluster) and never call this,
so they are unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants