Skip to content

Skip the RSS-based half of the external DISTINCT memory test under ASan - #121454

Merged
nihalzp merged 2 commits into
masterfrom
fix-flaky-external-distinct-memory-limit-asan
Sep 22, 2026
Merged

nihalzp merged 2 commits into
masterfrom
fix-flaky-external-distinct-memory-limit-asan

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Related: #121096
Related: #104965

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

Skipped the RSS-based parameter of test_max_bytes_ratio_before_external_distinct on Address Sanitizer builds, where it fails about half of the time.

Description

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=e033cea645358fa98672769636b5c979d8adcd26&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%201%2F8%29

test_max_bytes_ratio_before_external_distinct[server] fails on Integration tests (amd_asan_ubsan, db disk, 1/8) in about half of the runs that carry #121096, which resized the test on 2026-09-21 to fit the harness's per-query timeout. Since it merged, the parameter has 16 failures against 17 passes on that job, 4 of the failures on master; [user] has 33 passes and no failures, and neither parameter has failed on arm_binary or amd_llvm_coverage. Before #121096 the same test failed the other way, by exceeding the 600 second client timeout, so this is the second failure mode of the same oracle rather than a new one.

Post-#121096 runs on the failing job, per parameter
SELECT
    splitByString('::', test_name)[2] AS param,
    test_status,
    count() AS cnt
FROM checks
WHERE check_name = 'Integration tests (amd_asan_ubsan, db disk, 1/8)'
  AND test_name LIKE '%test_max_bytes_ratio_before_external_distinct%'
  AND check_start_time > '2026-09-21 12:00:00'
  AND test_duration_ms < 200000   -- excludes PR branches still on the pre-#121096 workload
GROUP BY param, test_status
┌─param─────────────────────────────────────────────────┬─test_status─┬─cnt─┐
│ test_max_bytes_ratio_before_external_distinct[server] │ FAIL        │  16 │
│ test_max_bytes_ratio_before_external_distinct[server] │ OK          │  17 │
│ test_max_bytes_ratio_before_external_distinct[user]   │ OK          │  33 │
└───────────────────────────────────────────────────────┴─────────────┴─────┘

What fails

It is the spilling half of the test, the one that is supposed to succeed, and it is rejected on RSS rather than on tracked memory:

Code: 241. DB::Exception: (total) memory limit exceeded: would use 2.65 GiB
(attempt to allocate chunk of 64.50 MiB), current RSS: 3.95 GiB, maximum: 4.00 GiB.
... While executing BufferingFromFileSource.

max_server_memory_usage is enforced against RSS, and an Address Sanitizer build's RSS carries redzones and quarantined chunks that the memory tracker never sees. Here that gap is 1.3 GiB: the server log has (total) current memory usage: 2.01 GiB against a tracked baseline of 10 MiB, so the whole gap is allocator overhead.

Why the node has no room for it

The query behaves as designed. With max_bytes_ratio_before_external_distinct = 0.3 against the node's 4 GiB it spills at 1.2 GiB, and the server log shows what the final merge then holds open at once:

Extracting 1111953 DISTINCT suppression keys (set memory: 992.00 MiB) into sorted runs
Preparing final DISTINCT merge (temporary runs: 58, in-memory chunks: 15, restore input order: false)

54 suppression runs of 15.98 MiB, 4 ordinary runs of 958.83 MiB read back in 64.50 MiB blocks, and a 15 chunk in-memory tail, all live simultaneously — roughly twice the spill threshold, which is what the 2.65 GiB in the exception is. That leaves about 1.3 GiB of the node spare, exactly what the sanitizer overhead consumes, so the test sits on the break-even point and flips on run-to-run variation.

Raising the limit does not buy margin, because the unspilled peak has to stay above it and #121096 already sized the workload to the 600 second per-query cap; lowering it is worse, because the sanitizer surcharge is a fixed cost that a smaller budget absorbs less well.

The fix

[user] is unaffected by construction — max_memory_usage_for_user counts tracked bytes rather than RSS — so only [server], and only on an Address Sanitizer build, is skipped. The file already skips this test on Thread and Memory Sanitizer builds for the same class of reason. Both parameters keep running on arm_binary (36 s) and on amd_llvm_coverage.

Not fixed here

Reading all 58 runs back concurrently puts the entire spilled hash set back into memory, so the merge phase of external DISTINCT needs about twice the spill threshold rather than staying under it. External ORDER BY has had the same shape of problem (ff8e0db56d79). That is a property of the new operator's design rather than of this test, and bounding the merge fan-in belongs with the feature rather than with a CI fix.


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

Version info

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

