Skip to content

Verify settings possible range at the right place - #113787

Merged
PedroTadim merged 10 commits into
masterfrom
fix-setting
Sep 1, 2026
Merged

PedroTadim merged 10 commits into
masterfrom
fix-setting

Conversation

@PedroTadim

@PedroTadim PedroTadim commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

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

Fix setting temporary_files_buffer_size or format_avro_schema_registry_* to an out-of-range value making every subsequent query in the session fail, with no way to recover; the values are now bounded when they are set.

Closes: #113782


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

@mintlify

mintlify Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Aug 7, 2026, 11:00 AM

@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5438acb]

Summary: ❌

job_name test_name status info comment
Stress test (arm_release) FAIL
Cannot start clickhouse-server FAIL cidb IGNORED
Check failed FAIL cidb IGNORED
Stress test (arm_debug) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED

AI Review

Summary

This PR moves the upper-bound checks for temporary_files_buffer_size and the Avro Schema Registry settings out of hot runtime paths so a bad session SET no longer poisons every later query, and it adds the missing client/query-plan clamps for the remaining consumption sites. The remaining blocker is that four existing Avro settings were changed to NonZeroUInt64, which turns previously persisted 0 values in users.xml or settings profiles into load-time failures before any clamp can run.

Findings

❌ Blockers

