Skip to content

Fix flaky test 02676_optimize_old_parts_replicated - #110178

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-flaky-02676-optimize-old-parts
Jul 13, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-flaky-02676-optimize-old-parts

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

Closes: #107506

The test 02676_optimize_old_parts_replicated relies on the automatic whole-partition force merge (min_age_to_force_merge_on_partition_only) reducing the number of active parts within a bounded wait. Under heavy parallel load two effects could starve that merge past the wait window, leaving an extra part and a result differing from the reference (3 instead of 2 in the "disable limit" case):

  • getBestPartitionToOptimizeEntire skips the whole-partition merge while the server-wide background merge pool has fewer free slots than number_of_free_entries_in_pool_to_execute_optimize_entire_partition (default 25). On a busy runner this gate keeps firing.
  • Every merge-selection round that selects nothing multiplies the merge-selecting sleep by merge_selecting_sleep_slowdown_factor up to max_merge_selecting_sleep_ms (default 60s), so retries become sparse.

The fix sets number_of_free_entries_in_pool_to_execute_optimize_entire_partition=1 and max_merge_selecting_sleep_ms=1000 on the partition-only tables - the same guards the analogous test 03357_replacing_min_age_cleanup already uses. No product code changes; only the test.

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.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

  • Merged into: 26.7.1.863 (included in 26.7 and later)

The test relies on the automatic whole-partition force merge
(`min_age_to_force_merge_on_partition_only`) reducing the number of
active parts within a bounded wait. Under heavy parallel load two effects
could starve that merge past the wait window, leaving an extra part and a
result differing from the reference (`3` instead of `2` in the "disable
limit" case):

- `getBestPartitionToOptimizeEntire` skips the whole-partition merge while
  the server-wide background merge pool has fewer free slots than
  `number_of_free_entries_in_pool_to_execute_optimize_entire_partition`
  (default 25). On a busy runner this gate keeps firing.
- Every merge-selection round that selects nothing multiplies the
  merge-selecting sleep by `merge_selecting_sleep_slowdown_factor` up to
  `max_merge_selecting_sleep_ms` (default 60s), so retries become sparse.

Set `number_of_free_entries_in_pool_to_execute_optimize_entire_partition=1`
and `max_merge_selecting_sleep_ms=1000` on the partition-only tables - the
same guards the analogous test 03357_replacing_min_age_cleanup already uses.

Closes: #107506

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [267e0c7]

Summary: ✅


AI Review

Summary

This PR makes 02676_optimize_old_parts_replicated less timing-sensitive by pinning max_merge_selecting_sleep_ms and lowering number_of_free_entries_in_pool_to_execute_optimize_entire_partition on the partition-only ReplicatedMergeTree tables. Those settings match the two code paths that can defer the expected whole-partition merge, and I did not find a correctness problem in the test update.

Missing context / blind spots
  • ⚠️ The dedicated Stateless tests (... flaky check) jobs for this PR were still running while I reviewed. A completed green stress run would close the remaining evidence gap that the flakiness is actually gone.
Final Verdict
  • Status: ✅ Approve

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

@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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Jul 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 13, 2026
Merged via the queue into master with commit 32264bc Jul 13, 2026
176 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-flaky-02676-optimize-old-parts branch July 13, 2026 14:33
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 13, 2026
alexey-milovidov pushed a commit to lneves12/ClickHouse that referenced this pull request Aug 18, 2026
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]>
github-actions Bot pushed a commit to Altinity/ClickHouse that referenced this pull request Aug 24, 2026
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]>
(cherry picked from commit 98f7919)
github-actions Bot pushed a commit to Altinity/ClickHouse that referenced this pull request Aug 24, 2026
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]>
(cherry picked from commit 98f7919)
github-actions Bot pushed a commit to Altinity/ClickHouse that referenced this pull request Aug 24, 2026
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]>
(cherry picked from commit 98f7919)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…optimize-old-parts

Fix flaky test 02676_optimize_old_parts_replicated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Flaky test: 02676_optimize_old_parts_replicated

2 participants