Skip to content

Bound the stress job's three dataset preparation INSERTs - #117626

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci/stress-prep-statement-bound
Sep 3, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci/stress-prep-statement-bound

Conversation

@groeneai

@groeneai groeneai commented Sep 2, 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):

Bound the stress job's three test.hits_s3 / test.hits / test.visits preparation INSERTs in wall-clock time, and dump the server's thread stacks when the bound fires.

Description

Related: #117132 (comment)
Failing job: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117132&sha=36daaa0b2b59eae8c3ddfbd72137c5235282cfb8&name_0=BackportPR&name_1=Stress%20test%20%28amd_tsan%29

Stress test (amd_tsan) burned its whole 10800 s budget inside dataset preparation, before any stress test ran, leaving zero test rows and no stacks. Job 99232249984, under azure_cache: the INSERT INTO test.hits_s3 traced, then 176 minutes of silence until praktika's Timeout exceeded [10800].

Two causes.

  1. The statement never returned. --max_execution_time is enforced cooperatively: CancellationChecker raises the deadline out of band, ending the query only where its threads observe it; a thread parked in blocking I/O never does. Which frame was parked is unknown: the SIGTERM left no stacks, so this PR does not touch src/.

  2. It cost the whole budget because nothing bounded it in wall clock and nothing captured state. Bound each statement of the stateful data preparation #115585 added that bound to prepare_stateful_data, but the stress job never calls it: stress_job.py runs stress_runner.sh instead.

Same mechanism: timeout --verbose --signal=TERM --kill-after=60 900 per statement, the 600 s declared deadline plus 300 s of grace, against a worst measured 187 s. On a proven expiry it writes a named FAIL row, dumps the server's threads to gdb.log, force-stops and exits, mirroring upgrade_runner.sh:161.

An expiry needs the exit code AND timeout's own diagnostic: clickhouse-client exits with the server's error code, so 124 is also an ordinary error, and a forwarded signal prints the same TERM line but exits 143. A 9-arm harness over the shipped helper covers both expiry shapes and five non-expiry ones, both directions.

Only those three are bounded. create_tpch.sh runs eight earlier s3() INSERTs, but they declare no deadline, so there is no unenforced limit to restore; bounding them is a separate change.

Behaviour change: a wedge becomes a named red with stacks, bounded by 900 s plus the 30 min dump, not an opaque 10800 s timeout with nothing to diagnose. Ordinary failures keep today's set +e behaviour.


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


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

`Stress test (amd_tsan)` on ClickHouse#117132's previous head burned its entire 10800 s
budget inside dataset preparation, before any stress test ran, and produced zero
test rows and no stacks to root-cause from. Job 99232249984, sha 36daaa0:
`Using azure storage policy` at 08:47:41 (that echo exists only in the
`RANDOM % 3` branch of the policy selector, so the policy was drawn randomly),
the `INSERT INTO test.hits_s3` traced at 08:47:42, then 176.1 minutes of complete
log silence until praktika's `WARNING: Timeout exceeded [10800]` and
`exit code [-15]`. The CIDB row is `check_status = error`,
`check_duration_ms = 10812856`, `test_name` and `test_status` both empty.

There are two causes and this commit addresses only the second.

`--max_execution_time` is enforced cooperatively: `ProcessList` registers the
query with `CancellationChecker::appendTask`, whose `cancelTask` calls
`QueryStatus::cancelQuery(CancelReason::TIMEOUT)` from a background thread, so
the deadline is raised out of band but ends the query only where the query's own
threads observe it. A thread parked in a blocking call never observes it. Which
frame was parked is unknown, because the job was TERM-killed and left no stacks,
so I am not touching `src/` and not naming a frame.

It cost the whole job budget because nothing bounded those statements in
wall-clock time and nothing captured state when they overran. ClickHouse#115585 added
`timeout --verbose --signal=TERM --kill-after=60 <N>` per statement to
`ClickHouseService.prepare_stateful_data`, but that method is called only from
`ci/jobs/functional_tests.py`; the stress job runs `stress_runner.sh` in docker
instead, so its prep was never covered. This closes that gap with the same
mechanism and adds the stack capture that makes the first cause reachable next
time. It does not paper over that cause: today an occurrence yields no stacks
and no rows, so the cause is unreachable by construction, and the capture is a
prerequisite for an engine fix rather than a substitute for one.

The bound is 900 s, derived from the deadline the statement itself declares plus
300 s of grace for client start, connect, handshake and the final commit. The
worst single statement measured is 187.1 s and the worst three-statement total
429.8 s, so a healthy run cannot reach 900 s unless the server-side deadline has
already failed to fire, which is the condition worth reporting.

