Skip to content

Fix flaky tests 05227_lightweight_update_pending_rename and 05331_lightweight_update_before_rename_merge - #125070

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05227-05331-merge-selecting-interval
Oct 10, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05227-05331-merge-selecting-interval

Conversation

@groeneai

@groeneai groeneai commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119144
Related: #124653
Related: #115279

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

05227_lightweight_update_pending_rename (added in #119144) hit the 60 second per-test cap in Fast test (arm_darwin):
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125032&sha=72c0c5818dc13066056600406d463dd36ae39ffe&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29
05331_lightweight_update_before_rename_merge (added in #124653) has the same shape; in Fast test (arm_darwin) it runs p99 55.1 s, max 58.8 s over 30 days.

Root cause. Both tests run RENAME COLUMN ... SETTINGS alter_sync = 0 and then wait with ALTER TABLE ... DELETE WHERE 0 SETTINGS mutations_sync = 2. The DELETE cannot be assigned while the ALTER mutation is unfinished (alters run in strict order), so every merge-selecting round in that window returns CannotSelect and multiplies the interval by 1.2. Finalizing the ALTER mutation schedules no new round, so the DELETE waits out the whole backed-off interval, up to max_merge_selecting_sleep_ms (60 s). In the failing run 05227 waited 22.1 s, then more than 35 s.

The fix pins merge_selecting_sleep_ms = 100, max_merge_selecting_sleep_ms = 200 on every table of both tests, as #115279 did for 03100_lwu_22_detach_attach_patches. Both tests hold their mutations with SYSTEM STOP MERGES or max_replicated_mutations_in_queue = 0, not with timing, so what they check is unchanged.

Validation on a local debug server with the Fast test config, 20 sequential runs per arm:

  • unpinned: the logged interval reached 8.1 to 27.9 s on every table, 62 of 160 DELETEs waited 5 s or more, 05331 took up to 47.8 s;
  • pinned: interval at most 200 ms, every DELETE under 330 ms, each test under 4 s;
  • system.part_log shows the same merges in both arms, and every held mutation still runs only after the test releases it;
  • 50 runs without and 50 with randomization: all pass.

Waking the merge selector when an ALTER mutation is finalized would remove this delay in the engine. I kept this PR test only and can send that separately if wanted.

Server log of the failing run, t_lwu_rename_after (excerpt, server clock UTC+2, table UUID elided)
08:22:08.293884 executeQuery: ALTER TABLE t_lwu_rename_after DELETE WHERE 0 SETTINGS mutations_sync = 2
08:22:08.388435 Created mutation with ID 0000000001 (data versions: all = 3; )
08:22:08.403695 Scheduling next merge selecting task after 29985ms, current attempt status: CannotSelect
08:22:08.427664 Part all_0_0_0_2 committed to zookeeper
08:22:08.442258 Scheduling next merge selecting task after 36278ms, current attempt status: CannotSelect
08:22:08.448625 (ReplicatedMergeTreeQueue): Finishing data alter with version 1 for entry 0000000000
08:22:43.702350 Shutdown started
08:22:43.770574 Code: 341. DB::Exception: Mutation is not finished because table shutdown was called. (UNFINISHED)

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

Version info

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

…htweight_update_before_rename_merge

Both tests run RENAME COLUMN with alter_sync = 0 and then wait with
ALTER TABLE ... DELETE WHERE 0 SETTINGS mutations_sync = 2. The DELETE
cannot be assigned until the ALTER mutation is finalized, every
merge-selecting round in that window returns CannotSelect and multiplies
the interval by 1.2, and finalizing the ALTER mutation schedules no new
round, so the DELETE waits out the backed-off interval (up to
max_merge_selecting_sleep_ms, 60 s). Pin merge_selecting_sleep_ms = 100,
max_merge_selecting_sleep_ms = 200 on every table, as was done for
03100_lwu_22_detach_attach_patches. The mutations stay held by
SYSTEM STOP MERGES / max_replicated_mutations_in_queue = 0, so the tests
check the same thing.

Failing report (Fast test (arm_darwin), 60 s per-test cap):
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125032&sha=72c0c5818dc13066056600406d463dd36ae39ffe&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added 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 labels Oct 10, 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; 0 findings) plus a separate cold review (0 code findings; 2 PR-description nits, both applied before opening).

# Sev Finding Verdict Evidence / action
- - No findings on the diff - Mechanism checked in ReplicatedMergeTreeMergePredicate.cpp (alter-mutation barrier), StorageReplicatedMergeTree::mergeSelectingTask (backoff and clamp) and ReplicatedMergeTreeQueue::tryFinalizeMutations (no merge-selecting wakeup)

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

Session id: cron:clickhouse-review-slot-10:20261010-110400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 20 sequential unpinned runs: the logged merge-selecting interval was at least 8.1 s on all 160 table instances, and 62 of 160 DELETE WHERE 0 waits took 5 s or more (max 11.2 s).
b Root cause explained? The waiting DELETE cannot be assigned until the RENAME mutation is finalized; rounds in that window return CannotSelect and grow the interval by 1.2x, and finalization schedules no new round, so the DELETE waits out the whole interval (up to 60 s).
c Fix matches root cause? Yes. max_merge_selecting_sleep_ms = 200 bounds exactly that wait. No widened bound, no tag, no smaller dataset.
d Test intent preserved / new tests added? Yes. References unchanged; system.part_log shows the same merges in both arms and every held mutation still runs only after the test releases it.
e Both directions demonstrated? Yes. Unpinned: 05331 up to 47.8 s, interval up to 27.9 s. Pinned: interval at most 200 ms, every DELETE under 330 ms, each test under 4 s.
f Fix is general across code paths? All 8 tables of the two tests that have this shape are pinned; other alter_sync = 0 + mutations_sync = 2 replicated tests have neither the shape nor the tail.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test settings fix). 50 randomized runs pass.
h Backward compatible? (maintainer-approved exception only) N/A, no setting, default or format change.
i Invariants and contracts preserved? N/A for product code; the tests' own invariant (mutations held until released) is unchanged, see d.

Session id: cron:clickhouse-impl-slot-4:20261010-094600

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [67fa667]

Summary: ✅


AI Review

Summary

This PR narrows the merge-selector backoff only inside the two flaky ReplicatedMergeTree stateless tests by pinning merge_selecting_sleep_ms and max_merge_selecting_sleep_ms, which matches the failure mode described in the PR and keeps the tests’ behavioral contract intact. I read the current diff and surrounding test logic, checked the prior PR discussion, and did not find a correctness, isolation, or coverage issue worth flagging.

Final Verdict

✅ No findings. The change is appropriately scoped to test-only settings, and the current Praktika report for https://github.com/ClickHouse/ClickHouse/pull/125070 is all green.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 10, 2026
@groeneai
groeneai requested a review from tavplubix October 10, 2026 11:37
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 10, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 10, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 10, 2026
Merged via the queue into ClickHouse:master with commit d339929 Oct 10, 2026
163 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 Oct 10, 2026
@clickhouse-gh clickhouse-gh Bot added comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). 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-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). 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