Skip to content

Make finished_mutations_to_keep=0 mean "keep no finished mutations" - #104876

Open
nikitamikhaylov wants to merge 1 commit into
masterfrom
finished-mutations-to-keep-zero-means-none
Open

nikitamikhaylov wants to merge 1 commit into
masterfrom
finished-mutations-to-keep-zero-means-none

Conversation

@nikitamikhaylov

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Previously, setting finished_mutations_to_keep to 0 was interpreted as "keep all finished mutation entries" (the cleanup code returned early on the zero value). Flip the semantics so that 0 means "do not keep any finished mutation entry" - the natural reading of the setting name.

Previously, setting `finished_mutations_to_keep` to 0 was interpreted as
"keep all finished mutation entries" (the cleanup code returned early on
the zero value). Flip the semantics so that 0 means "do not keep any
finished mutation entry" - the natural reading of the setting name.

Update the setting's inline documentation, the ALTER docs, and the two
existing tests that asserted the old behaviour.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@nikitamikhaylov nikitamikhaylov changed the title Make finished_mutations_to_keep=0 mean "keep no finished mutations" Make finished_mutations_to_keep=0 mean "keep no finished mutations" May 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1c22c40]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, flaky check) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
Stateless tests (amd_tsan, flaky check) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
Stateless tests (amd_msan, flaky check) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
Stateless tests (amd_debug, flaky check) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
02994_merge_tree_mutations_cleanup FAIL cidb
Stateless tests (amd_asan_ubsan, distributed plan, parallel, 1/2) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential) FAIL
Server died FAIL cidb, issue
03716_mutations_parts_in_progress_rmt UNKNOWN cidb
03716_mutations_parts_postpone_reasons_mt UNKNOWN cidb
Segmentation fault (STID: 0883-5109) FAIL cidb
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DatabaseReplicated, WasmEdge, parallel) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
Stateless tests (amd_llvm_coverage, AsyncInsert, s3 storage, parallel) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb
00952_insert_into_distributed_with_materialized_column NOT_FAILED cidb
03008_deduplication_cases_from_docs NOT_FAILED cidb
02912_ingestion_mv_deduplication NOT_FAILED cidb
Stateless tests (amd_debug, parallel) FAIL
02994_merge_tree_mutations_cleanup FAIL cidb

AI Review

Summary

This PR flips finished_mutations_to_keep = 0 semantics to keep no finished mutation entries and updates docs/tests accordingly. The code changes are coherent, but one updated test expectation is timing-dependent with current settings, and the PR metadata should classify this as backward-incompatible.

PR Metadata
  • 💡 Changelog category is likely mismatched: this change alters behavior for existing finished_mutations_to_keep = 0 configurations, so Backward Incompatible Change is a better fit than Improvement.
  • 💡 Changelog entry should add migration guidance describing how to preserve previous keep-all behavior for users who currently rely on finished_mutations_to_keep = 0.
Findings
  • ⚠️ Majors

  • [tests/queries/0_stateless/02994_merge_tree_mutations_cleanup.reference:2] The new expected 0 after 5 seconds depends on background cleanup running quickly, but the corresponding SQL test does not set deterministic cleanup cadence (cleanup_delay_period, cleanup_delay_period_random_add). With defaults (cleanup_delay_period = 30 plus jitter), clearOldMutations is not guaranteed to run within that window, so this assertion can be flaky.
    Suggested fix: in 02994_merge_tree_mutations_cleanup.sql.j2, set cleanup_delay_period = 1, cleanup_delay_period_random_add = 0, and optionally cleanup_thread_preferred_points_per_iteration = 0 for both tables.

  • 💡 Nits

  • [src/Storages/MergeTree/MergeTreeSettings.cpp:1639] Since this line changes existing semantics for finished_mutations_to_keep = 0, align PR metadata with a backward-incompatible change and include explicit migration text.

Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
  1. Make the 02994 cleanup expectation deterministic before asserting zero retained mutations.
  2. Update changelog metadata/text to reflect backward-incompatible semantics and provide migration guidance.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 13, 2026
@@ -1,4 +1,4 @@
mutations after ALTER for data_rmt 1
mutations after cleanup for data_rmt 1
mutations after cleanup for data_rmt 0

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 new expected value depends on background cleanup running within the 5-second wait in 02994_merge_tree_mutations_cleanup.sql.j2, but that test still uses default cleanup scheduling.

With defaults (cleanup_delay_period = 30 and cleanup_delay_period_random_add = 10), clearOldMutations is not guaranteed to run within 5 seconds, so this can become flaky (or fail) depending on timing.

Please set deterministic cleanup settings in the test table definitions (for example cleanup_delay_period = 1, cleanup_delay_period_random_add = 0, and optionally cleanup_thread_preferred_points_per_iteration = 0).

DECLARE(UInt64, finished_mutations_to_keep, 100, R"(
How many records about mutations that are done to keep. If zero, then keep
all of them.
How many records about mutations that are done to keep. If zero, then no

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 flips the meaning of finished_mutations_to_keep = 0 for existing deployments (from "keep all" to "keep none").

Because existing configurations can change behavior after upgrade, this looks backward-incompatible. Please consider using Backward Incompatible Change in PR metadata and adding explicit migration guidance in the changelog entry (how to preserve the previous keep-all behavior).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a valid point

@azat azat self-assigned this May 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (13/13) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Dear @azat, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@abashkeev abashkeev added the comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). label Sep 4, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 14, 2026
@nikitamikhaylov nikitamikhaylov added the hold Skip for auto-updating. label Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). hold Skip for auto-updating. pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants