Skip to content

Fix flaky test_database_delta::test_snapshot_version (Spark DESCRIBE HISTORY timeout) - #109641

Merged
scanhex12 merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-snapshot-version-spark-retry
Jul 7, 2026
Merged

scanhex12 merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-snapshot-version-spark-retry

Conversation

@groeneai

@groeneai groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

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

...

Description

Fixes the chronic flaky test_database_delta/test.py::test_snapshot_version (timed out after 600s).

Root cause: the get_table_versions() helper runs a read-only DESCRIBE HISTORY through execute_spark_query() without retry_on_timeout, so it uses a single 600s attempt. A transient Unity Catalog HTTP-client hang (the UC Java client has no per-request timeout, see the jstack root cause recorded when the retry mechanism was added) can consume that whole attempt, and the test fails with timed out after 600s. The CI report (Integration tests amd_tsan 5/6, PR #109229) shows exactly this: the hang is inside Spark/Ivy + UC on the DESCRIBE HISTORY invocation.

Fix: pass retry_on_timeout=True on this read-only call. It is idempotent, so a fresh-JVM retry is safe. This uses the shorter 300s per-attempt budget with 2 attempts (600s total), which still fits the 900s pytest timeout. The non-idempotent INSERT calls in the same test are deliberately left un-retried.

test_database_delta::test_snapshot_version is chronically flaky: the
get_table_versions() helper runs a read-only DESCRIBE HISTORY via
execute_spark_query() without retry_on_timeout, so a single 600s attempt
is consumed entirely by a transient Unity Catalog HTTP-client hang (the
UC Java client has no per-request timeout, see the jstack root cause
recorded in the retry mechanism added earlier). The test then fails with
'timed out after 600s'.

DESCRIBE HISTORY is read-only and idempotent, so retry_on_timeout is
safe: it uses the shorter 300s per-attempt budget and a fresh-JVM retry,
and two attempts (600s) still fit the 900s pytest timeout. The
non-idempotent INSERT calls are deliberately left un-retried.

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

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Not locally (needs the full Docker + Spark + MinIO + Unity Catalog integration stack). Backed by CIDB: chronic timeout across many unrelated PRs, ~0 on master; the CI report for this issue shows the hang on the exact DESCRIBE HISTORY call.
b Root cause explained? get_table_versions() runs a read-only DESCRIBE HISTORY via execute_spark_query() without retry_on_timeout, so it gets a single 600s attempt. A transient Unity Catalog HTTP-client hang (UC Java client has no per-request timeout) parks Spark's main thread for the whole 600s → timed out after 600s.
c Fix matches root cause? Yes — enables the existing opt-in fresh-JVM retry (retry_on_timeout=True) for exactly the read-only call that hangs, applying the already-merged retry contract to a caller that was missed. Not a band-aid (no timeout widening, no skip).
d Test intent preserved / new tests added? Preserved — the test still asserts ["0","1","2"] and all version/data checks. No assertion weakened.
e Both directions demonstrated? Cannot run the integration stack in the fleet slot. Correctness is by construction: DESCRIBE HISTORY is read-only/idempotent so retry is safe; 2×300s = 600s < 900s pytest timeout.
f Fix is general across code paths? The two INSERT calls in this test are intentionally NOT retried (non-idempotent — a fresh-JVM retry after a partial commit would double-insert). Only the read-only DESCRIBE HISTORY gets retry, consistent with the existing retry_on_timeout contract.
g Fix generalizes across inputs? N/A (integration-test flakiness fix, not a code bug).
h Backward compatible? N/A (test-only change).
i Invariants and contracts preserved? Yes — retry_on_timeout contract requires the query be idempotent/read-only; DESCRIBE HISTORY satisfies it.

Session id: cron:clickhouse-worker-slot-12:20260707-125100

@groeneai

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 — could you review? Small test-only fix: enable the existing retry_on_timeout on the read-only DESCRIBE HISTORY call that hangs in test_database_delta::test_snapshot_version (transient Unity Catalog HTTP-client hang).

@scanhex12 scanhex12 added the can be tested Allows running workflows for external contributors label Jul 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5e22d65]

Summary: ✅


AI Review

Summary

This PR opts the read-only DESCRIBE HISTORY call in test_snapshot_version into the existing retry_on_timeout contract. That matches the helper's documented safety rule for idempotent and read-only Spark operations, and I did not find a remaining correctness or contract issue in the current diff.

Missing context / blind spots
  • ⚠️ The full PR CI matrix was still in progress during review, so runtime confirmation of the flake reduction is based on code inspection and the linked flake report rather than a completed post-fix integration run.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 7, 2026
@scanhex12
scanhex12 enabled auto-merge July 7, 2026 14:04
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.00% 86.02% +0.02%
Functions 91.48% 91.48% +0.00%
Branches 78.54% 78.57% +0.03%

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

Newly covered by added/modified tests: 131 line(s), 4 function(s) across 18 file(s) · Details

