Skip to content

Capture jstack/UC liveness diagnostics on Spark hang in test_database_delta - #104801

Merged
antonio2368 merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/diag-spark-timeout-test_database_delta
May 14, 2026
Merged

antonio2368 merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/diag-spark-timeout-test_database_delta

Conversation

@groeneai

@groeneai groeneai commented May 13, 2026 •

Copy link
Copy Markdown
Collaborator

The chronic flaky test test_database_delta::test_check_database_unity times out on Integration tests (arm_binary, distributed plan, 4/4) when the Spark JVM hangs between Hive metastore initialization and actual query execution. PR #102649 (merged 2026-04-14) batched 7 sequential Spark invocations into one, dropping the failure rate to 2 master hits in 30 days, but a residual hang remains and we currently have no data to localize it.

When subprocess.TimeoutExpired fires inside execute_spark_query, the Spark JVM is killed by SIGKILL so its stdout/stderr are truncated to whatever it logged before the hang point, and the existing uc.log tail is not enough to tell us where the JVM is stuck. CIDB rows for the failing master shards (2a00d99d, 2f0c1004 — 2026-05-11) consistently stop at ObjectStore.setMetaStoreSchemaVersion, which is the last metastore-init log line. We do not know whether Spark is then blocked on a Unity Catalog HTTP call, on a Derby file lock, or somewhere else entirely.

This PR adds a _capture_spark_hang_diagnostics helper that runs after the existing log capture in the exception handler of execute_spark_query and collects three pieces of state from inside the test container:

  1. jstack thread dump of every running org.apache.spark JVM — shows exactly where the JVM is stuck during the hang.
  2. Unity Catalog HTTP liveness probe on http://localhost:8080/api/2.1/unity-catalog/schemas — shows whether UC is responsive while Spark is hung.
  3. ss -tnp snapshot of sockets matching :8080 or java — shows whether Spark holds open sockets to UC at the moment of the hang.

Each diagnostic is wrapped in its own try/except so a failure in one does not prevent collection of the others, and all exec_in_container calls use short timeouts (15–30 s) so the diagnostics cannot meaningfully extend the test failure time. The helper runs only on the already-failing path so it cannot make a passing test fail. All three tools (jstack, curl, ss) are present in the clickhouse/integration-test-with-unity-catalog:latest image used by the test fixture (verified by docker run --entrypoint /bin/bash ... -c 'which jstack curl ss').

This is diagnostic-only — it does not fix the residual hang. The data it captures will let the next master hit be localized to a specific stuck thread or UC RPC instead of "Spark stopped logging".

Sample failure (master): https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2a00d99de694fda4302148265b75a9d42ae878fa&name_0=MasterCI

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

...

Documentation entry for user-facing changes

  • Documentation is unchanged (no user-facing behavior change).

Version info

  • Merged into: 26.5.1.648

The chronic flaky test `test_database_delta::test_check_database_unity`
times out on `Integration tests (arm_binary, distributed plan, 4/4)`
when the Spark JVM hangs between metastore initialization and actual
query execution. PR ClickHouse#102649 (merged 2026-04-14) batched 7 sequential
Spark invocations into one, dropping the failure rate to 2 master hits
in 30 days, but a residual hang remains and we currently have no data
to localize it: on `subprocess.TimeoutExpired` the Spark JVM is killed
by SIGKILL, so `stdout`/`stderr` are truncated to whatever Spark logged
before the hang point and the existing `uc.log` tail is not enough to
say where the JVM is stuck.

Add a `_capture_spark_hang_diagnostics` helper that runs after the
existing log capture in the exception handler of `execute_spark_query`
and collects three pieces of state from inside the test container:

  1. `jstack` thread dump of every running `org.apache.spark` JVM —
     shows exactly where the JVM is stuck during the hang.
  2. Unity Catalog HTTP liveness probe on `http://localhost:8080` —
     shows whether UC is responsive while Spark is hung.
  3. `ss -tnp` snapshot of sockets matching `:8080` or `java` — shows
     whether Spark holds open sockets to UC at the moment of the hang.

Each diagnostic is wrapped in its own `try`/`except` so a failure in
one does not prevent collection of the others, and all `exec_in_container`
calls use a short timeout (15-30 s) so the diagnostics cannot extend the
test failure time noticeably. The helper runs only on the already-failing
path so it cannot make a passing test fail.

