Skip to content

Introduce Settings Compatibility Blocker - #114190

Merged
Michicosun merged 15 commits into
masterfrom
compatibility_blocker
Sep 14, 2026
Merged

Michicosun merged 15 commits into
masterfrom
compatibility_blocker

Conversation

@Michicosun

@Michicosun Michicosun commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Normally, the compatibility setting reverts to the default value from the settings changes history back to its previous value. This patch adds a per-change compatibility_mode field to the history: entries marked StartUsingNew are excluded from this rollback, so the new default takes effect as soon as the server runs the version that introduced it, even if compatibility points to an older version.


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

Version info

  • Merged into: 26.9.1.1497 (included in 26.9 and later)

@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6f117d2]

Summary: ✅


AI Review

Summary

This PR adds per-change compatibility_mode metadata to the settings history and exposes it through system.settings_changes, so selected defaults can ignore rollback under compatibility. The per-entry Ignore bookkeeping itself is straightforward, but I would not merge this yet: MergeTree settings derived from compatibility are still cached in ContextSharedPart, so the first access pins them for later callers with different compatibility values, and the current test/docs updates still do not prove or describe the new user-visible behavior end to end.

PR Metadata

Changelog category is not correct. This PR changes user-visible compatibility behavior and adds a fifth element to system.settings_changes.changes, so it is not Not for changelog.

Suggested replacement:

  • Backward Incompatible Change

A Changelog entry is required for that category. Suggested replacement text:
compatibility no longer rolls back shared_merge_tree_merge_coordinator_distribution_algorithm to water_filling: on servers with this change, the default remains sainte_lague even when compatibility points to an older version. system.settings_changes now exposes a compatibility_mode field for each history entry; set shared_merge_tree_merge_coordinator_distribution_algorithm = 'water_filling' explicitly if you need the previous behavior.

Missing context / blind spots
  • ⚠️ I did not run a live repro: this workspace has no build directory or clickhouse binary, and the PR's linked CI currently exposes only Build profile diff. The cache issue below is based on tracing the current Context and MergeTree call chain in the checked-out code.
Findings

❌ Blockers

  • [src/Interpreters/Context.cpp:1412-1428, 3517-3550, 7517-7555; src/Storages/System/StorageSystemMergeTreeSettings.cpp:53; src/Functions/getMergeTreeSetting.cpp:84; src/Storages/MergeTree/registerStorageMergeTree.cpp:731] Query/session contexts copy settings but share ContextSharedPart, and getMergeTreeSettings / getReplicatedMergeTreeSettings cache a compatibility-derived MergeTreeSettings object in that shared state without invalidating it on later SET compatibility or SET profile changes. So the first caller that warms the cache decides the MergeTree defaults seen by later callers with a different compatibility value. A warm default query can suppress the rollback that a later SETTINGS compatibility = '26.7' query expects, and the reverse order leaks rolled-back defaults into later system.merge_tree_settings, getMergeTreeSetting, and CREATE TABLE ... MergeTree calls. The new Ignore blocker is built on top of the same cache, so the rollout-control contract this PR extends is still bypassable.
    Suggested fix: key the cached MergeTree settings by the effective compatibility / profile state, or stop storing compatibility-resolved MergeTree settings in ContextSharedPart so each copied context recomputes its own view.

⚠️ Majors

  • [tests/queries/0_stateless/02326_settings_changes_system_table.sql:1-2; tests/queries/0_stateless/02326_settings_changes_system_table.reference:3-4] The only touched coverage checks DESC system.settings_changes and one Session history row, so the new Ignore path is still unproven. There is still no focused regression that exercises a blocked MergeTree setting under SETTINGS compatibility = '26.7', and no test that warms system.merge_tree_settings before the compatibility query to catch the shared-cache bug above. That leaves the main contract of this PR open to silent regressions.
    Suggested fix: add a stateless test that queries both a rollbackable MergeTree setting such as compute_exact_num_defaults_for_sparse_columns and the blocked shared_merge_tree_merge_coordinator_distribution_algorithm, with and without a warm-cache access before the compatibility query.

  • [docs/reference/system-tables/settings_changes.mdx:19-36] The checked-in English page still documents changes as a four-element tuple and shows a stale example with type: Core. Because the example lives outside the autogenerated block, the source-level updates in StorageSystemSettingsChanges.cpp do not fix it automatically. Merging as-is leaves the published system.settings_changes docs contradicting the new compatibility_mode field.
    Suggested fix: refresh or remove the manual example in this page, and run the docs autogeneration flow so the checked-in English page matches the updated source registration.

Final Verdict

Changes requested. The per-entry compatibility_mode idea is reasonable, but the shared MergeTree settings cache still breaks the promised compatibility behavior, and the docs/tests remain incomplete.

LLVM Coverage Report

Measured on commit 6f117d2.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.80% 91.70% -0.10%
Branches 81.40% 81.30% -0.10%

