Skip to content

Fix flaky test 03100_lwu_22_detach_attach_patches - #115279

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-merge-selecting-sleep-03100-lwu-22
Aug 18, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-merge-selecting-sleep-03100-lwu-22

Conversation

@groeneai

@groeneai groeneai commented Aug 18, 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):

Not for changelog.

Description

03100_lwu_22_detach_attach_patches hits the 60 second per-test cap in Fast test
(Timeout! Killing process group). Measured over 30 days: 7 failures across 7 distinct
pull requests, 0 on master. Example report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115234&sha=3d3a0b0cfb7379259dd3158099a5035c6d7099fe&name_0=PR&name_1=Fast%20test

Root cause. Every merge-selection round that selects nothing multiplies the table's
merge-selecting interval by merge_selecting_sleep_slowdown_factor, up to
max_merge_selecting_sleep_ms (default 60000). Externally woken rounds count too, and
mutate() schedules one for every UPDATE and APPLY PATCHES, so the interval saturates
at the 60 second ceiling within a second of CREATE TABLE. Any later statement that has to
wait for the next selection round then pays that interval. This test issues APPLY PATCHES
under mutations_sync = 2, so a single such wait consumes the whole 60 second budget.

Measured locally on one server, reading the interval the engine itself logs
(Scheduling next merge selecting task after Nms): unpinned, the interval reaches 60000 ms
and the longest observed wait between selection rounds is 54832 ms; with the pin the
interval never exceeds 200 ms and the longest wait is 121 ms. Over 20 unpinned randomized
runs, 7 took more than 30 seconds (max 57.51 s, i.e. a near miss of the cap); with the pin,
100 runs all finished in under 3 seconds.

The fix pins merge_selecting_sleep_ms and max_merge_selecting_sleep_ms on the test's two
tables, which is what the merged #110178 did for 02676_optimize_old_parts_replicated and
what 03047_on_fly_mutations_basics_rmt already does. Test only, no product code change.

I did not change the engine here. That the interval grows on externally woken rounds is a
scheduling policy question that affects merge latency and Keeper load for every replicated
table, and justifying a change to it needs multi-replica measurements this PR does not have.


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

The test hits the 60 second per-test cap in Fast test: 7 failures across 7
distinct pull requests over 30 days, 0 on master.

Every merge-selection round that selects nothing multiplies the table's
merge-selecting interval by merge_selecting_sleep_slowdown_factor, up to
max_merge_selecting_sleep_ms (default 60000). Externally woken rounds count
too, and mutate() schedules one for every UPDATE and APPLY PATCHES, so the
interval saturates at the 60 second ceiling within a second of CREATE TABLE.
Any later statement that has to wait for the next selection round then pays
that interval. This test issues APPLY PATCHES under mutations_sync = 2, so a
single such wait consumes its whole budget.

Measured locally, reading the interval the engine itself logs: unpinned, the
interval reaches 60000 ms and the longest observed wait between selection
rounds is 54832 ms; with the pin the interval never exceeds 200 ms and the
longest wait is 121 ms. Over 20 unpinned randomized runs 7 took more than 30
seconds, max 57.51 s against the 60 s cap; with the pin, 100 runs all finished
in under 3 seconds.

Pin merge_selecting_sleep_ms and max_merge_selecting_sleep_ms on both tables,
as the merged ClickHouse#110178 did for 02676_optimize_old_parts_replicated and as
03047_on_fly_mutations_basics_rmt already does. Test only.

The engine behaviour is left alone deliberately. That the interval grows on
externally woken rounds is a scheduling policy question affecting merge latency
and Keeper load for every replicated table, and changing it needs multi-replica
measurements this change does not have.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (0 blockers, 0 major, 2 nits, all resolved)

Independent cold review of the resulting diff, then an independent second-model gate pass, then
adjudication. Reviewer did not write code.

# Severity Finding Verdict
1 💡 nit The Related: #110178 line sits inside the template's HTML comment block, so it does not render DISAGREE. #110178 is cited in the rendered Description prose and the canonical CI report URL is rendered too; there is no closing issue (searched open issues for the test name, detach_attach_patches, merge_selecting_sleep_ms flaky, all empty). The comment block is where the upstream template declares relationships, so moving the line would deviate from the verbatim template.
2 💡 nit Should the unpinned 03100_lwu_* siblings that also use mutations_sync = 2 be pinned in the same change? DISAGREE, deliberately out of scope. Over 90 days the two sibling cap-band hits share one pull request and one check_start_time, i.e. one runner event; the others have a single hit each or a different failure mode. Against this test's 7 failures across 7 distinct pull requests, no sibling shows a pattern. A sibling gets pinned when its own CI log shows the same ceiling-interval chain, not by inference from mutations_sync plus duration.

Second-model gate pass: 0 findings, full coverage of the changed test, its reference, the
scheduling and mutation-assignment functions with callers, comparable tests, and the cited CI
timeline.

Verified independently during review, from source rather than from the author's notes:

  • StorageReplicatedMergeTree.cpp:4633-4641 clamps the interval into
    [merge_selecting_sleep_ms, max_merge_selecting_sleep_ms] every round, so pinning the ceiling
    bounds the stall regardless of which attempt status arrives. MergeTreeSettings.cpp:2682
    requires max >= min, which 100 <= 200 satisfies.
  • The same task also assigns mutations (:4584-4617), which is the causal link between this
    interval and a mutations_sync = 2 wait.
  • The pin cannot neuter the test's three SUPPORT_IS_DISABLED arms, which depend on patch parts
    staying unapplied. Patches are applied only as a rider on a merge of regular parts, a merge
    range needs at least two parts (SimpleMergeSelector.cpp:224, :283), and patch and regular
    parts cannot share a range (DistributedMergePredicate.h:83). This test writes one part per
    partition, so no patch-applying merge is selectable at any cadence. The reference file is
    unchanged.
  • merge_selecting_sleep_ms is not in the test runner's merge-tree settings randomizer, and an
    explicit CREATE TABLE ... SETTINGS clause beats runner injection, so the pin holds in both CI
    configurations that run this test.

