Skip to content

Add always_fetch_mutated_part setting - #113020

Merged
alexey-milovidov merged 17 commits into
ClickHouse:masterfrom
rorylshanks:add-always-fetch-mutated-part
Aug 9, 2026
Merged

alexey-milovidov merged 17 commits into
ClickHouse:masterfrom
rorylshanks:add-always-fetch-mutated-part

Conversation

@rorylshanks

@rorylshanks rorylshanks commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Adds the always_fetch_mutated_part setting for replicated MergeTree tables. When enabled, the replica fetches parts produced by MUTATE_PART entries from another active replica instead of executing mutations locally.

The behavior is analogous to always_fetch_merged_part. At least one replica must keep the setting disabled so that mutated parts are produced.

Changelog category (leave one):

  • New Feature

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

Add the always_fetch_mutated_part setting, which allows a replica to download mutated parts from other replicas instead of executing mutations locally.

Version info

  • Merged into: 26.8.1.1036 (included in 26.8 and later)

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 2, 2026
@alexey-milovidov alexey-milovidov self-assigned this Aug 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [808ae47]

Summary: ✅


AI Review

Summary

This PR adds the always_fetch_mutated_part setting for ReplicatedMergeTree, makes fetch-only replicas back off instead of spinning while they wait for another replica to publish the mutated part, and fail-closes synchronous waits that cannot observe remote mutation failures. I did not find any remaining blockers or majors in the current head; the earlier review concerns about false latest_fail_reason, tight retry loops, and hanging synchronous waits are addressed in the code and covered by the added integration tests.

Final Verdict

✅ No remaining review findings on the current PR head.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.80% +0.00%