Changed lines: Changed C/C++ lines covered: 60/62 (96.77%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 10, 2026
@azat azat self-assigned this Aug 10, 2026
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
Comment thread src/Core/Settings.cpp Outdated

ClickHouseVersion version(compatibility_value);
const auto & settings_changes_history = getSettingsChangesHistory();
UnorderedSetWithMemoryTracking<std::string_view> blocked_settings;

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.

Maybe worth to put a comment why we need set

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.

Not sure if it is needed in the code; the logic is simple: iteration goes back through versions across all settings, not within a single one.

/// In case the alias is being used (e.g. use enable_analyzer) we must change the original setting
auto final_name = MergeTreeSettingsTraits::resolveName(change.name);

if (change.compatibility_mode == SettingsChangesHistory::SettingChange::CompatibilityMode::StartUsingNew)

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.

applyCompatibilitySetting only helps if the MergeTreeSettings cache is rebuilt, but Context keeps merge_tree_settings / replicated_merge_tree_settings in ContextSharedPart and Context::setSettingWithLock never invalidates those caches when compatibility changes. A concrete repro already exists in the current tree: first query system.merge_tree_settings to warm the cache, then run SELECT value FROM system.merge_tree_settings WHERE name = 'compute_exact_num_defaults_for_sparse_columns' SETTINGS compatibility = '26.7'. StorageSystemMergeTreeSettings::fillData still reads the cached object, so the second query keeps returning 1 instead of the expected compatibility value 0. This new blocker has the same issue, so session/query-level rollout control is bypassable after the first MergeTree settings access. Please key these caches by the effective compatibility value, or invalidate them whenever compatibility / the active profile changes.

@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6f117d21f with master b8798d61a (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

6 object files changed (+37.87 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Core/SettingsChangesHistory.cpp.o 1023.02 KiB 1.03 MiB +27.80 KiB (+2.72%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@rschu1ze

rschu1ze commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

@Michicosun

This patch adds the ability to stop compatibility rollback on a specific version. This way, we can control the rollout of settings across the fleet without configuration changes.

That's not specific enough, kindly add more details, an example etc., thanks.

@Michicosun
Michicosun enabled auto-merge August 11, 2026 14:46

@rschu1ze rschu1ze left a comment •

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.

@Michicosun I see that you extended the changelog message by one sentence (thanks). Sorry for asking again, but it's still not clear what this PR is doing. The enum values in the code have no comments and the extra system table field lacks documentation in https://clickhouse.com/docs/reference/system-tables/settings_changes.

  • How is the compatibility blocker supposed to be used?
  • In which situations should it be used?
  • Should we document or mention in the docs of "compatibility blocked" settings (e.g. shared_merge_tree_merge_coordinator_distribution_algorithm) that the compatibility setting has no effect for them?

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@Michicosun Michicosun closed this Aug 14, 2026
auto-merge was automatically disabled August 14, 2026 11:59

Pull request was closed

@Michicosun Michicosun reopened this Aug 14, 2026
@Michicosun
Michicosun requested a review from rschu1ze August 14, 2026 12:15
@rschu1ze

Copy link
Copy Markdown
Member

The problems mentioned in #114190 (review) are still there.

changes Array(Tuple(\n name String,\n previous_value String,\n new_value String,\n reason String)) The list of changes in settings which changed the behaviour of ClickHouse.
Session 22.5 [('memory_overcommit_ratio_denominator','0','1073741824','Enable memory overcommit feature by default'),('memory_overcommit_ratio_denominator_for_user','0','1073741824','Enable memory overcommit feature by default')]
changes Array(Tuple(\n name String,\n previous_value String,\n new_value String,\n reason String,\n compatibility_mode String)) The list of changes in settings which changed the behaviour of ClickHouse.
Session 22.5 [('memory_overcommit_ratio_denominator','0','1073741824','Enable memory overcommit feature by default','RollbackToOld'),('memory_overcommit_ratio_denominator_for_user','0','1073741824','Enable memory overcommit feature by default','RollbackToOld')]

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 is the only coverage added for the new CompatibilityMode::StartUsingNew path, but it never exercises that path: the sample row here is a Session history entry that still stays RollbackToOld. We still have no focused regression proving that SETTINGS compatibility = '26.7' leaves shared_merge_tree_merge_coordinator_distribution_algorithm at sainte_lague, or that the warm-cache system.merge_tree_settings path keeps honoring that behavior after the first MergeTree settings access. Please add a stateless test for the blocked MergeTree setting itself.

@clickhouse-gh clickhouse-gh Bot added the comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). label Sep 4, 2026
Preserve `StartUsingNew` in the resolved compatibility history and reconcile settings history entries.

#114190 (review)
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
std::make_shared<DataTypeString>(),
std::make_shared<DataTypeString>()},
Names{"name", "previous_value", "new_value", "reason"})), "The list of changes in settings which changed the behaviour of ClickHouse."},
Names{"name", "previous_value", "new_value", "reason", "compatibility_mode"})), "Setting changes. `compatibility_mode`: `RollbackToOld` permits rollback to `previous_value`; `StartUsingNew` blocks rollback of this and earlier changes to the same setting."},

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.