`test_max_bytes_ratio_before_external_distinct[server]` fails on `Integration tests
(amd_asan_ubsan, db disk, 1/8)` in about half of the runs that carry #121096: 16 failures
against 17 passes since it merged on 2026-09-21, 4 of them on `master`. The `[user]`
parameter passed 33 out of 33 over the same window.

It is the spilling half that fails, and it is rejected on RSS rather than on tracked
memory: `(total) memory limit exceeded: would use 2.65 GiB (attempt to allocate chunk of
64.50 MiB), current RSS: 3.95 GiB, maximum: 4.00 GiB`. `max_server_memory_usage` is
enforced against RSS, and an Address Sanitizer build's RSS carries redzones and
quarantined chunks that the memory tracker never sees - 1.3 GiB of them here.

The query itself behaves as designed. With `max_bytes_ratio_before_external_distinct =
0.3` against the node's 4 GiB it spills at 1.2 GiB, and the final merge then holds 54
suppression runs of 16 MiB, 4 ordinary runs read back in 64.50 MiB blocks and a 15 chunk
in-memory tail open at once, so it needs roughly twice the spill threshold. That leaves
about 1.3 GiB of the node spare, which is exactly what the sanitizer overhead consumes.
Raising the limit does not buy margin, because the unspilled peak has to stay above it,
and #121096 already sized the workload to the harness's 600 second per-query cap.

The `[user]` parameter is unaffected by construction, because
`max_memory_usage_for_user` counts tracked bytes rather than RSS, so only the `[server]`
parameter is skipped and only on an Address Sanitizer build. Both parameters keep running
on `arm_binary` and on `amd_llvm_coverage`, where neither has failed.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=e033cea645358fa98672769636b5c979d8adcd26&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%201%2F8%29
Related: #121096
@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d2b0cb0]

Summary: ✅


AI Review

Summary

This PR skips test_max_bytes_ratio_before_external_distinct[server] under ASan by guarding the whole server parameter when the limit follows RSS. The flaky part described in the PR is the spill-success branch, but the current placement also removes the deterministic ratio = 0 regression check for max_server_memory_usage, so the change weakens coverage more than the PR claims.

Findings

⚠️ Majors

  • [tests/integration/test_max_bytes_ratio_before_external_order_group_by_for_server/test.py:113-137] The new if limit_follows_rss and sanitizer_build["address"] branch returns before both halves of test_max_bytes_ratio_before_external_distinct. The flaky half is the first query with max_bytes_ratio_before_external_distinct = 0.3, but the second query is still the deterministic guard that the same DISTINCT workload fails once spilling is disabled. With the skip here, ASan stops exercising any max_server_memory_usage path for external DISTINCT, so a regression in the failure arm will land unnoticed.
    Suggested fix: split the success and failure assertions into separate tests, or move the ASan skip so only the spill-success branch is bypassed while the ratio = 0 failure check still runs for server.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: keep the ASan workaround limited to the flaky spill-success assertion and preserve a deterministic server-limit regression check for external DISTINCT.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 21, 2026
pytest.skip("TSan build is skipped due to memory overhead")
if sanitizer_build["memory"]:
pytest.skip("Memory Sanitizer uses more memory, making precise memory limit testing unreliable")
if limit_follows_rss and sanitizer_build["address"]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This skips the entire [server] parameter, but the flakiness described in the PR only affects the first half of the test: the max_bytes_ratio_before_external_distinct = 0.3 query that is supposed to spill and finish. The second half is still the deterministic regression check that the same DISTINCT query fails under max_server_memory_usage when spilling is disabled. With this guard, ASan stops testing any server-limit behavior for external DISTINCT. Can we split the success and failure assertions, or move the skip so only the spill-success branch is bypassed?

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looks ok.

…l-distinct-memory-limit-asan

# Conflicts:
#	tests/integration/test_max_bytes_ratio_before_external_order_group_by_for_server/test.py
@nihalzp
nihalzp enabled auto-merge September 22, 2026 09:35
@nihalzp
nihalzp added this pull request to the merge queue Sep 22, 2026
Merged via the queue into master with commit 7b3eac9 Sep 22, 2026
177 checks passed
@nihalzp
nihalzp deleted the fix-flaky-external-distinct-memory-limit-asan branch September 22, 2026 12:43
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 2026
pull Bot pushed a commit to Dream-hu/ClickHouse that referenced this pull request Sep 27, 2026
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 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]>
PedroTadim added a commit that referenced this pull request Nov 5, 2026
Cherry pick #121454 to 26.9: Skip the RSS-based half of the external DISTINCT memory test under ASan
robot-clickhouse added a commit that referenced this pull request Nov 5, 2026
@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 5, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 5, 2026
Backport #121454 to 26.9: Skip the RSS-based half of the external DISTINCT memory test under ASan
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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