[src/Core/FormatFactorySettings.h:869-881] [dismissed by author -- https://github.com//pull/113787#discussion_r3735648404] Changing these existing settings to NonZeroUInt64 breaks backward compatibility for persisted configs and profiles that already contain 0. SettingsImpl::setProfile and SettingsImpl::loadSettingsFromConfig still pass config strings straight into set (src/Core/Settings.cpp:9361-9393), and SettingFieldNonZeroUInt64::parseFromString throws on 0 before doSettingsSanityCheckClamp ever sees the value (src/Core/SettingsFields.cpp:642-650). A historical format_avro_schema_registry_*timeout = 0 or format_avro_schema_registry_retry_initial_backoff_ms = 0 now fails during startup/profile load instead of only on the specific AvroConfluent query that uses it. I still consider this real because the current head keeps the NonZeroUInt64 type change in src/Core/FormatFactorySettings.h and none of the profile/config loading paths were changed.

Suggested fix: keep the stored setting type backward-compatible (UInt64) and reject or rewrite 0 only in the interactive query-setting path that this PR is trying to harden, not in the generic config/profile parser.

Tests

⚠️ Add a focused regression test for loading a settings profile or users.xml entry with one of these Avro settings set to 0; the current stateless test only proves the interactive SET path.

Final Verdict

Needs changes before merge: the session-bricking fix is good, but the current NonZeroUInt64 type change introduces a startup/profile-load regression for existing persisted configurations.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.30% 87.30% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 89/95 (93.68%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 7, 2026
@PedroTadim

Copy link
Copy Markdown
Member Author

@antaljanosbenjamin maybe you can review this? It should be easy

Comment thread src/Core/FormatFactorySettings.h Resolved
Comment thread src/Formats/FormatFactory.cpp Resolved
Comment thread src/Core/FormatFactorySettings.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5438acb6f with master 81fdf3cc0 (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
Binary Master PR Δ
programs/clickhouse-stripped 712.33 MiB 709.29 MiB -3.04 MiB (-0.43%)

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.

Object file sizes

20 object files changed (+24.77 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Core/SettingsQuirks.cpp.o 166.35 KiB 202.82 KiB +36.47 KiB (+21.92%)

737 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

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

Job report

Comment thread src/Formats/FormatFactory.cpp Resolved
Comment on lines +117 to +125
/// `doSettingsSanityCheckClamp` bounds these at apply time, but it does not run for
/// `ApplicationType::CLIENT`, which builds format settings of its own for every statement and
/// reaches the registry when it parses `INSERT ... FROM INFILE`. Clamp here to cover it too.
format_settings.avro.schema_registry_timeouts.connection_timeout
= std::min<UInt64>(settings[Setting::format_avro_schema_registry_connection_timeout], MAX_SCHEMA_REGISTRY_TIMEOUT_SECONDS);
format_settings.avro.schema_registry_timeouts.send_timeout
= std::min<UInt64>(settings[Setting::format_avro_schema_registry_send_timeout], MAX_SCHEMA_REGISTRY_TIMEOUT_SECONDS);
format_settings.avro.schema_registry_timeouts.receive_timeout
= std::min<UInt64>(settings[Setting::format_avro_schema_registry_receive_timeout], MAX_SCHEMA_REGISTRY_TIMEOUT_SECONDS);

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.

I don't like the special handling of these settings, but I don't see a better way to fix this.

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.

Then what should we do?

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 apply-time clamp looks like the right place for the upper bound, because the failure only becomes user-visible after these values have been stored in session state and later reused by unrelated statements.

What I would still avoid is changing the existing settings to NonZeroUInt64: Context::setCurrentProfilesWithLock applies profile / users.xml values before any clamp runs, so a historical 0 now turns into a profile-load failure. Keeping the stored type compatible and enforcing the bounds at the same application boundary would preserve the fix without breaking persisted configs.

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.

I asked Pavel, who is the most experienced in formats to take a look at it. We can merge it as is if he also cannot find a better way to handle it.

Comment thread src/Core/FormatFactorySettings.h Resolved
Comment thread src/Core/Settings.cpp Resolved
@PedroTadim PedroTadim added the pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard label Aug 11, 2026
@PedroTadim

Copy link
Copy Markdown
Member Author

@antaljanosbenjamin all the CI failures seem unrelated, so you can continue the review

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

Some minor things to change @groeneai:

  • [src/Client/BuzzHouse/Generator/SessionSettings.cpp:2247] The BuzzHouse generator still picks 0 from the choices for format_avro_schema_registry_retry_initial_backoff_ms. With the type now NonZeroUInt64, that value is guaranteed to fail at SET time, producing pure noise in fuzz runs. The file already has a nonzero_bytes_values list for exactly this reason (line 1930). Suggested fix: drop 0 from {0, 1, 10, 100, 1000}.
  • [PR description] Changelog entry quality: setting names and SET should be wrapped in inline code blocks per the changelog guidelines. Suggested replacement: "Fix SET temporary_files_buffer_size or format_avro_schema_registry_* to an out-of-range value making every subsequent query in the session fail, with no way to recover; the values are now bounded when they are set."

Some notes that worth to mention but I agree with AI that it doesn't need to be addressed:

  • The UInt64 → NonZeroUInt64 type change means a server config profile containing format_avro_schema_registry_*_timeout = 0 or ..._retry_initial_backoff_ms = 0 now fails at profile load (server startup) instead of at query time. I consider this acceptable: such a configuration previously made every format-touching query fail, the settings are recent (26.5/26.6), failing fast is the fail-close behavior, and the same semantics already apply to established NonZeroUInt64 settings like max_block_size and max_read_buffer_size. No compatibility gate needed, but worth being aware of.
  • The upper bounds changed from reject to silent clamp. This is a deliberate part of the fix (a rejection at read time is exactly what bricked sessions), it follows the established MAX_SANE_READ_BUFFER_SIZE clamp pattern, logs a warning, and the new behavior is documented in every setting description and doc page. No versioning concern: settings travel as name=value strings.

@antaljanosbenjamin

Copy link
Copy Markdown
Member

@groeneai please also change the changelog category to backward incompatible change

@PedroTadim

Copy link
Copy Markdown
Member Author

@groeneai please also change the changelog category to backward incompatible change

The PR is from me? 😄

@PedroTadim

Copy link
Copy Markdown
Member Author

The BuzzHouse setting should already be fixed on master. Running CI one more time

@antaljanosbenjamin

Copy link
Copy Markdown
Member

The PR is from me? 😄

Wupsy, sorry Pedro, I was reviewing quite some groene AI PRs and probably got confused. Sorry. I was surprised it is quite good PR compared to a groene ai PR, but this explains why 😄

@PedroTadim

Copy link
Copy Markdown
Member Author

@antaljanosbenjamin both CI failures are unrelated and address the review comments. You give the final word

Comment thread src/Core/SettingsQuirks.h
/// is clamped to it by `doSettingsSanityCheckClamp`.
inline constexpr UInt64 MAX_TEMPORARY_FILES_BUFFER_SIZE = 1_GiB;

/// Bounds for the Confluent Schema Registry client. `doSettingsSanityCheckClamp` applies them to

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 very central setting header is definitely not the right place for schema registry defines.

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.

Open a PR to change this?

@rschu1ze rschu1ze Sep 8, 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.

@groeneai Open a PR which moves constants MAX_SCHEMA_REGISTRY_TIMEOUT_SECONDS, MAX_SCHEMA_REGISTRY_RETRIES, and MAX_SCHEMA_REGISTRY_INITIAL_BACKOFF_MS to src/Core/Defines.h. Make no mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Acknowledged. I will open a PR moving the three constants to src/Core/Defines.h and link it here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Opened #118953: a pure move of the three constants, comment included, with the values and the explicit UInt64 type unchanged. The one adapted token is inline constexpr -> static constexpr, matching the rest of Defines.h; happy to switch it back.

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.

Thanks Robert, good find!

pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Sep 9, 2026
`MAX_SCHEMA_REGISTRY_TIMEOUT_SECONDS`, `MAX_SCHEMA_REGISTRY_RETRIES` and
`MAX_SCHEMA_REGISTRY_INITIAL_BACKOFF_MS` were added to `src/Core/SettingsQuirks.h`
by ClickHouse#113787. As @ rschu1ze pointed out while reviewing that PR, "this very central
setting header is definitely not the right place for schema registry defines", and
he asked for them to be moved to `src/Core/Defines.h`, which is where this project
keeps its named magnitude constants.

Requested in
ClickHouse#113787 (comment)

The three definitions move together with the comment block that explains why the
same bounds are applied at two sites. Values (599, 20, 60000), the explicit
`UInt64` type and the enclosing `namespace DB` are unchanged, so both consumers
see exactly what they saw before.

The storage-class specifier is the one adapted token: `inline constexpr` becomes
`static constexpr`, matching the destination file, which uses `static constexpr`
for all 103 of its existing constants and has never contained an `inline constexpr`
one. It is semantically inert here because nothing takes the address of these
constants; both consumers read them by value. The explicit `UInt64` is deliberately
kept rather than switching to the `auto` most of `Defines.h` uses, because `auto` on
`599` would deduce `int` and change the type at the `std::min<UInt64>` and
`CHECK_SETTING_MAX_VALUE` sites.

`SettingsQuirks.cpp` needs no change; it already includes `<Core/Defines.h>`.
`FormatFactory.cpp` had been reaching the constants through its
`<Core/SettingsQuirks.h>` include and uses nothing else from that header, so the
include is replaced by `<Core/Defines.h>`.

Co-Authored-By: Claude Opus 5 <[email protected]>

This branch was successfully deployed

1 active deployment
staging - docs — 5438acb6 Deployed Aug 27, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard 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.

SET format_avro_schema_registry_retry_initial_backoff_ms = 0 permanently bricks the session

5 participants