Repository navigation
Fix flaky test 04546_constant_join_shrink_stored_blocks - #111921
alexey-milovidov merged 2 commits into
Conversation
The middle assertion reads the ConstantJoin "Shrinking stored blocks" log line from system.text_log, filtered by a 60-second recency window (event_time >= now() - 60). text_log.event_time is the message emission time, not the flush time, so this window races the duration of the preceding SYSTEM FLUSH LOGS. On a loaded parallel runner the flush can take tens of seconds, and the emitted line then falls out of the window, so count() returns 0 instead of 1. Measured on four failing runs, all on the parallel sanitizer jobs: the flush took 65.8s on master sha 693a303, 59.7s on PR ClickHouse#110886 sha 06b7c4b, 101.2s on PR ClickHouse#111790 and 60.9s on PR ClickHouse#111691 sha 19338ec. In each case the line's age at the assertion was at or just past the 60-second boundary (66s, 60.1s, 101s, 62s), and for the master and ClickHouse#110886 runs the server log holds the shrink line for the exact failing query id, so the shrink did happen and only the time predicate excluded it. Widen the window to 600s. This is safe because the per-test timeout is 600s, so a flush slow enough to push the emitted line past a 600s window would trip the per-test timeout first. The assertion is unchanged and never weakened: rows are scoped exactly by query_id from system.query_log filtered by log_comment and current_database = currentDatabase(), and CI assigns every test run a unique database, so the time predicate only prunes the scan. This mirrors 00177_memory_bound_merging.sh, which uses now() - 600 on the same text_log-via-query_id pattern. Reports: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=693a303c1017477fc39aaa7706af0ec078e13fbc&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110886&sha=06b7c4b127f65dbc45d7c26d867a4801c0742209&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model reviewBefore opening this PR I ran an independent review of the change, across two rounds: a reviewer
Verification behind the change: the root cause was confirmed on four independent failing runs (line Session id: cron:clickhouse-review-slot-11:20260725-213300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260725-184800 |
|
cc @antaljanosbenjamin — could you review this? It widens the |
|
Workflow [PR], commit [c1096ff] Summary: ✅ AI ReviewSummaryThis PR widens the Final VerdictStatus: ✅ Approve |
The assertion matched every historical query_id carrying log_comment = '04546_constant_join_shrink' in the current database. With clickhouse-test --database the database is reused across runs, so a rerun within the recency window could be satisfied by an earlier run's "Shrinking stored blocks" row even when the current run shrank nothing. Widening the window from 60 s to 600 s made that window ten times larger. Taking only the newest matching query_id keeps the wider window doing what it is for (absorbing a slow SYSTEM FLUSH LOGS) without broadening the match set. CI is unaffected either way: clickhouse-test derives a fresh test_<random8> database per run and no stateless job passes --database. Verified against a local server, one fixed database, three consecutive queries with the same log_comment: run 1 shrinks, run 2 does not (compression on keeps the stored blocks below the threshold) -> old subquery yields 1 (stale pass), new subquery yields 0; run 3 shrinks again -> new subquery yields 1, so a genuine regression still fails and a real shrink still passes. clickhouse-test --database, 3 consecutive runs: OK, OK, OK. clickhouse-test default mode: OK; 20 runs with randomized settings: 20/20 OK.
…-join-shrink-flaky Fix flaky test 04546_constant_join_shrink_stored_blocks
Fix flaky test 04546_constant_join_shrink_stored_blocks
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Related: #110886
04546_constant_join_shrink_stored_blocksintermittently outputs0instead of1for its middle assertionshrunk_stored_blocks.The assertion reads the
ConstantJoin"Shrinking stored blocks" line fromsystem.text_log, filtered by a 60-second recency window (event_time >= now() - 60).text_log.event_timeis the message emission time, not the flush time, so the window races the duration of the precedingSYSTEM FLUSH LOGS. On a loaded parallel runner that flush takes tens of seconds, the emitted line ages out of the window, andcount()returns 0.Measured on four failing runs. In each the shrink line was emitted and only the time predicate excluded it, and the line's age at the assertion sits at or just past the 60-second boundary:
SYSTEM FLUSH LOGS693a303c101706b7c4b127f19338ecf1813For the master and #110886 runs the server log holds the line for the exact failing query id (
ConstantJoin: Shrinking stored blocksat 06:26:18.990 and 01:55:02.893), so the shrink did happen.system.text_logdropped nothing: the failing master run logs noQueue is full for system logand its flush offsets advance continuously.The in-place reruns point at runner load rather than at randomized settings: in the #110886 job 19 databases ran this test, 18 of them flushed in 148-420 ms, and only the failing one took 59.7 s. The master job likewise ran the test once, at 65.8 s.
Since the test reached master on 2026-07-24 this signature has hit 10 runs in CIDB: master once plus 9 unrelated PRs, 9 of them on
Stateless tests (amd_tsan, parallel)and one onStateless tests (amd_msan, WasmEdge, parallel, 1/2). Those 10 runs have a median duration of 74 s, against a few seconds for the several thousand passing runs on the same checks.Fix: widen the window to 600 s. The per-test timeout is 600 s (
clickhouse-test --timeoutdefault, and no CI stateless job overrides it), so a flush slow enough to push the line past a 600 s window trips that timeout first; the observed worst case leaves a 6x margin. The assertion is not weakened:count() > 0and the reference are unchanged, and rows stay scoped exactly byquery_idfromsystem.query_logfiltered onlog_commentandcurrent_database = currentDatabase(), with a fresh database per test run, so the time predicate only prunes the scan. If shrinking ever regressed, the line would be absent and the test would still fail. 600 s is the common outer recency bound among the stateless tests that time-bound asystem.text_logread, and the 60 s bound here was the outlier;00177_memory_bound_merging.shusesnow() - 600on the same text_log-via-query_id pattern.Reports:
Version info
26.8.1.153(included in26.8and later)