Skip to content

Clear cached Hadoop filesystems when a Spark JVM is reused by the next integration test module - #125448

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-reused-spark-jvm-stale-s3a-filesystem
Oct 13, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-reused-spark-jvm-stale-s3a-filesystem

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120519

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):

Integration tests: ResilientSparkSession now clears the JVM-wide Hadoop FileSystem cache when it reuses a live Spark JVM, so a module's Spark session no longer gets the previous module's s3a:// filesystem bound to that module's MinIO.

Description

test_storage_iceberg_concurrent/test_concurrent_reads.py::test_concurrent_reads fails on master in Integration tests (arm_binary[, distributed plan], 1/4) since #120519 added test_storage_delta/test_writes_interop.py (report, report): either Code 107 (the Iceberg metadata file does not exist) or a failure inside Spark's CREATE TABLE.

ResilientSparkSession reuses a live py4j gateway, so one pytest worker keeps one JVM across modules. Hadoop caches FileSystem instances JVM-wide, keyed by scheme, authority and user but not by configuration, and SparkSession.stop() does not clear them. The two modules are the only Spark users that read MinIO through s3a://root, so when the interop module ran first on a worker, the iceberg session got its S3AFileSystem, still bound to the interop cluster's MinIO. Across 32 CI jobs carrying both modules, the test failed 7/7 times on the same xdist worker as the interop module and passed 25/25 times on a different one.

The change: when _prepare_and_create reuses a live JVM with no active context, it calls FileSystem.closeAll() first. The JVM is still reused.

Validation, local, on both runner images (Spark 3.5.5, which the failing jobs used, and Spark 4.0.0, which master uses now): a two-session probe in one process shows the second session's S3AFileSystem bound to the first endpoint before the change and to its own after it, with the same JVM. The real pair in one pytest process, with the two MinIOs on different addresses as in CI, failed 2/2 before and passed 3/3 after. test_spark_session_recovery and test_storage_iceberg_interoperability_azure pass.


Workflow [PR]
Sync PR [sync-upstream/pr/125448]

Version info

  • Merged into: 26.10.1.2250-master (included in 26.10 and later)

`test_storage_iceberg_concurrent/test_concurrent_reads.py::test_concurrent_reads` fails in
`Integration tests (arm_binary[, distributed plan], 1/4)` on master since ClickHouse#120519 added
`test_storage_delta/test_writes_interop.py`, the second Spark module that reads MinIO through
`s3a://root`:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=56e72cfad0e82b5dfd2e3be5202aff91757dc920&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%201%2F4%29
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=360bb0de656eb8f83cea4ca307f8480348494eb4&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%201%2F4%29

`ResilientSparkSession` reuses a live py4j gateway, so one pytest worker keeps one JVM across
modules. Hadoop caches `FileSystem` instances JVM-wide by scheme and authority only, and
`SparkSession.stop()` does not clear them, so the iceberg session got the interop module's
`S3AFileSystem` for `s3a://root`, still bound to the interop cluster's MinIO, while its own
configuration named its own MinIO.

In 32 CI jobs carrying both modules, the iceberg test failed 7/7 times when it ran on the same xdist
worker after the interop module, and passed 25/25 times on a different worker. In the failed job on
56e72cf, the interop MinIO's released address 172.16.2.4 went to another module's MinIO at 13:56:53Z,
Spark's Iceberg metadata write landed there, and ClickHouse's `CREATE TABLE` 6 s later reported
Code 107 against its own MinIO.

Call `FileSystem.closeAll()` when reusing a live JVM with no active context. The JVM is still reused,
so the reuse contract of `test_spark_session_recovery` is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (3 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ test_spark_session_recovery still passes if closeAll() is removed DISAGREE This changes test infrastructure only, and tests of the test infrastructure are not added (#119766). Validated locally instead: a two-session probe on the Spark 3.5.5 and 4.0.0 runner images gets the stale endpoint before the change and its own after it, and the real module pair fails 2/2 before and passes 3/3 after.
2 💡 The cache key also includes the user, not only scheme and authority AGREE Description reworded; the point is that the configuration is not part of the key.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261012-151300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A two-session probe in one process (different fs.s3a.endpoints on s3a://root) gets the first endpoint's S3AFileSystem every time, on the Spark 3.5.5 and 4.0.0 runner images; the real module pair fails 2/2.
b Root cause explained? A reused py4j gateway keeps one JVM across modules, and Hadoop's JVM-wide FileSystem cache survives SparkSession.stop(), so the iceberg session got the interop module's s3a://root filesystem bound to the wrong MinIO. CI: same worker 7/7 failed, different worker 25/25 passed.
c Fix matches root cause? Yes. FileSystem.closeAll() runs where a reused JVM is handed to a new session; no test, timeout or setting is changed.
d Test intent preserved / new tests added? No test is changed. No new test: test-infrastructure change, validated locally (a and e).
e Both directions demonstrated? Yes. Probe stale before, fresh after, JVM reused in every run; negative control fs.s3a.impl.disable.cache=true is fresh. Real pair 2/2 failed before, 3/3 passed after.
f Fix is general across code paths? Yes. Covers every ResilientSparkSession construction and _restart(), and every cached scheme.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Independent of bucket, endpoint and module pair; measured on Hadoop 3.3.4 and 3.4.1.
h Backward compatible? (maintainer-approved exception only) Yes. Harness only; JVM reuse is kept and test_spark_session_recovery passes 3/3.
i Invariants and contracts preserved? Yes. closeAll() runs only when no SparkContext is active; the dead-gateway path is unchanged; test_storage_iceberg_interoperability_azure passes.

Session id: cron:clickhouse-impl-slot-5:20261012-144600

@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 12, 2026
@groeneai
groeneai requested a review from zlareb1 October 12, 2026 15:31
@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8058af9]

Summary: ✅


AI Review

Summary

This PR clears Hadoop FileSystem caches when ResilientSparkSession reuses a live JVM after the previous SparkSession has been stopped, which matches the stale-s3a:// filesystem failure described in the PR. The change is scoped to the reused-JVM path, preserves the existing live-gateway reuse contract, and I did not find a remaining correctness or surface-coverage issue in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 7fecf73

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, targeted) / test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested not from this PR (it only changes helpers/spark_tools.py): the Spark 4.0 runner image of #117198 broke this test on master. The tested tree predates the revert #125455 (external, merged), merged master @ 8058af9
Integration tests (amd_asan_ubsan, db disk, targeted) / test_storage_delta/test_writes_interop.py::test_write_to_table_with_unsupported_writer_feature_is_rejected same cause as the row above #125455 (external, merged), merged master @ 8058af9
Mergeable Check, PR praktika rollups of the rows above #125455 (external, merged), merged master @ 8058af9

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261012-190013

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 15, 2026
The only failure on the previous head was test_storage_iceberg_concurrent/test_concurrent_reads (arm_binary), fixed on master by ClickHouse#125448.

Co-Authored-By: Claude Opus 5.5 <[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 comp-testing Test content only (no production code). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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