This is diagnostic-only — it does not fix the residual hang. The data it
captures will let the next master hit be localized to a specific stuck
thread or UC RPC instead of "Spark stopped logging".

Tracked in worker task 2026-05-12-ci-p2-testdatabasedeltatestcheckd.
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antonio2368 @kssenii — could you review? Small diagnostic-only change in tests/integration/test_database_delta/test.py to capture jstack thread dumps, Unity Catalog liveness, and ss socket state when execute_spark_query raises (typically TimeoutExpired). Antonio, you authored PR #102649 (the batching fix), so you have the most context on this test; Ksenia owns comp-datalake. No behavior change on the passing path — extra diagnostics run only inside the existing except block and each is wrapped in its own try/except.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (session cron:clickhouse-ci-task-worker:20260513-074500):

This PR is diagnostic-only — it does not change behavior on the passing path, only adds extra captures inside the existing exception handler of execute_spark_query. The standard "deterministic repro + both directions demonstrated" gate is for code fixes; for a defensive-diagnostic change the relevant checks are:

a) Tools exist in the test container? Yes — verified which jstack (/usr/bin/jstack), which curl (/usr/bin/curl), which ss (/usr/bin/ss) inside clickhouse/integration-test-with-unity-catalog:latest. JVM is OpenJDK 17, so jstack is the standard tool.

b) Cannot break a passing test? Yes — the helper is called only inside the except Exception branch, after the existing log capture. The hot path (line 104–125) is untouched.

c) Cannot extend test failure time noticeably? Yes — all exec_in_container calls use short timeouts (15–30 s) and the diagnostics are wrapped in try/except, so timeouts/failures inside the helper print a one-line error and continue. Worst case adds ≈75 s to an already-failing test.

d) Test intent preserved? Yes — no test assertion or query changed; only the failure-mode logging is richer.

e) Why a fix is not in this PR. The root cause of the residual hang is unknown — CIDB rows always stop at ObjectStore.setMetaStoreSchemaVersion, so we do not know whether Spark is then blocked on a Unity Catalog HTTP call, a Derby file lock, or somewhere else. Reproducing requires a local rebuild with ENABLE_RUST=1 (~45 min) plus iterative reproduction, which does not fit a single CI-monitor cron run. This PR is the next-best actionable step: the next master hit will give us a jstack-resolved thread location instead of "Spark stopped logging".

