Repository navigation
Retry Spark query on transient hang in test_database_delta - #107133
alexey-milovidov merged 3 commits into
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-14:20260611-015500 |
|
cc @scanhex12 — could you review this? It fixes the chronic flake in |
|
Workflow [PR], commit [1ea6cc0] Summary: ✅ AI ReviewSummaryThis PR makes the Spark SQL timeout retry in Missing context / blind spots
Final VerdictStatus: ✅ Approve |
test_check_database_unity (and other test_database_delta tests that call execute_spark_query) is chronically flaky: the spark-sql invocation occasionally hangs for the full 600s timeout and the test fails with subprocess.TimeoutExpired. Root cause, from a jstack thread dump captured by the existing hang diagnostics (PR ClickHouse#104801) on a CI failure (PR ClickHouse#106374, Integration tests (arm_binary, distributed plan, 4/4)): the Spark main thread parks for the whole timeout inside the Unity Catalog Java client: jdk.internal.net.http.HttpClientImpl.send io.unitycatalog.client.api.SchemasApi.getSchema io.unitycatalog.spark.UCProxy.loadNamespaceMetadata SupportsNamespaces.namespaceExists CreateNamespaceExec.run <- first CREATE SCHEMA The UC client uses the JDK HttpClient with no per-request timeout, so a single transient stall hangs forever. The hang is transient, not a UC outage: in the same run the UC liveness probe answered in 7.8ms with http_code 500, Ivy dependency resolution succeeded in 396ms (so this is not a package-download problem), and the very next test (test_multiple_schemes_tables, same CREATE SCHEMA path) ran 17s later and passed in under a second once the stuck JVM was killed. Retry the Spark invocation with a fresh JVM when it hangs. Only the timeout is retried; real query errors are re-raised immediately. Per-attempt timeout is 300s and at most two attempts are made, keeping the worst case within the 900s per-test pytest limit. The retry is opt-in (retry_on_timeout, default False) because the pkill + metastore cleanup preamble does not reset Unity Catalog or Delta committed state: blindly re-running a multi-statement batch that already committed an earlier statement could fail on "already exists" or duplicate INSERT rows. Non-idempotent callers keep the original single-attempt behavior. test_check_database_unity opts in after being made idempotent (CREATE SCHEMA/TABLE IF NOT EXISTS, INSERT OVERWRITE), so a fresh-JVM retry after a partial commit converges to the same final state. The test asserts only table count and CHECK DATABASE, so OVERWRITE vs INSERT changes no assertion. Co-Authored-By: Claude Opus 4.8 <[email protected]>
8c12431 to
674a4a2
Compare
Pre-PR validation gate (updated for 674a4a2 idempotency fixup)
Session id: cron:clickhouse-worker-slot-11:20260611-103400 |
_run_spark_query_once hardcoded the 300s per-attempt timeout for every caller, so non-opt-in (retry_on_timeout=False) callers lost the original 600s budget that master used. A slow-but-progressing spark-sql setup or query could newly time out at 300s and flake. Thread the timeout into _run_spark_query_once: retry_on_timeout=False runs a single attempt at the original 600s; retry_on_timeout=True runs up to 2 attempts at 300s each (worst case 600s, within the 900s pytest limit). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (fixup 3756093)
Session id: cron:clickhouse-worker-slot-16:20260611-125100 |
The pre-attempt cleanup in _run_spark_query_once runs as bash -c "...", so the shell's own command line contains the literal pkill pattern. A plain pkill -f 'org.apache.spark' therefore matched and SIGKILLed that shell before 'sleep 1; rm -rf metastore_db' could run; with nothrow=True the nonzero exit was swallowed, so a corrupt Derby metastore_db could survive into the next retry and hang Spark initialization. Use the [o]rg.apache.spark character-class pattern (already used by _capture_spark_hang_diagnostics) so the regex no longer matches its own command line while still matching real Spark JVMs. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (fixup 1ea6cc0)
Session id: cron:clickhouse-worker-slot-16:20260611-140400 |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 315 line(s), 120 function(s) across 113 file(s) · Details Top files
|
|
CI finished on 1ea6cc0. All checks green (55 success, 111 skipped, 0 failures). No PR-caused failures. Ready for review. (cron:our-pr-ci-monitor:20260611-210000) |
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]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Fix chronic flakiness in
test_database_delta/test.py::test_check_database_unity(and sibling tests usingexecute_spark_query). Thespark-sqlinvocation occasionally hangs for the full 600s timeout, failing withsubprocess.TimeoutExpired.Root cause (jstack thread dump captured by the hang diagnostics from #104801, on the failure in PR #106374 /
Integration tests (arm_binary, distributed plan, 4/4)): the Spark main thread parks for the whole timeout inside the Unity Catalog Java client, which uses the JDKHttpClientwith no per-request timeout:The hang is transient, not a UC outage: in the same run the UC liveness probe answered in 7.8ms (http_code 500), Ivy resolution finished in 396ms (so it is not a package-download issue), and the next test (
test_multiple_schemes_tables, sameCREATE SCHEMApath) passed in under a second 17s later once the stuck JVM was killed.Fix: retry the Spark invocation with a fresh JVM when it hangs. Only the timeout is retried; real query errors are re-raised immediately. The existing
pkill+ metastore cleanup preamble runs before each attempt, so the retry starts clean. Per-attempt timeout is 300s with at most two attempts, keeping the worst case within the 900s per-test pytest limit.No related open issue was found for this test.