Skip to content

Fix SettingsConstraints erasing explicit settings when compatibility is present - #99402

Merged
rienath merged 17 commits into
masterfrom
fix-setting-constraints-fix
Apr 13, 2026
Merged

rienath merged 17 commits into
masterfrom
fix-setting-constraints-fix

Conversation

@rienath

@rienath rienath commented Mar 13, 2026 •

Copy link
Copy Markdown
Member

This re-lands #97078 (reverted in #99352) with a fix for the forwarded-settings path that caused stress test failures.

The original fix prevented SettingsConstraints::check from erasing explicit settings when compatibility is present in the same batch, but only on the initial settings path. With parallel replicas, the coordinator forwards settings to replicas through SettingsConstraints::clamp, which still had the old behavior. With old compatibility applied, coordinator could keep enable_analyzer=1 but replicas let compatibility override it to 0, producing NOT_FOUND_COLUMN_IN_BLOCK due to different internal column naming with and without analyzer (example)

This PR extracts a shared logic to checkOrClamp so paths can't diverge again. A regression test for the exact scenario is included.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix a bug where explicit settings sent alongside compatibility in the same request could be silently ignored when their value matched the server default.

Version info

  • Merged into: 26.4.1.885

@clickhouse-gh

clickhouse-gh Bot commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a331351]

Summary: ✅


AI Review

Summary

This PR re-lands the SettingsConstraints + compatibility fix by unifying check and clamp through checkOrClamp, so explicit settings are not lost when compatibility is present in the same batch (including forwarded settings on parallel replicas). It also adds targeted stateless regressions for compatibility + explicit overrides, readonly/CONST interactions, and the parallel-replica path. I did not find new blocker or major issues in the current PR head diff.

Missing context
  • ⚠️ No CI report/log links were provided in this review task, so I could not validate runtime outcomes beyond code-level analysis and test intent.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 13, 2026
@rienath
rienath force-pushed the fix-setting-constraints-fix branch from d003821 to be9d9f2 Compare March 13, 2026 15:01
The previous fix for SettingsConstraints erasing explicit settings before compatibility applies was only in the check path (initial settings), not in clamp (forwarded settings). With parallel replicas, the coordinator kept explicit settings but replicas dropped them via the forwarded path, causing NOT_FOUND_COLUMN_IN_BLOCK due to analyzer being silently disabled by compatibility. I extracted a shared checkOrClamp helper used by both paths so they can't diverge again
Comment thread src/Access/SettingsConstraints.cpp Resolved
rienath added 2 commits March 26, 2026 13:34
…rClamp

Previous change kept all settings when compativility was present. This one makes it surgical. We keep only unchanged settings, while genuinely rejected ones are still erased
@rienath
rienath marked this pull request as ready for review March 27, 2026 12:55
@vitlibar vitlibar self-assigned this Mar 30, 2026
Comment thread src/Access/SettingsConstraints.cpp Outdated

template <typename SettingsT>
bool getNewValueToCheck(const SettingsT & current_settings, SettingChange & change, Field & new_value, bool throw_on_failure)
bool getNewValueToCheck(const SettingsT & current_settings, SettingChange & change, Field & new_value, bool throw_on_failure, bool * value_unchanged = nullptr)

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 function with this extra bool * parameter looks overcomplicated. I suggest simplifying it by turning into

Field getNewValueToCheck(const SettingsT & current_settings, const SettingChange & change, bool ignore_if_unchanged, bool throw_on_failure)

I mean such function could return Field{} instead of false and also check whether it's changed only if ignore_if_unchanged==true

@vitlibar vitlibar Mar 31, 2026 •

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.

Please also add a comment for getNewValueToCheck, it looks like it's worth commenting.

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.

Great suggestion, this simplifies the logic a lot!

Comment thread src/Access/SettingsConstraints.h Outdated
SettingChange & change,
ReactionOnViolation reaction,
SettingSource source,
bool keep_if_unchanged = false) const;

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.

Let's rename the parameter to ignore_unchanged_settings? Because otherwise it looks confusing that function checking settings has a parameter named keep...

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.

Thanks, changed

Comment thread src/Access/SettingsConstraints.cpp Outdated
else if (!access_control->isSettingNameAllowed(setting_name))
return false;