Recent failure history (post-PR #102649): 2 master hits in 30 days, both on Integration tests (arm_binary, distributed plan, 4/4) (2026-05-11). P3 rare-flaky band.

@antonio2368 antonio2368 added the can be tested Allows running workflows for external contributors label May 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [37e278d]

Summary: ✅


AI Review

Summary

This PR adds failure-path diagnostics in test_database_delta to capture Spark JVM thread dumps, Unity Catalog liveness, and socket state when execute_spark_query fails (primarily timeout/hang cases). I reviewed the current head diff and prior discussion threads; the previously flagged shell-pipeline and fallback issues are addressed in the current code, and I did not find additional correctness, safety, or reliability problems that require changes.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 13, 2026
@antonio2368 antonio2368 self-assigned this May 13, 2026

@antonio2368 antonio2368 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mostly small stuff, but the jstack fallback doesn't actually fall back — head masks jstack's exit code, so -F never runs. Same pattern bites the ss sentinel.
@groeneai address all the comments

# 1. Thread dumps of running Spark JVMs.
try:
pids_out = node.exec_in_container(
["bash", "-c", "pgrep -f 'org.apache.spark' || true"],

@antonio2368 antonio2368 May 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pgrep -f 'org.apache.spark' can match the bash -c wrapper itself, so when no Spark JVM is left you sometimes get the wrapper PID back and jstack runs against it. Easy fix:

["bash", "-c", "pgrep -f '[o]rg.apache.spark' || true"]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 720c43fe7e6 — pgrep -f '[o]rg.apache.spark' || true. The [o] character class matches a literal o, so the regex still matches a real Spark JVM cmdline, but the regex string itself contains [o] instead of plain o and therefore does not match the wrapper's own bash -c command line. Verified the trick in isolation (real Spark cmdline java ... org.apache.spark.executor.CoarseGrained... still matches; wrapper cmdline bash -c "pgrep -f '[o]rg.apache.spark' || true" does not).

Comment on lines +130 to +131
f"jstack {pid} 2>&1 | head -500"
f" || jstack -F {pid} 2>&1 | head -500",

@antonio2368 antonio2368 May 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The -F fallback never runs. head -500 exits 0 as soon as it sees any byte, and jstack's errors go through 2>&1 into head, so the left side of the || succeeds even when jstack failed. This is the unresponsive-JVM path the PR exists to capture.

f"(jstack {pid} || jstack -F {pid}) 2>&1 | head -500"

or set -o pipefail; at the start if you'd rather keep the current shape.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 87abec5f9fc — restructured to (jstack {pid} 2>&1 || jstack -F {pid} 2>&1) | head -500 so the fallback runs inside the subshell, before head truncates. Smoke-verified: forcing jstack to fail (false substitute) now triggers the -F branch; with the old shape it did not.

Comment on lines +122 to +138
for pid in pids:
try:
# Prefer non-force jstack; fall back to ``-F`` if the JVM is
# unresponsive to the attach mechanism.
dump = node.exec_in_container(
[
"bash",
"-c",
f"jstack {pid} 2>&1 | head -500"
f" || jstack -F {pid} 2>&1 | head -500",
],
nothrow=True,
timeout=30,
)
print(f"Spark hang diag: jstack of PID {pid}:\n{dump}")
except Exception as je:
print(f"Spark hang diag: jstack PID {pid} failed: {str(je)}")

@antonio2368 antonio2368 May 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If executors are also stuck you'll pay 30s per PID. Usually just one driver, so probably fine — head -n 3 on the PID list would cap it if you want a belt.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Capped in 720c43fe7e6 — pids = pids[:3] in Python. Belt for the pathological case where driver + several executors are all hung; normal case (one driver JVM per query) is unchanged.

Comment on lines +166 to +167
"ss -tnp 2>&1 | grep -E ':8080|java' | head -50"
" || echo ' no_matching_sockets'",

@antonio2368 antonio2368 May 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same head-eats-exit-status thing here: when nothing matches, grep fails but head succeeds, so || echo ' no_matching_sockets' never runs and you get empty output instead of the sentinel. set -o pipefail and { grep ... || true; } would do it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 87abec5f9fc — set -o pipefail; ss -tnp 2>&1 | { grep -E ':8080|java' || true; } | head -50 || echo ' no_matching_sockets'. pipefail propagates ss's exit status through head; grep ... || true deliberately swallows the exit-1 that grep produces on no matches, so the sentinel fires only when ss itself fails. Smoke-verified that forcing ss to fail now triggers the sentinel.

groeneai added 2 commits May 14, 2026 05:48
…_diagnostics`

The diagnostic helper added in commit `44b9947afaf` used two shell pipelines
whose fallback branches were unreachable due to exit-code masking by `head`:

  1. `jstack <pid> 2>&1 | head -500 || jstack -F <pid> 2>&1 | head -500`
     The exit code of `cmd | head` is `head`'s, not `cmd`'s. Once `jstack`
     emits even a single byte (or fails to attach with a non-empty error
     message on stderr that gets folded by `2>&1`), `head` returns 0 and
     the `|| jstack -F` fallback never fires. On the exact hang path this
     PR targets — JVM unresponsive to the regular attach mechanism — we
     could silently get an empty thread dump instead of the force-attach
     dump that actually localizes the stuck thread.

  2. `ss -tnp 2>&1 | grep -E ':8080|java' | head -50 || echo ' no_matching_sockets'`
     Same class of bug, deeper pipeline. `head -50`'s exit code masks both
     `ss` and `grep`. The `|| echo` sentinel is unreachable even when `ss`
     itself fails to run.

Reshape both pipelines so the fallback can actually fire:

  1. `(jstack <pid> 2>&1 || jstack -F <pid> 2>&1) | head -500`
     The fallback runs INSIDE the subshell, BEFORE `head` truncates. If
     plain `jstack` fails, `jstack -F` runs; whichever produces output
     gets piped through `head`.

  2. `set -o pipefail; ss -tnp 2>&1 | { grep -E ':8080|java' || true; } | head -50 || echo ' no_matching_sockets'`
     `pipefail` makes the pipeline's exit reflect any failing stage.
     `grep ... || true` deliberately swallows the exit-1 that `grep`
     produces on no matches (we don't want the sentinel for "ran fine,
     just no matches"), so the sentinel fires only when `ss` itself
     fails — the intended semantics.

Smoke-verified locally:
- Old `jstack` pattern: forced-fail `jstack` does NOT trigger fallback (bug).
  New pattern: forced-fail `jstack` DOES trigger fallback.
- Old `ss` pattern: forced-fail `ss` does NOT trigger sentinel (bug).
  New pattern: forced-fail `ss` triggers sentinel; success + no `grep` match
  produces empty output (no false-positive sentinel); success + matches
  produces the matched lines.

Addresses inline review on PR ClickHouse#104801:
- clickhouse-gh[bot] 2026-05-13T07:59:39Z (`jstack`)
- @antonio2368 2026-05-13T12:19:51Z ("address all the comments";
  flagged that the same pattern also bites the `ss` sentinel)
…ng_diagnostics`

Two further follow-ups on the diagnostic helper, addressing the remaining
inline comments from @antonio2368 on PR ClickHouse#104801:

1. `pgrep -f 'org.apache.spark'` matched the wrapper `bash -c` cmdline
   itself on shards where no real Spark JVM is left, so the next loop
   ran `jstack` against an unrelated shell PID and produced a confusing
   "no Java thread state" dump instead of the intended "no Spark JVMs"
   message. Switch the pattern to `[o]rg.apache.spark`: the character
   class `[o]` matches a literal `o`, so the regex still matches a real
   Spark cmdline, but the regex string itself contains `[o]` rather than
   plain `o` and therefore does NOT match the wrapper's own command line.

2. The `jstack` loop has a 30s per-PID timeout. If a hang affects both
   the driver and several executors the helper would consume `30 * N`
   seconds before the test could fail and be reported. In practice there
   is one driver JVM per query, but the safe upper bound is cheap: cap
   the iterated PID list at 3 with a slice. The cap is a belt; the
   normal-case behaviour is unchanged.

Smoke-verified in isolation (`tmp/testpattern.py`): the OLD pattern
self-matches its OLD wrapper cmdline; the NEW pattern does NOT
self-match its NEW wrapper cmdline; both patterns still match a real
Spark JVM cmdline (`java ... org.apache.spark.executor.CoarseGrained...`).

Addresses inline review on PR ClickHouse#104801:
- @antonio2368 2026-05-13T12:16:23Z (`pgrep` self-match)
- @antonio2368 2026-05-13T12:16:24Z (30s-per-PID cap)
@groeneai

Copy link
Copy Markdown
Collaborator Author

@antonio2368 — addressed all four inline comments in two commits.

87abec5f9fc — Fix jstack and ss fallback unreachability:

Block Old shape New shape
jstack (#2) jstack <pid> 2>&1 | head -500 || jstack -F <pid> 2>&1 | head -500 (jstack <pid> 2>&1 || jstack -F <pid> 2>&1) | head -500
ss (#4) ss -tnp 2>&1 | grep -E ':8080|java' | head -50 || echo ' no_matching_sockets' set -o pipefail; ss -tnp 2>&1 | { grep -E ':8080|java' || true; } | head -50 || echo ' no_matching_sockets'

For ss, pipefail propagates ss's exit through head, and grep ... \|\| true deliberately swallows grep's exit-1 on no matches so the sentinel fires only when ss itself fails (the intended semantics).

720c43fe7e6 — Avoid pgrep self-match and cap diagnosed PIDs:

Block Old shape New shape
pgrep (#1) pgrep -f 'org.apache.spark' || true pgrep -f '[o]rg.apache.spark' || true
pid loop (#3) for pid in pids: (unbounded) pids = pids[:3] (Python cap)

The [o] character class matches a literal o, so the regex still matches a real Spark JVM cmdline, but the regex string contains [o] rather than plain o and therefore does not match the wrapper's own bash -c cmdline.

Smoke-verified each change in isolation:

  • jstack fallback: forcing jstack to fail (substitute false) triggers the -F branch with the new shape; old shape silently swallowed the failure.
  • ss sentinel: forcing ss to fail triggers the sentinel; success + no grep matches produces empty output (no false-positive sentinel); success + matches produces the matched lines.
  • pgrep self-match: regex [o]rg.apache.spark matches java ... org.apache.spark.executor.CoarseGrained... (real Spark) but does not match bash -c "pgrep -f '[o]rg.apache.spark' || true" (wrapper). Old regex matched both.
  • PID cap: simple Python slice, normal one-driver case unchanged.

The changes are diagnostic-only and run only on the already-failing path inside execute_spark_query's except block — a passing test cannot be made to fail by them.

The v2 ss-block pipeline (`set -o pipefail; ss | grep | head -50 || ' no_matching_sockets'`)
fixed one bug (sentinel was unreachable without `pipefail`) but introduced another:
under `pipefail`, when `ss` produces more than 50 matching lines, `head -50` closes
its stdin after reading 50 lines. Upstream `ss` (and `grep`) continue writing into
the closed pipe, receive `SIGPIPE`, and exit 141. `pipefail` propagates that as the
pipeline status, so `||` then triggers `echo ' no_matching_sockets'` even though
`ss` succeeded with many matches. This produces a false "no matching sockets"
signal in exactly the scenario where rich diagnostics matter most — a container
with many java/UC connections during a Spark hang.

Reproduction:

    set -o pipefail
    yes ':8080 estab pid=java' | head -100000 \
      | { grep -E ':8080|java' || true; } \
      | head -50 \
      || echo ' no_matching_sockets'
    # → last line of output is ' no_matching_sockets' even though grep
    # succeeded with thousands of matches.

Fix: decouple `ss` execution from filtering/truncation. Capture `ss` into a shell
variable; test its exit status directly via `if ss_output=$(ss -tnp 2>&1); then ...`.
The filtering/truncation stage then operates on the variable with no `pipefail`,
so `head`'s early-close cannot influence the success/failure decision. The
sentinel fires only when `ss` itself fails to run (e.g., not installed, permission
denied).

Smoke-verified across six scenarios: (A) 200 lines fitting pipe buffer, (B) 100K
lines forcing SIGPIPE, (C) 10 matching lines, (D) zero grep matches, (E) `ss`
exits non-zero, (F) command not found. Old pattern false-fires in (B); new
pattern is correct in all six.

Addresses @antonio2368's review feedback and clickhouse-gh[bot]'s inline review
on PR ClickHouse#104801.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Third fix-up pushed: 37e278daa46 — addresses the pipefail + head -50 SIGPIPE false-fire on the ss block flagged by @clickhouse-gh[bot] and seconded by @antonio2368.

Root cause of the v2 bug. The previous shape set -o pipefail; ss | grep | head -50 || sentinel looked safe but had a subtle failure mode: when ss produced more than 50 matching lines, head -50 closed its stdin after reading 50, upstream ss/grep got SIGPIPE (exit 141), pipefail propagated that as the pipeline status, and the || falsely fired no_matching_sockets — exactly when the diagnostic data is most useful (a container under load with many sockets).

Fix. Capture ss's output into a shell variable first; test ss's exit directly via if ss_output=$(ss -tnp 2>&1); then .... The truncation stage operates on the captured variable with no pipefail, so head's SIGPIPE cannot mask success. Sentinel fires only when ss itself fails to run (e.g., binary missing).

if ss_output=$(ss -tnp 2>&1); then
    echo "$ss_output" | { grep -E ":8080|java" || true; } | head -50
else
    echo ' no_matching_sockets'
fi

Pre-PR validation gate (diagnostic-only change).

(a) Deterministic repro set -o pipefail; yes ":8080 estab pid=java" | head -100000 | { grep -E ":8080|java" || true; } | head -50 || echo " no_matching_sockets" reliably ends with no_matching_sockets — bug deterministic for any input >50 lines with backpressure on ss.
(b) Root cause pipefail propagates head -50's SIGPIPE-on-early-close from upstream as pipeline failure, triggering the || sentinel even when ss succeeded.
(c) Fix matches root cause Decouples ss execution from filtering/truncation so the truncation stage cannot influence success/failure detection. Direct exit-status check via shell if.
(d) Test intent preserved Diagnostic-only helper. Runs only inside execute_spark_query's except branch. Cannot make a passing test fail.
(e) Both directions demonstrated Old pattern: 51-line output ending with false no_matching_sockets. New pattern: clean 50-line output, no sentinel.
(f) Fix is general Audited the other 3 helpers (pgrep, jstack, curl) in _capture_spark_hang_diagnostics: none of them combine pipefail + pipe-to-head + sentinel ||, so none have this anti-pattern. Only the ss block needed the fix.

All four prior inline review comments from @antonio2368 (the original review) remain addressed by 87abec5f9fc and 720c43fe7e6. PTAL.

@antonio2368
antonio2368 added this pull request to the merge queue May 14, 2026
Merged via the queue into ClickHouse:master with commit 5794d42 May 14, 2026
167 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 14, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 11, 2026
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]>
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