The source-level docs are updated here, but the checked-in English page still has a hand-written example in docs/reference/system-tables/settings_changes.mdx that shows the old four-element tuples (and even the old type values). Because that example sits outside the autogenerated block, merging this still leaves the public docs page contradicting the new compatibility_mode field. Please refresh or remove that manual output snippet as part of this change.

@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 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.

@clickhouse-gh clickhouse-gh Bot assigned rschu1ze and unassigned azat Sep 11, 2026
Michicosun and others added 2 commits September 12, 2026 19:27
Rename the modes to `Apply` and `Ignore`, update descriptions and reference output, and remove the scheduling example.

#114190 (comment)
#114190 (comment)
@Michicosun
Michicosun added this pull request to the merge queue Sep 14, 2026
Merged via the queue into master with commit 4be746a Sep 14, 2026
347 of 348 checks passed
@Michicosun
Michicosun deleted the compatibility_blocker branch September 14, 2026 22:08
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 14, 2026
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Oct 7, 2026
SET x = DEFAULT restored the compiled default of x and ignored an active
compatibility setting, so the session reported the current version's default
while compatibility still claimed the old era - a state no new session with
the same compatibility could reach. That contradicts the documented contract
of compatibility ("only settings that have not been modified are affected"),
since after a reset the setting is by definition not modified.

SET x = DEFAULT is not a SettingChange: the parser puts the bare name into
ASTSetQuery::default_settings, and the reset reaches
BaseSettings::resetToDefault, which is not virtual. The whole chain therefore
bypasses SettingsImpl::set, the only compatibility-aware mutator and the sole
override of the single virtual in BaseSettings, so the derivation never re-runs.

SettingsImpl::resetToDefaultRespectingCompatibility resets and then calls the
existing applyCompatibilitySetting. Reading compatibility after the reset is
what makes SET compatibility = DEFAULT revert every setting it derived, with
no special case, because the value read is then the empty default. Calling the
existing walk rather than duplicating it filtered to one name keeps the reset
path from diverging from the fresh-session path, which matters because ClickHouse#114190
is editing that walk.

Only the four surfaces that implement SET <name> = DEFAULT are repointed;
every internal caller that wants the declared default keeps the raw reset.
Settings::setDefaultValue itself is deliberately not repointed: Connection.cpp
resets a setting purely to mark it unchanged so it is not resent and asserts
exactly that on the next line, and re-deriving assigns a value and so sets
changed, which was measured to fire that assert on an ordinary query whenever
the user profile activates compatibility. AsynchronousInsertQueue resets
async_insert to let the remote part decide, and async_insert has a live history
row, so re-deriving would take that decision away under compatibility <= 26.1.
MySQLHandler rewrites = DEFAULT to SQL text and re-enters the first surface, so
it is fixed with no edit.

SettingsConstraints::checkResetToDefault had to move with it. It was
centralized in ClickHouse#115334 on the premise that the defaults do not depend on the
session, which this change makes false: with a profile that both pins and
constrains a setting, the pin keeps it changed, compatibility leaves it alone,
and a reset would install the era value the constraint forbids. Measured on a
build carrying the reset change without this half, such a reset was accepted
silently and landed below the profile's declared minimum. The check now
replays the statement on a throwaway copy of the context the resets will
mutate and validates the values it lands on; enforcement stays on the checking
context, matching the ordinary-change check one line earlier, and the whole
statement is still left without effect on a violation.

Behaviour changes: a reset under an active compatibility now yields the era
value; SET compatibility = DEFAULT now reverts what it derived; and a reset
can now be rejected by a settings constraint where it previously succeeded.

Not addressed, pre-existing and wider: applyCompatibilitySetting writes through
BaseSettings::set, so SET compatibility = '<version>' installs era values for
every unchanged setting with no constraint check at all.

Closes: ClickHouse#116883
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Oct 10, 2026
…compatibility

The four settings added by the 24.10 BACKUP ON CLUSTER coordination rewrite
(backup_restore_failure_after_host_disconnected_for_seconds,
backup_restore_keeper_max_retries_while_initializing,
backup_restore_keeper_max_retries_while_handling_error,
backup_restore_finish_timeout_after_error_sec) carry "New setting" history
records with a previous value of 0, so compatibility <= 24.10 sets them to 0.
In the current code 0 means no Keeper retries while initializing or handling
an error, no lost-host detection and an untimed wait after an error.

A host that fails its first Keeper step and then fails to write its error
never reports anything, so the initiator's
waitOtherHostsFinish(throw_if_error = false) in BackupStarter::onException
waits forever: KILL QUERY does not stop it and shutdown_wait_backups_and_restores
blocks server shutdown. No release behaved like this: 24.9 retried those
steps with backup_restore_keeper_max_retries (20) and did not wait for other
hosts after an error. Stress tests hit it through compatibility randomization
plus backup Keeper fault injection (ClickHouse#116783).

Add a 26.10 CompatibilitySetting::Ignore record (ClickHouse#114190) to each of the four
settings, so any compatibility value keeps their defaults. The 24.10/24.11
records are unchanged, backup_restore_keeper_max_retries still rolls back to
24.9's 20, and an explicit SET still wins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). pr-not-for-changelog This PR should not be mentioned in the changelog 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.

5 participants