/// `getNewValueToCheck` returns false either because the value is unchanged (no-op) or because the cast failed.

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 comment looks unnecessary

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.

Especially with the new logic. Removed

Comment thread src/Access/SettingsConstraints.cpp Outdated
///
/// Thus, when `compatibility` is present, we keep unchanged settings so they get marked as explicitly `changed` and take precedence.
/// Genuinely rejected settings (unknown names, cast failures, constraint violations) are still erased.
bool has_compatibility = changes.tryGet("compatibility") != nullptr;

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.

Please rename to has_compatibility_setting. Also the comment is too long and quite unclear at the same time.

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.

Done. Let me know if it is still unclear

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

I was going to send these messages once I saw that CI doesn't fail, but you already approved the PR. Thanks for the detailed review :)

Comment thread src/Access/SettingsConstraints.h Outdated
SettingChange & change,
ReactionOnViolation reaction,
SettingSource source,
bool keep_if_unchanged = false) const;

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.

Thanks, changed

Comment thread src/Access/SettingsConstraints.cpp Outdated
///
/// Thus, when `compatibility` is present, we keep unchanged settings so they get marked as explicitly `changed` and take precedence.
/// Genuinely rejected settings (unknown names, cast failures, constraint violations) are still erased.
bool has_compatibility = changes.tryGet("compatibility") != nullptr;

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.

Done. Let me know if it is still unclear

Comment thread src/Access/SettingsConstraints.cpp Outdated

template <typename SettingsT>
bool getNewValueToCheck(const SettingsT & current_settings, SettingChange & change, Field & new_value, bool throw_on_failure)
bool getNewValueToCheck(const SettingsT & current_settings, SettingChange & change, Field & new_value, bool throw_on_failure, bool * value_unchanged = nullptr)

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.

Great suggestion, this simplifies the logic a lot!

Comment thread src/Access/SettingsConstraints.cpp Outdated
else if (!access_control->isSettingNameAllowed(setting_name))
return false;

/// `getNewValueToCheck` returns false either because the value is unchanged (no-op) or because the cast failed.

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.

Especially with the new logic. Removed

Comment thread src/Access/SettingsConstraints.cpp Resolved
… in tests

The '<readonly/>' constraint on 'æenable_analyzer' throws when the test framework sends '--enable_analyzer=1 --compatibility=25.1', because this stops filtering unchanged settings when 'compatibility' is present. Replace with '<min>1</min>' which still prevents the fuzzer from disabling the analyzer but does not reject a no-op set to 1.
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@rienath

This comment was marked as outdated.

 When 'compatibility' is in the batch, unchanged settings are kept so they take precedence over 'compatibility' defaults. But they were still going through constraint checks, which could reject them (e.g. 'readonly=2' in readonly mode). Since the value isn't actually changing, skip the check.
@alexey-milovidov

Copy link
Copy Markdown
Member

The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158

@alexey-milovidov

Copy link
Copy Markdown
Member

The flaky check failure is fixed in #102148, let's update the branch.

@clickhouse-gh

clickhouse-gh Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 96.30% (52/54) | lost baseline coverage: 11 line(s) · Uncovered code

Full report · Diff report

@rienath
rienath added this pull request to the merge queue Apr 13, 2026
Merged via the queue into master with commit c0acc65 Apr 13, 2026
164 checks passed
@rienath
rienath deleted the fix-setting-constraints-fix branch April 13, 2026 14:29
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 13, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this PR may need backporting to 26.3 (LTS), 26.2, 26.1, 25.8 (LTS), but no backport label was found.

Affected code: SettingsConstraints::check, SettingsConstraints::clamp, SettingsConstraints::checkOrClamp — core code present in all supported branches.

Why: SettingsConstraints::check/clamp and the compatibility setting both predate all supported branches (SettingsConstraints: 2019, compatibility: 2022-07). The bug affects any user combining explicit settings with compatibility in TCP or HTTP paths. The original fix #97078 was reverted (#99352) due to stress test failures; this PR re-lands it with the clamp path fixed. All supported branches are affected.

If this should be backported, consider adding pr-must-backport or a version-specific label (e.g. v26.3-must-backport). Ignore this if backporting is not applicable.

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

Labels

pr-bugfix Pull request with bugfix, not backported by default 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