Reviewed commit: 98f7919599fb98415dcd9b10c74eb7f9309f4c6c
Session id: cron:clickhouse-review-slot-8:20260818-103900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The mechanism reproduces on every run of tests/clickhouse-test 03100_lwu_22_detach_attach_patches on an unpinned tree: the interval the engine logs (Scheduling next merge selecting task after Nms, read from system.text_log) climbs 6445 -> 60000 ms within 0.79 s of CREATE TABLE, on 35 of 35 unpinned table instances. The resulting stall is visible in wall-clock too: 7 of 20 unpinned randomized runs exceeded 30 s, max 57.51 s against a 60 s cap.
b Root cause explained? Every merge-selection round returning CannotSelect multiplies the table's shared merge_selecting_sleep_ms by merge_selecting_sleep_slowdown_factor and re-clamps to max_merge_selecting_sleep_ms (default 60000). Externally woken rounds count, and mutate() schedules one per UPDATE / APPLY PATCHES, so the interval saturates at the ceiling immediately. A statement that must wait for the next selection round then blocks for that interval. Measured: one round scheduled at 54804 ms with the next round arriving 54832 ms later, inside a test whose harness cap is 60 s.
c Fix matches root cause? Yes. It bounds the exact quantity in (b), the per-table selection interval, to 200 ms. It is not a bound widening, not a data reduction, and not a no-random-* tag; the test's assertions and dataset are untouched.
d Test intent preserved / new tests added? Preserved. Only two CREATE TABLE ... SETTINGS blocks change; every statement, assertion and the .reference file are byte-identical (git status on the .reference is empty). No new test file, deliberately: an assertion that the interval stays low would only re-assert the setting this diff sets, and a timing-shaped test would be flaky by construction. The existing test is the regression test.
e Both directions demonstrated? Yes, on one Build-ID-verified server, arms interleaved. Unpinned: max interval 60000 ms, max observed wait between rounds 54832 ms, 7 of 20 randomized runs over 30 s (max 57.51 s). Pinned: max interval 200 ms, max wait 121 ms, 100 of 100 runs passed in under 3 s. Bucketing every table instance seen: 322 pinned tables capped at exactly 200 ms, 35 unpinned tables at 60000 ms, no overlap.
f Fix is general across code paths? N/A for product code (test-only change). Across the test's own carriers: both ReplicatedMergeTree tables are pinned, source and destination, verified 161 + 161 instances each capped at 200 ms. The AS <src> form does not inherit settings, so the destination needs its own pin; confirmed via system.tables.engine_full. Siblings deliberately not swept: 6 of the structurally similar 03100_lwu_* tests use mutations_sync = 0 and cannot reach this blocking path, and the rest show no CIDB pattern.
g Fix generalizes across inputs? N/A (flaky test setting fix, not a code bug). The pin is a table setting with no type or wrapper surface. It holds under both CI configurations that run this test: 50 of 50 with --no-random-settings --no-random-merge-tree-settings (the Fast test shape) and 50 of 50 with randomization enabled, since an explicit CREATE TABLE ... SETTINGS clause beats runner injection.
h Backward compatible? Yes. No setting is added or re-defaulted, so no SettingsChangesHistory.cpp entry is required; no format, no product code, no compatibility surface is touched. The values are precedented in tree (03047_on_fly_mutations_basics_rmt uses 100 / 200).
i Invariants and contracts preserved? Yes. merge_selecting_sleep_ms and max_merge_selecting_sleep_ms are declared table-level MergeTreeSettings, and the engine clamps its interval into [merge_selecting_sleep_ms, max_merge_selecting_sleep_ms] on every round, so 100 / 200 satisfies the floor <= ceiling ordering the clamp assumes. Lowering the ceiling only shortens a background sleep; it changes no assignment, no correctness path and no locking. Test output is unchanged, which the untouched .reference confirms.

Session id: cron:clickhouse-impl-slot-5:20260818-095700

@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [98f7919]

Summary: ✅


AI Review

Summary

This PR pins merge_selecting_sleep_ms and max_merge_selecting_sleep_ms on the two ReplicatedMergeTree tables in 03100_lwu_22_detach_attach_patches so the test no longer spends most of the Fast test budget waiting for the next merge-selection round. I did not find a correctness or coverage regression in the current code: the change only bounds the background reschedule delay, the test still exercises the same SUPPORT_IS_DISABLED guards for partitions with unapplied patch parts, and Fast test is already green on this head.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 18, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12, could you review this? It is a test-only pin: every merge-selection round that selects nothing multiplies the table's merge-selecting interval up to max_merge_selecting_sleep_ms (60000 by default), externally woken rounds count too, so the interval saturates at the ceiling within a second of CREATE TABLE and one APPLY PATCHES wait under mutations_sync = 2 then eats the whole 60 second Fast test budget.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 18, 2026
@PedroTadim PedroTadim self-assigned this Aug 18, 2026
@PedroTadim
PedroTadim enabled auto-merge August 18, 2026 12:34
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 18, 2026
Merged via the queue into ClickHouse:master with commit 33748e6 Aug 18, 2026
361 of 364 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 18, 2026
@groeneai groeneai added the groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect label Aug 19, 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-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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.

3 participants