The firing predicate is the conjunction of the exit code and `timeout`'s own
diagnostic, because neither half identifies an expiry alone. `clickhouse-client`
returns the server's error code (`programs/client/Client.cpp:483`) and
`M(124, INCORRECT_ELEMENT_OF_SET)` exists, so 124 is also an ordinary query
failure, and 137 is any SIGKILL death including an external or OOM kill.
Symmetrically, GNU `timeout` prints the identical `sending signal TERM to
command` line when it merely forwards a signal it received, exiting 143. That
shape is not hypothetical: it is how the job on record ended. praktika's own
job timeout prints `WARNING: Timeout exceeded [10800] for [2254]` and then sends
SIGTERM to the whole process group (`ci/praktika/utils.py:1087-1098` and
`:1184-1188`, over the group created at `:1148`), which docker forwards into the
container. So a marker-only predicate would dump stacks, force-stop the server
and fail the job during a cancellation, extending exactly what this change
exists to shorten. The marker substrings are deliberately quote-free because
`timeout` renders the command name in locale-dependent quotes, curly under
`C.UTF-8` and straight under `LC_ALL=C`, which also pins the message text.

On a proven expiry the script reports a named `FAIL` row, dumps the server's
threads and stops, rather than preparing data against a wedged server. That
turns an opaque job-level timeout into a named failed sub-result, and it is the
in-tree idiom: `upgrade_runner.sh:161-167` and `stress_tests.lib:319-322` both
bound a statement, dump stacks to the same `gdb.log` and
`clickhouse stop --force`. Exiting loses nothing, because `stress_job.py` runs
`collect_cores`, the OOM probes, `fatal.log` generation and `process_results`
unconditionally after the docker exit, and both `/test_output` and
`/var/log/clickhouse-server` are volume mounts.

Only a proven expiry exits. Any ordinary non-zero exit keeps today's `set +e`
behaviour, which the surrounding comment already documents as intended.

Only those three statements are bounded. `create_tpch.sh`, run earlier at
`stress_runner.sh:70`, loops eight `INSERT ... SELECT FROM s3()` statements that
are also unbounded in wall clock, and `create.sql` and `create_tpcds.sh` attach
their tables over a web disk and insert nothing. I left TPC-H alone on purpose:
those eight declare no `max_execution_time`, so there is no unenforced limit
there to restore, they read from public buckets where a bound would newly fail
jobs that today merely run slowly, and they sit in the `set -e` region rather
than the `set +e` region whose continue-on-failure semantics this change is
deliberately narrower than. Bounding them is a separate change if it is wanted.

Related: ClickHouse#117132 (comment)
Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 2, 2026
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

An independent model reviewed this change against the ClickHouse review skill, and I reviewed it cold
myself before reading the implementation notes. Verdicts below; every disagreement carries the
measurement it rests on.

Finding Verdict
❌ Eight earlier INSERT ... SELECT FROM s3() statements in create_tpch.sh (stress_runner.sh:70) are also unbounded, so "bound each INSERT of the dataset preparation" over-claims. Agreed on the mismatch, and closed by narrowing the claim rather than the diff. The changelog entry and description now name the three statements that are bounded and say plainly that TPC-H's eight are not. Those eight declare no max_execution_time, so unlike the three there is no unenforced limit to restore; they read from public buckets, where a wall-clock bound would newly fail jobs that today merely run slowly; and they sit in the set -e region rather than the set +e region this change is deliberately narrower than. Bounding them is a separate change if it is wanted. Checked the two siblings as well: create.sql and create_tpcds.sh attach their tables over a web disk and insert nothing, so the residual is exactly TPC-H's eight.
❌ The commit message attributed the forwarded-SIGTERM shape to Shell.run(timeout=). Agreed, corrected. stress_job.py:288 is Shell.run(run_command) with no timeout=, so that watchdog never starts and the citation was inert. The live mechanism is praktika's own job timeout, which is what ended the job on record: ci/praktika/utils.py:1087-1098 prints WARNING: Timeout exceeded [10800] for [2254] and sends SIGTERM to the process group (:1184-1188, group created at :1148), which docker forwards into the container.
⚠️ The description quantified the new failure path as "an exit at roughly 2800 s". Agreed, corrected. Not derivable: containment is the 900 s bound plus the 30 min stack dump, on top of however long the job ran before reaching the statement. The description now states those two numbers instead.
💡 The third line of the new header comment restates what the code below it does. Not changed. It is the conclusion of the two-line statement above it about cooperative enforcement; removing it leaves that property with no stated consequence. The block is three lines and the diff carries 6 comment lines against 23 added code lines.
💡 If all three INSERTs succeed, the DROP ... SYNC statements just below them are still unbounded. Noted, not changed. Bounding them and continuing would relocate this hang rather than remove it: a TERMed client can leave the server-side INSERT running, and DROP TABLE datasets.hits_v1 SYNC then needs a lock on the table that query is reading. Exiting on a proven expiry removes that path, which is why the change exits rather than bounding four more statements. No wedged DROP is on record.