Changed lines: Changed C/C++ lines covered: 75/76 (98.68%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Aug 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 808ae47fb with master 31081d9f0 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 16bd8e494; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.17 MiB 687.15 MiB -3.02 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

49 translation units recompiled, 544 s compile time in total, 49 of them have a recent master baseline.

Job report

rorylshanks and others added 6 commits August 3, 2026 13:09
…th always_fetch_mutated_part

When `always_fetch_mutated_part` is enabled, the replica went to `executeFetch`
with `need_to_check_missing_part_in_fetch = true`, although no replica can have
`entry.new_part_name` until some replica finishes the mutation. The first attempt
therefore threw `NO_REPLICA_HAS_PART`, which was recorded as `latest_fail_reason`
in `system.mutations`, and `ALTER ... SETTINGS mutations_sync = 1/2` issued on the
fetch-only replica could fail for long-running mutations even while another replica
was mutating the part successfully.

Pass `need_to_check_missing_part_in_fetch = false` instead, so `executeFetch`
quietly returns and the entry is retried later (the same pattern as waiting for
another replica to produce a recompressed part), and add an integration test that
holds the mutation on the executing replica and checks that the fetch-only replica
does not record `NO_REPLICA_HAS_PART` while waiting.

Co-Authored-By: Claude Fable 5 <[email protected]>
Fetch retries on the fetch-only replica are paced by the background task
backoff, so the default 20 seconds may be tight on slow CI runners.

Co-Authored-By: Claude Fable 5 <[email protected]>
…he test

The `MutateFromLogEntryTask` logger name contains the table UUID, not the
table name, so the log-line wait never matched.

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

Copy link
Copy Markdown
Member

🕵 Addressed the AI-review blocker: with always_fetch_mutated_part enabled, MutateFromLogEntryTask::prepare now returns need_to_check_missing_part_in_fetch = false, so while no replica has produced the mutated part yet, executeFetch quietly lets the entry be retried later (the same pattern as waiting for another replica to produce a recompressed part) instead of throwing NO_REPLICA_HAS_PART. Previously that exception was recorded as latest_fail_reason in system.mutations, so ALTER ... SETTINGS mutations_sync = 1/2 issued on the fetch-only replica could fail for long-running mutations. Retries are paced by the background task backoff, so there is no hot loop.

Also added an integration test that holds the mutation on the executing replica with SYSTEM STOP MERGES and checks that the fetch-only replica does not record NO_REPLICA_HAS_PART while waiting. All three tests in test_always_fetch_merged pass locally.

The two stress-test failures are unrelated to this PR: "Logical error: ColumnBLOB should be converted to a regular column before usage" is tracked in #113165, and "Logical error: Join is supported only for pipelines with one output port" has a fix in progress in #109393.

alexey-milovidov and others added 2 commits August 4, 2026 21:06
…T` entries

The setting short-circuits only `MUTATE_PART` replication log entries.
Patch parts created by lightweight updates are applied during merges by
`MergeTask`, which is governed by `always_fetch_merged_part` instead, so
narrow the documented contract accordingly.

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

Copy link
Copy Markdown
Member

🕵 The feature_docs.py failure ("No documentation changes found") is a bug in the CI hook, not a missing-docs problem: this PR documents the new setting in the DECLARE docstring in src/Storages/MergeTree/MergeTreeSettings.cpp, which is the correct (and only allowed) source — the docs/reference/settings/** pages are autogenerated from it. The hook's glob src/**/*Settings.cpp is matched with PurePosixPath.match, which treats ** as a single path component, so the doubly-nested MergeTreeSettings.cpp was not recognized. Fix: #113387 — once it merges, updating this branch from master will clear the check.

Also addressed the AI-review note by narrowing the setting's documented contract to MUTATE_PART entries (patch parts from lightweight updates are still applied during merges; always_fetch_merged_part covers those), and merged latest master.

…a part

Addressed the AI-review finding: with `always_fetch_mutated_part` enabled,
`MutateFromLogEntryTask::prepare` returns a non-throwing fetch result while no
replica has produced the mutated part yet. Because no exception is thrown,
`ReplicatedMergeTreeQueue` does not arm its exponential backoff (it is armed by
`updateLastExeption`), and `ReplicatedMergeMutateTaskBase::onCompleted` used to
pass `state != SUCCESS` down the immediate `trigger` path, so the same
`MUTATE_PART` entry could be re-scheduled in a tight loop (with the
corresponding Keeper requests from `executeFetch`) while another replica was
still mutating the part.

Add an explicit `postpone_next_attempt` flag to `PrepareResult`; when it is set,
`onCompleted` asks the background assignee to `postpone` the next attempt
instead of triggering it right away.
…serve remote failures

With `always_fetch_mutated_part` enabled, the replica does not execute
`MUTATE_PART` entries, and per-replica mutation failure status
(`latest_fail_reason`) is not replicated, so a `mutations_sync` wait
issued on such a replica cannot observe mutation failures happening on
the executing replicas. Document this in the setting docstring and log a
warning in `waitMutationToFinishOnReplicas`, which relies on local
execution for error detection.

Addresses the AI review finding in
ClickHouse#113020
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 CI triage for commit 69ed4c3 — all three failures are unrelated to this PR:

Also pushed 696a456 addressing the AI review finding: the setting docstring now documents that mutations_sync on a fetch-only replica cannot observe executor-side mutation failures, and waitMutationToFinishOnReplicas logs a warning in that configuration (see the reply on the review thread for why a full fix — replicating per-replica mutation failure status — is out of scope for this setting).

alexey-milovidov and others added 2 commits August 7, 2026 02:15
A replica with the `always_fetch_mutated_part` setting enabled does not
execute mutations, and per-replica mutation failure status is not
replicated, so `waitMutationToFinishOnReplicas` cannot observe mutation
failures that happen on the replicas executing the mutation and would
wait until the query is cancelled or the mutation is killed.

Fail closed instead of hanging, per the review feedback in
ClickHouse#113020: `mutations_sync > 0`
is now rejected in `StorageReplicatedMergeTree::mutate` before the
mutation entry is created, and `waitMutationToFinishOnReplicas` throws
`SUPPORT_IS_DISABLED` (covering `alter_sync > 0` for `ALTER` queries
that mutate data) instead of logging a warning. Add a regression test
that synchronous mutations and synchronous data-mutating `ALTER`s are
rejected on the fetch-only replica while asynchronous application and
synchronous mutations issued on an executing replica keep working.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 9, 2026
Merged via the queue into ClickHouse:master with commit ccd0884 Aug 9, 2026
180 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 9, 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 pr-feature Pull request with new product feature 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