Top files
  • src/Storages/ObjectStorage/DataLakes/Iceberg/MetadataGenerator.cpp: 48 line(s)
  • src/Server/ACME/Client.cpp: 26 line(s), 1 function(s)
  • src/Backups/BackupCoordinationStageSync.cpp: 13 line(s)
  • src/Server/ACME/RequestHandler.cpp: 7 line(s), 1 function(s)
  • src/Common/getCurrentProcessFDCount.cpp: 7 line(s)

Full report

@groeneai

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — b0c7fcb

All CI checks passed. No failures to own.

Check / test Reason Owner / fixing PR
CH Inc sync — CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260707-163000

@scanhex12
scanhex12 added this pull request to the merge queue Jul 7, 2026
Merged via the queue into ClickHouse:master with commit 18230fa Jul 7, 2026
175 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…pshot-version-spark-retry

Fix flaky test_database_delta::test_snapshot_version (Spark DESCRIBE HISTORY timeout)
clickhouse-gh Bot added a commit that referenced this pull request Sep 15, 2026
Backport #109641 to 26.6: Fix flaky test_database_delta::test_snapshot_version (Spark DESCRIBE HISTORY timeout)
qiuyanjun888 pushed a commit to qiuyanjun888/ClickHouse that referenced this pull request Sep 27, 2026
test_complex_table_schema and test_varchar_char_types_via_unity_catalog fail with
"subprocess.TimeoutExpired: ... bin/spark-sql ... timed out after 600 seconds".
CIDB over 30 days: 5 rows across 5 distinct PRs for this signature, 0 on master.

The Unity Catalog server accepts GET /schemas/{name} and never answers it, and the
UC Java client issues that request through java.net.http.HttpClient with no
per-request timeout, so the Spark driver parks for the whole subprocess budget.
The jstack that the test's own hang diagnostics capture 600s into the stall puts
it in the batch's first statement:

  "main" ClickHouse#1 cpu=11625.96ms elapsed=600.24s WAITING (parking)
    jdk.internal.net.http.HttpClientImpl.send
    io.unitycatalog.client.api.SchemasApi.getSchemaWithHttpInfo(SchemasApi.java:273)
    io.unitycatalog.spark.UCProxy.loadNamespaceMetadata(UCSingleCatalog.scala:399)
    SupportsNamespaces.namespaceExists(SupportsNamespaces.java:98)
    CreateNamespaceExec.run(CreateNamespaceExec.scala:43)

CreateNamespaceExec.run probes namespaceExists before creating anything. In the
same diagnostics both socket ends are ESTAB with Recv-Q = Send-Q = 0 for 600s
(the request was fully delivered and UC produced no response byte) while a
concurrent UC liveness probe answered in 10.7ms, so the server was serving other
requests and a fresh client converges.

Two alternatives are excluded by measurement. Ivy package resolution is not
involved: the failing run reports "0 artifacts copied, 33 already retrieved
(0kB/16ms)", because the image pre-resolves the same --packages list at build
time. Derby metastore init is not involved either: the JVM got well past
ObjectStore init.

UC is a third-party server pinned in the test image and its client constructs its
own HttpClient, so neither the handler nor a request timeout is reachable from the
spark-sql command line. The only lever the test owns is to survive the stall,
which is what ClickHouse#107133 established and ClickHouse#109641 extended to the read path.

Hence the same two-part remedy at the two measured write sites: rewrite the batch
into the idempotent form already used at the precedent site (CREATE SCHEMA IF NOT
EXISTS, CREATE TABLE IF NOT EXISTS, INSERT OVERWRITE), then pass
retry_on_timeout=True so one fresh-JVM replay is allowed. 2 x 300s fits the 900s
per-test cap from tests/integration/pytest.ini with roughly 300s of headroom; no
timeout constant changes. Both tables are named with a fresh uuid4() and hold
exactly one row, so a replay converges to identical content.

test_snapshot_version is deliberately left alone. It asserts the Delta commit
history (get_table_versions() == ["0","1","2"] and _commit_version), so INSERT
OVERWRITE would add a commit and break the assertions; making it replay-safe
needs a real restructure. That is the same boundary ClickHouse#109641 drew when it retried
only that test's read-only DESCRIBE HISTORY.

Validation. Since the UC stall cannot be forced, a temporary local injection
reported a timeout after the batch had really executed and committed, which is
the worst case for a replay: 4/4 test executions passed and each logged the
retry. Reverting exactly one edit at a time then reddens the run for the
predicted reason (SCHEMA_ALREADY_EXISTS, TABLE_OR_VIEW_ALREADY_EXISTS, and a
duplicate row breaking the column assertions), so no edit is decoration. Without
injection: 4/4 on the pristine tree and 4/4 with the fix in the same wall-clock
band, 21 passed / 3 skipped for the whole module, and 40/40 over --count 10 on
all four parameter ids.

Failing job:
https://github.com/ClickHouse/ClickHouse/actions/runs/35763632624/job/107009114425

Co-Authored-By: Claude Opus 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 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