After those corrections a second independent round returned no findings, and I re-read each replaced
citation in the tree rather than trusting the acceptance checks, since a commit-message fix can
relocate a wrong claim instead of removing it.

Also verified rather than assumed, since each one could have hidden a defect: both case arms are
reachable (GNU timeout signals its own process group, so --kill-after kills the wrapper too and the
shell sees 137, while the plain expiry yields 124); set -x per-statement attribution survives the new
stderr redirection, checked against a real job log where stress_tests.lib:385 traces despite its own
redirection; the early exit 1 loses no artifacts, because stress_job.py collects cores, the OOM
probes, fatal.log and the results unconditionally after the container exits and both output paths are
volume mounts; the FAIL row is structurally identical to the existing Possible deadlock on shutdown
row; nothing competes with the gdb attach; and the report URL matches CIDB's own report_url for that
job. Per-statement durations were re-measured independently from the last green run: 148 s, 187 s, 94 s.

@clickhouse-gh clickhouse-gh Bot closed this Sep 2, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 2, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 2, 2026
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the defect fixed here (unbounded cost + no diagnostics): a 9-arm harness reproduces both expiry shapes deterministically against the shipped helper text. The engine wedge itself is NOT reproduced, and no src/ change is made on account of it.
b Root cause explained? Yes. --max_execution_time is enforced cooperatively, so CancellationChecker raising the deadline out of band cannot end a thread parked in blocking I/O; and nothing bounded the statement in wall clock or captured state when it overran. #115585 added that bound to prepare_stateful_data, which stress_job.py never calls.
c Fix matches root cause? Yes. The statement already declares its limit; only enforcement was missing, and the CI script is the only layer that can enforce a wall clock over a client the server will not release. No widened bound, no reduced dataset, no skip tag, no src/ guard.
d Test intent preserved / new tests added? Preserved: the set +e tolerance and the healthy path are unchanged (harness arms 3 and 4). No in-tree test file is added, because ci/tests/ and the CI Tests job that ran it were removed from master in #115650. The permanent test is the Stress test (*) family, which runs the changed script on every future run.
e Both directions demonstrated? Yes. Fires on rc 124 with the TERM diagnostic and on rc 137 with the KILL one (exit 1, one named FAIL row, one gdb.log header, force-stop). Does not fire on five non-expiry shapes. Two further arms corrupt each half of the predicate and both stop producing every side effect, so the assertions can fail. All arms passed twice.
f Fix is general across code paths? Yes. Twelve carriers enumerated. upgrade_runner.sh has no such site (it does not do this prep, re-verified), the sibling Python path is already bounded by #115585, the 26.8 copy of the file is byte-identical, and the gdb dump this fix adds is itself bounded.
g Fix generalizes across inputs? Yes for the input space that exists here: the timeout outcome space is exhausted (rc 0, ordinary non-zero, 124 with and without the diagnostic, 137 with and without it, and a forwarded 143). Type wrappers and settings matrices are N/A for a shell script. Locale is the one environmental input, and both the default and LC_ALL=C renderings of the diagnostic are measured.
h Backward compatible? Yes, nothing engaged: no setting, no serialization format, no SettingsChangesHistory entry, no user-facing surface. CI only.
i Invariants and contracts preserved? Yes. set +e continue-on-failure holds on every non-expiry path; the FAIL row uses the file's own row shape, matching an existing row that process_results already parses; the set -x per-statement attribution that every duration measurement depends on is preserved. The early exit loses nothing, because stress_job.py runs collect_cores, the OOM probes, fatal.log and process_results unconditionally after the docker exit and both output directories are volume mounts. All three call sites are plain statements, never a pipeline or subshell, so the exit ends the script.

Session id: cron:clickhouse-impl-slot-7:20260902-045700

@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c8a0a1c]

Summary: ✅


AI Review

Summary

This PR adds a wall-clock timeout wrapper around the three dataset-preparation INSERT statements in stress_runner.sh, reports a named FAIL row when that bound fires, and captures gdb thread stacks before force-stopping the server. I reviewed the current diff, the surrounding stress-job/result-handling code, and the prior PR discussion, and I did not find a correctness or contract issue in the current version.

Final Verdict

✅ No new findings.

@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim, could you review this? It bounds the stress job's three dataset-preparation INSERTs with timeout --signal=TERM --kill-after=60 900 and dumps the server thread stacks when the bound fires, so a prep statement that ignores its own max_execution_time costs one bounded step rather than the full 10800 s job budget. It does not overlap the stress_runner.sh hunk in #114029 that you are reviewing (line 305 there, line 211 here).

@PedroTadim PedroTadim self-assigned this Sep 2, 2026

@alexey-milovidov alexey-milovidov 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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 3, 2026
Merged via the queue into ClickHouse:master with commit c6f0607 Sep 3, 2026
344 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 Sep 3, 2026
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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI 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.

4 participants