Skip to content

Run the user-limit case of the external DISTINCT ratio test at 4 GiB to fit the ASan query timeout - #122494

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:external-distinct-user-limit-4gib
Sep 27, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:external-distinct-user-limit-4gib

Conversation

@groeneai

@groeneai groeneai commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #118637
Related: #121477

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

Sized the user-limit case of test_max_bytes_ratio_before_external_distinct to fit the integration harness's 600 second per-query timeout on Address Sanitizer builds.

Description

test_max_bytes_ratio_before_external_distinct[user] times out on Integration tests (amd_asan_ubsan, db disk, 1/8): https://github.com/ClickHouse/ClickHouse/actions/runs/35801986381/job/107020660441, and on master https://github.com/ClickHouse/ClickHouse/actions/runs/35994108559/job/107628302473. Since #121454 merged it has failed 10 of 1974 runs on that job, every time at the harness's unconditional 600 second client cap on the spilling ratio = 0.3 query; the passing runs have a median of 587 s.

The test must consume memory up to the limit it checks, so the limit sets its runtime: at the 10Gi profile it needs 100M keys. This change gives the [user] row its own query, 7M keys of 800 bytes with max_memory_usage_for_user = '4Gi' in its settings, on the same node. A user's memory tracker is reset when its last running query finishes, so the lower limit applies after the other tests. [server] is unchanged.

This re-lands only the [user] half of #121096, which #121477 reverted: the failures behind that revert were in [server], whose limit is checked against RSS and which #121454 now skips on ASan. A user limit counts tracked bytes only, and this row passed all 152 runs of the failing job that carried #121096 (median 76 s). The alternative, skipping [user] on ASan too, leaves this test with no ASan coverage.

max_block_size is pinned to its default, as the feature's own tests do (04493_external_distinct), because the final merge holds a block of every spilled run at once. The harness randomizes it between 8000 and 100000 in half of the runs; at 84000, 92237 and 96000 the spilling query peaks at 3.3 to 3.6 GiB of the 4 GiB limit, and at 88000 it fails. Pinned, it peaks at 2.57 GiB whatever the draw.

Locally, on the ASan build, the spilling query drops from 412 s to 44 s; 50 of 50 repetitions and the whole module, in its usual order, passed.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.848-master (included in 26.10 and later)

test_max_bytes_ratio_before_external_distinct[user] fails on
Integration tests (amd_asan_ubsan, db disk, 1/8) at the integration
harness's 600 second per-query cap (DEFAULT_QUERY_TIMEOUT in
helpers/client.py, applied unconditionally): since ClickHouse#121454 merged, 10 of
1972 runs on that job failed with "timed out after 600 seconds" at the
ratio = 0.3 spilling call, one of them on master, and the passing runs
have a median of 587 s.

The test proves a memory-limit behaviour by consuming memory up to the
limit, so the limit sets its runtime. At node_user's 10Gi profile limit
the rejection half needs an unspilled footprint above 10 GiB, i.e. 100M
~85-byte keys, and on the ASan build the spilling half alone takes 412 s
locally. ClickHouse#121096 had moved both parameters to 4Gi instances with 7M keys
of 800 bytes; ClickHouse#121454 then skipped [server] under ASan, measured on that
tree, and kept [user] because a user limit counts tracked bytes, not RSS;
ClickHouse#121477 reverted ClickHouse#121096 in full on the strength of [server] failures
(its query filters distinct[server]), which put [user] back on the
workload that times out.

This gives the [user] row its own query, the 7M x 800-byte workload with
max_memory_usage_for_user = '4Gi' in its SETTINGS, on the existing
node_user, so no instance is added. A user's memory tracker is reset
when the user's last running query finishes (ProcessList), and the next
query applies its own limit, so the 4 GiB holds after the group_by and
sort tests' 10Gi queries on the same node. [server] keeps its query,
node and ASan skip; only its query moved into the parametrize row. The
trimmed [user] row passed all 152 runs of the failing job that carried
ClickHouse#121096 (median 76 s).

max_block_size is pinned to its default because the final merge holds
one block of every spilled run at once, and a random draw above ~83.9K
rows makes each 800-byte-key block a 128 MiB allocation. Measured on the
ASan build (query_log.memory_usage of the spilling query, pin removed,
draw forced): 84000 -> 3.45 GiB, 92237 -> 3.61 GiB, 96000 -> 3.33 GiB of
the 4 GiB limit, and 88000 rejects the spilling query itself. The peak
is not monotone in the draw (100000 -> 2.73 GiB, 50000 -> 2.04 GiB),
because the size of the unspilled tail depends on how the input chunks
align with the run size. Pinned, it is 2.57 GiB with 58 runs and 14 tail
chunks at every draw. 04493_external_distinct and its siblings pin the
same value.

Measured locally, ASan+UBSan, db disk flavour, harness containers
(cpus: 5, mem_limit: 12g): the spilling query drops from 411.6 s to
43.5 s; with the client cap scaled to 200 s the old test times out and
the new one passes; the unspilled peak is 5.69 GiB, so the ratio = 0
half is still rejected, by "User memory limit exceeded ... maximum:
4.00 GiB"; 50 of 50 repetitions and the whole module twice passed.

