Skip to content

Fix flaky 01666_merge_tree_max_query_limit: pin max_threads=1 on the holder query - #111528

Merged
devcrafter merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-01666-merge-tree-max-query-limit-holder-max-threads
Jul 28, 2026
Merged

devcrafter merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-01666-merge-tree-max-query-limit-holder-max-threads

Conversation

@groeneai

@groeneai groeneai commented Jul 23, 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

The test starts a long-running "holder" query
select sleepEachRow(0.1) from simple settings max_block_size = 1 to occupy the single
max_concurrent_queries slot, then asserts that concurrent reads are throttled with
error 202.

The holder pinned only max_block_size and left max_threads to the CI settings
randomizer. When the randomizer picks a high max_threads together with a low
merge_tree_min_rows_for_concurrent_read, the single part is split into many concurrent
read streams (MergeTreeSelect(pool: ReadPool, algorithm: Thread) x N), so the 5000
sleepEachRow(0.1) rows run in parallel and the holder finishes early. Once it finishes
it releases the concurrency slot, so a later throttle assertion returns success instead
of 202 and the test fails with "Expected error code: 202 but got: 0".

Pinning max_threads = 1 forces a single sequential read stream regardless of the
randomized settings, so the holder reads the rows one at a time and stays alive for the
whole test. The throttle assertions are unchanged.

Found by CI triage on #108091 (Stateless tests, amd_tsan, s3 storage, parallel).

Version info

  • Merged into: 26.8.1.265 (included in 26.8 and later)

…holder query

The test spins up a long-running "holder" query
(select sleepEachRow(0.1) from simple settings max_block_size = 1)
to occupy the single max_concurrent_queries slot, then asserts that
concurrent reads are throttled with error 202.

The holder pinned only max_block_size and left max_threads to the CI
settings randomizer. When the randomizer sets a high max_threads and a
low merge_tree_min_rows_for_concurrent_read, the single part is split
into many concurrent read streams
(MergeTreeSelect(pool: ReadPool, algorithm: Thread) x N), so the 5000
sleepEachRow(0.1) rows run in parallel and the holder finishes early.
Once the holder finishes it releases the concurrency slot, so a later
throttle assertion returns success instead of 202, and the test fails
with "Expected error code: 202 but got: 0".

Pinning max_threads = 1 forces a single sequential read stream
regardless of the randomized settings, so the holder reads the rows
one at a time and stays alive for the whole test, keeping the
concurrency slot occupied. The throttle assertions are unchanged.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With the holder run under harness-style settings (--max_threads=32 --merge_tree_min_rows_for_concurrent_read=1), the old holder self-completes within a ~15s window, so a later 202 assertion gets code 0 on demand.
b Root cause explained? Yes. High max_threads + low merge_tree_min_rows_for_concurrent_read split the single part into N concurrent read streams (MergeTreeSelect(pool: ReadPool, algorithm: Thread) x N), so the 5000 sleepEachRow(0.1) rows run in parallel and the holder finishes early, releasing the max_concurrent_queries slot before a later throttle assertion.
c Fix matches root cause? Yes. max_threads = 1 forces a single sequential read stream (verified via EXPLAIN PIPELINE: 0 -> 1), so the holder cannot drain early. It removes the randomization variable that shortened the holder rather than masking the symptom.
d Test intent preserved? Yes. The three error-202 throttle assertions are untouched; .reference is unchanged. Only the holder is made to reliably occupy the slot.
e Demonstrated both directions? Yes. Same settings/window: old holder gone after the window -> 2nd check code 0 (fail); pinned holder still alive -> 2nd check 202 (pass). Plus 50/50 on local disk and 50/50 on s3 storage with randomization.
f Fix general, not a narrow patch? N/A (test-only change, no code bug / no sibling code paths).
g Generalizes across inputs/types? N/A (test-only change, no input/type matrix).
h Backward compatible? N/A (test-only; a query-level SETTINGS pin in a test does not change server behavior).
i Invariants/contracts preserved? N/A (test-only; no invariant touched).

Session id: cron:clickhouse-author-slot-1:20260723-045300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).

Coverage: read the full changed test and reference, the runner randomization/precedence logic, the MergeTree planning and concurrency-holder paths, sibling tests, the parallel-replicas blacklist, and the CI report. Nothing material was uncovered; no blockers, majors, or nits raised.

Session id: cron:clickhouse-author-slot-1:20260723-045300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tiandiwonder — could you review this? Test-only flaky fix: it pins max_threads = 1 on the long-running holder query in 01666_merge_tree_max_query_limit so it reads sequentially and keeps the max_concurrent_queries slot occupied for the whole test, instead of finishing early when the settings randomizer splits it into parallel read streams. The error-202 throttle assertions are unchanged.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b0ed095]

Summary: ✅


AI Review

Summary

This PR makes 01666_merge_tree_max_query_limit deterministic by pinning max_threads = 1 on the background holder query, so randomized concurrent-read settings can no longer split the single part into multiple read streams and let the holder finish before the later 202 assertions. In the current code, InterpreterSelectQuery derives max_streams from max_threads, and ReadFromMergeTree only expands the stream count when the requested count is already greater than 1, so the fix matches the actual flake mechanism without weakening the test contract. I did not find remaining correctness, coverage, or PR metadata issues, and the current PR CI is green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 23, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 6e4780b

CI fully finished (only CH Inc sync pending, exempt; Finish Workflow SUCCESS). The one red is a coverage-lane job-level abort, not this PR's test. 01666_merge_tree_max_query_limit (the test this PR pins) does not appear failing anywhere on this head.

Check / test Reason Owner / fixing PR
Stateless tests (amd_llvm_coverage, AsyncInsert, s3 storage, parallel) coverage-lane job-level abort (no per-test failure row; harness/collection error; 33 PRs / 0 master in 14d) #109747 (ours, open) + #110048 (external, open)
Sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260723-193000

@alexey-milovidov alexey-milovidov self-assigned this Jul 26, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, as #110048 is merged, please update the branch.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Branch updated: merged master into it as 09e192090435e7783a9a6dca526e6d8405b5bc80.

#110048 (merge commit 2bf3033313d0a39f007b9cf892c1ef70c68f28fb) is now an ancestor of the head, so the coverage-lane abort that was the only red on the previous head should be gone. git merge-base --is-ancestor confirms it.

The merge was clean and the PR content is unchanged: still one file, one line (max_threads = 1 on the holder query), no submodule pin drift.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 09e1920

CI fully finished on this head (Config Workflow, Fast test, Style check, CH Inc sync and Finish Workflow all green; no job queued or running). Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / Server died + 02525_range_hashed_dictionary_update_field chronic macOS native-runner hang: the server stops answering and the in-flight test is recorded as the victim. Both rows are one event. 59 hits / 54 distinct PRs / 0 master in 30d for this exact signature a fix task is investigating at full effort (fixing-PR link to follow here)

Not caused by this PR: the whole diff is one file, tests/queries/0_stateless/01666_merge_tree_max_query_limit.sh, a max_threads = 1 pin on a single query. It cannot reach dictionaries and it cannot make a macOS runner's server disappear. The cleanest control is the Linux Fast test on the same head, which is green.

02525_range_hashed_dictionary_update_field is not independently flaky: 2 hits in 30d, this one plus one unrelated Stateless tests (amd_debug, parallel) hit on a different PR.

The crash-mode half of this family was fixed by #111656 (merged 2026-07-24) and that fix is already an ancestor of this head, so it is not the owner of this hang-mode failure.

Session id: cron:our-pr-ci-monitor:20260727-023000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Owner update for the Fast test (arm_darwin) / Server died line on this pull request's CI finish
ledger.

That failure is a hang on the macOS native runner, not a fault in this pull request's diff. It was
introduced by #109825; the crash half was fixed by #111656, and a ~2.7% residual hang half remains
with no open tracking issue. I posted the full forensics (global instant freeze, 17 of 21 system
logs stuck mid-flush, the named failing test always a _cleanup_database victim, plus the job-level
rate step from 0.04% to 4.3% at the #109825 merge hour) here:

#111579 (comment)

No fixing pull request exists yet, and I am deliberately not opening a speculative one: the stuck
lock cannot be named without a thread dump, the lldb dump is currently discarded by the test
harness (covered by the open #107173), and I have no native macOS-arm64 host to reproduce or
validate a fix on. I have asked the component owner who carries the hang half. When a fixing pull
request opens, I will post the link here.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b0ed095

CI fully finished on this head: Finish Workflow, Mergeable Check, PR, Style check and CH Inc sync all green, no job queued or running, zero FAIL/ERROR test rows across all checks (107648 result rows ingested for this commit).

Check / test Reason Owner / fixing PR
(none) - -

This head is a plain master merge on top of the previously ledgered 09e192090435. The two reds that head carried (Fast test (arm_darwin) / 02525_range_hashed_dictionary_update_field + Server died) are gone on this build.

Session id: cron:our-pr-ci-monitor:20260728-053000

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.

4 participants