Co-Authored-By: Claude Opus 5.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 27, 2026
@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; 2 findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test does not assert that the ratio = 0.3 run spilled or that the ratio = 0 run was rejected by the 4 GiB user limit DISAGREE The unspilled peak is 5.69 GiB, so the spilling run cannot finish under its 4 GiB limit without spilling. Both halves redden when their premise breaks: with 3M rows, or without the query-level 4 GiB, the ratio = 0 run gives DID NOT RAISE. Every measured rejection, including the whole module in CI order, reads User memory limit exceeded ... maximum: 4.00 GiB.
2 ⚠️ ASan runtime and memory cannot be verified from the code DISAGREE ASan, db disk, whole module in CI order twice: [user] 52 s, spilling query 44 s, 5 passed and 1 skipped each time; 50 of 50 repetitions. The same workload and limit passed all 152 runs of Integration tests (amd_asan_ubsan, db disk, 1/8) that carried #121096 (median 76 s).

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20260927-011400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: with the client cap scaled to 200 s the unchanged test fails subprocess.TimeoutExpired ... timed out after 200 seconds at test.py:134 on the ASan build every run (its spilling query takes 412 s here); CI hits the real 600 s cap (10 of 1972 runs, one on master).
b Root cause explained? The test must consume memory up to the limit it checks; at the 10Gi profile the spilling half processes 100M keys and runs at the 600 s cap on ASan, since #121477 reverted the 4Gi sizing that #121454 measured [user] on.
c Fix matches root cause? Yes: limit and workload come down together (4 GiB user limit, 7M x 800 B keys, 5.7 GiB unspilled), so the runtime floor drops to 44 s without raising the cap or skipping.
d Test intent preserved / new tests added? Yes: ratio 0.3 still spills (58 runs) and passes, ratio 0 is still rejected by the user limit (User memory limit exceeded ... maximum: 4.00 GiB); cutting the source to 3M rows, or dropping the 4Gi limit, reddens it with DID NOT RAISE.
e Both directions demonstrated? Yes: same binary and cap, unchanged test FAILED at 200 s, changed test PASSED (spilling query 43.5 s).
f Fix is general across code paths? [server] (skipped on ASan, passes on a debug build), group_by and sort for both nodes (218 to 236 s, far from the cap) checked; only distinct[user] was at the cap.
g Fix generalizes across inputs (params/datatypes/wrappers)? The only randomized input that matters, max_block_size, is pinned: without the pin draws of 84000 to 96000 reach 3.3 to 3.6 GiB of 4 GiB and 88000 fails; pinned, 2.57 GiB at every draw; 50 of 50 repetitions passed.
h Backward compatible? (maintainer-approved exception only) Test-only change, no setting, format or config change.
i Invariants and contracts preserved? The per-query user limit is re-applied after the other tests' 10Gi queries on the same node (checked in module order), the spill threshold follows it (1.20 GiB = 0.3 x 4 GiB), and a user limit has no RSS arm.

Session id: cron:clickhouse-impl-slot-40:20260927-000500

@groeneai
groeneai requested a review from nihalzp September 27, 2026 01:54
@clickhouse-gh

clickhouse-gh Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [41cdda1]

Summary: ✅


AI Review

Summary

This PR narrows the [user] branch of test_max_bytes_ratio_before_external_distinct to a smaller 4 GiB workload and pins max_block_size so the query still exercises spilling but finishes under the integration harness timeout on ASan. I reviewed the current diff, the existing PR discussion, and the relevant DISTINCT memory-threshold code paths, and I did not find a correctness or coverage regression in the updated test.

Final Verdict

✅ No findings.

@alexey-milovidov alexey-milovidov self-assigned this Sep 27, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 27, 2026
Merged via the queue into ClickHouse:master with commit d20ff42 Sep 27, 2026
172 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 27, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 3, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 3, 2026
Resolve the conflict in
test_max_bytes_ratio_before_external_order_group_by_for_server/test.py.
26.9 has neither ClickHouse#120751 (the `sanitizer_build` dict) nor ClickHouse#121454 (the
`limit_follows_rss` parameter and the ASan skip of the `[server]` case),
so only the change of ClickHouse#122494 itself is ported: each case's query moves
into its parametrize row, and the `[user]` row runs the 7M x 800-byte
query with `max_memory_usage_for_user = '4Gi'`. The 26.9 sanitizer
checks and the `[server]` query are kept as they are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-clickhouse-ci-1 added a commit that referenced this pull request Nov 4, 2026
Cherry pick #122494 to 26.9: Run the user-limit case of the external `DISTINCT` ratio test at 4 GiB to fit the ASan query timeout
robot-clickhouse added a commit that referenced this pull request Nov 4, 2026
…STINCT` ratio test at 4 GiB to fit the ASan query timeout
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 4, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 4, 2026
Backport #122494 to 26.9: Run the user-limit case of the external `DISTINCT` ratio test at 4 GiB to fit the ASan query timeout
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…STINCT` ratio test at 4 GiB to fit the ASan query timeout
@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.9-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants