Skip to content

Make to_throw settings cheangeable without restart - #106821

Merged
alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
UberDever:uberdever/feature/changeable-to-throw-settings
Jul 2, 2026
Merged

alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
UberDever:uberdever/feature/changeable-to-throw-settings

Conversation

@UberDever

@UberDever UberDever commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

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

Made max_named_collection_num_to_throw, max_table_num_to_throw, max_replicated_table_num_to_throw, max_view_num_to_throw, max_dictionary_num_to_throw, and max_database_num_to_throw changeable without a server restart.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [532cac8]

Summary: ✅


AI Review

Summary

This PR makes the max_*_num_to_throw entity limits live-reloadable by moving enforcement to Context's live mirrors, updating those mirrors from the server config-reload callback, and seeding them during setApplicationType so clickhouse-local does not silently fall back to startup defaults. I reviewed the current diff and all prior discussion, and the current head addresses the previously raised gaps around live-value reporting and clickhouse-local coverage. I did not find a remaining correctness, compatibility, or evidence problem in the touched code.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 9, 2026
Comment thread src/Core/ServerSettings.cpp Resolved
@UberDever
UberDever force-pushed the uberdever/feature/changeable-to-throw-settings branch from 57d2be5 to d088f3d Compare June 11, 2026 10:11
Comment thread src/Core/ServerSettings.cpp Resolved
Comment thread src/Interpreters/Context.cpp Resolved
Comment thread src/Interpreters/Context.cpp Outdated
void Context::setMaxNamedCollectionNumToThrow(size_t max_named_collection_to_throw)
{
std::lock_guard lock(shared->mutex);
shared->max_named_collection_num_to_throw = max_named_collection_to_throw;

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.

But no... let's aim for better. Can we refactor this code to remove repetitions for settings that don't require any additional actions on change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think X-macro approach is the best here, since we have single source of truth for settings and many places where they are instantiated. I've added x-macro and instantiations for getters/setters/variable declarations and couple other places

node2.query("DROP NAMED COLLECTION IF EXISTS nc_reload_test")


def test_runtime_config_reload_of_limits(started_cluster):

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.

A test that is almost tautological - not good. Let's be more creative with our tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Doing more intelligent test now, changing limits down and back

@alexey-milovidov alexey-milovidov 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.

.

@alexey-milovidov alexey-milovidov self-assigned this Jun 15, 2026
@UberDever
UberDever force-pushed the uberdever/feature/changeable-to-throw-settings branch from 1d12974 to 15d056b Compare June 16, 2026 09:31
@UberDever
UberDever force-pushed the uberdever/feature/changeable-to-throw-settings branch from 9fcccbd to 48792f6 Compare June 18, 2026 12:42
Squashes prior branch commits:

- Make `to_throw` settings changeable without restart

- Respect settings in local `clickhouse`

- Add runtime settings update test

- Extend tests and respect `server_settings`

- Condense duplicated `Context` code with X-macros

- Fix style check and warning format messages
@UberDever

Copy link
Copy Markdown
Contributor Author

Tests pass, CH Inc sync fails
image

Pushing changes with force to reconcile with current master

@UberDever
UberDever force-pushed the uberdever/feature/changeable-to-throw-settings branch from 3f2cb8f to 03c5aaf Compare June 29, 2026 10:58
@alexey-milovidov

Copy link
Copy Markdown
Member

Merged the latest master into this branch (it was ~378 commits behind) to refresh it and re-trigger CI. The merge was clean — no conflicts, and the net diff against master is exactly the 8 files of this PR.

CI status on the previous run (report)

The only red was Stress test (arm_asan_ubsan, s3), which failed on Logical error: 'Unexpected exception in refresh scheduling' (STID 2508-34af) in RefreshTask::doScheduling (src/Storages/MaterializedView/RefreshTask.cpp:939). That logical error aborts the server under sanitizers, which cascades into the other two sub-failures (Cannot start clickhouse-server and Check failed).

This is a known master-wide flake, unrelated to this PR — it changes *_num_to_throw server limits and does not touch the materialized-view refresh scheduler. The same failure occurs on master itself (pull_request_number = 0) on most days over the last month and across dozens of unrelated PRs. All other 9 stress-test variants (amd_debug, amd_asan_ubsan, amd_tsan, amd_msan, arm_release, arm_debug, arm_asan_ubsan, arm_tsan, arm_msan, arm_ubsan) and the test_table_db_num_limit integration test passed; changed-line coverage was 100%. (It is the same family as the now-closed #106737, which fixed a sibling STID 2508-3e7b.)

Review feedback

Both unresolved review threads appear addressed in the current code:

  • The repetition concern in Context.cpp → consolidated via the X-macro for getters/setters/fields/initialization.
  • The "almost tautological" test → replaced with a parameterized reload test that lowers each *_num_to_throw limit at runtime via SYSTEM RELOAD CONFIG, asserts enforcement (CREATE now throws) and getServerSetting/system.server_settings consistency, then restores the limit and re-checks.

The automated AI review now reports ✅ Approve.

@alexey-milovidov, your CHANGES_REQUESTED review predates the X-macro refactor and the new reload test — could you take another look?

@alexey-milovidov

Copy link
Copy Markdown
Member

Follow-up: the RefreshTask::doScheduling stress flake is already being fixed — #108441 (merged 2026-06-29) and the open follow-up #108890 (Related: #106737). No action needed in this PR.

@alexey-milovidov

Copy link
Copy Markdown
Member

Status after the latest master merge (report)

I went over the current run (commit c9d9c8f5, after the master merge). All builds, Style check, Build (arm_tidy) (clang-tidy) and Fast test are green, and the test_table_db_num_limit integration test already passed on the amd_msan, amd_llvm_coverage and arm_binary shards (the remaining amd_tsan/amd_asan_ubsan shards are still running). CH Inc sync is re-running (PENDING), not failing.

The only red is 02441_alter_delete_and_drop_column in Stateless tests (amd_tsan, parallel, 2/2) — a MUTATE_PART ordering mismatch in the test's own output. This is unrelated to this PR, which only touches the max_*_num_to_throw server limits and does not go near mutations or ALTER DELETE:

  • The CI rerun diagnosis for this exact failure reports Runs: 25, Failed: 0 → "All reruns passed. The failure is not reproducible (likely a transient issue)."
  • In CIDB it is a low-frequency, master-wide flake: it failed on ~10 distinct days across unrelated PRs over the last 90 days, including on master itself (pull_request_number = 0) on 2026-04-29.

I could not find an open issue tracking it.

@groeneai, could you take a look at this flake and open a tracking issue / fix in a separate PR? Failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106821&sha=c9d9c8f533f723c7d2faa39086efe79d8f42657f&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29

Review threads

The two still-open threads are already implemented in the current code, so they look ready to resolve on re-review:

  • Remove the repetition in Context.cpp → consolidated via the APPLY_FOR_CONTEXT_LIMITED_ENTITIES_WITH_WARNING / _WITH_THROW X-macros (getters, setters, fields and initialization).
  • Make the test less tautological → replaced with the parameterized test_runtime_config_reload_of_to_throw_limits, which lowers each of the six *_num_to_throw limits at runtime via SYSTEM RELOAD CONFIG, asserts that CREATE then throws, checks getServerSetting / system.server_settings consistency, and restores the limit afterwards.

@alexey-milovidov, your CHANGES_REQUESTED review predates the X-macro refactor and the new reload test, and the automated AI review now reports ✅ Approve — could you re-review?

@alexey-milovidov

Copy link
Copy Markdown
Member

Update: a second CI red appeared — also a known flake

After my previous status note (where the only red was 02441_alter_delete_and_drop_column), the Stress test (amd_tsan) job also went red on Hung check failed, possible deadlock found. This one is likewise unrelated to this PR:

  • The single hung query in the process-list dump is SELECT formatQuery($$SELECT [[[[…$$) — a deeply nested literal being formatted. The thread dump contains no frames from anything this PR touches (max_*_num_to_throw limits, throwIfTooManyEntities, the atomic settings mirrors, the ConfigReloader update path).
  • It matches the master-wide tracking issue Hung check failed, possible deadlock found #107941 (Hung check failed, possible deadlock found, OPEN). The underlying deep-nested-literal slowness that trips the hang is already being fixed on master by Parse nested literal collections in linear time #108892 (Parse nested literal collections in linear time).

So both current reds are pre-existing flakes (02441_alter_delete_and_drop_column and this Hung check), neither related to the server-limit settings change.

@groeneai, FYI: the Stress test (amd_tsan) Hung check here is the #107941 flake (deep-nested formatQuery literal); the perf fix is in flight as #108892. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106821&sha=c9d9c8f533f723c7d2faa39086efe79d8f42657f&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov Looked into it. Confirmed unrelated to this PR, and the real signature is rarer than the headline suggests. I'm taking the fix-PR route.

The actual flake. Two distinct things hide under "02441 failed on ~10 days":

  • The MUTATE_PART result-differs signature you hit (expected first line MUTATE_PART all_0_0_0_1 ['all_0_0_0'] missing, plus an undeleted 10 20 row) occurred only twice in 90 days: this PR on 2026-06-30, and 2026-04-07 on an unrelated PR's flaky-check. Both are PR runs.
  • The other ~8 hits are unrelated failure modes on other PRs: auto_minmax_index / _block_number / _block_offset errors (a minmax-by-default PR), a notIn "Not-ready Set" LOGICAL_ERROR, SYNC REPLICA timeouts on s3 storage, plus infra (ZK session expiry, process-group timeout).
  • The single pull_request_number = 0 hit on 2026-04-29 is not this signature: it is a DNS_ERROR ("Cannot resolve host ip-172-31-29-165") in a merge-queue Fast test run (head_ref = gh-readonly-queue/master/pr-103641-...), i.e. infra, not the test. So there is no true-master occurrence of this flake in 90 days.

Reports for the real signature: 2026-06-30 (this PR) and 2026-04-07.

Root cause. The test runs SYSTEM STOP MERGES, then ALTER TABLE mut DELETE, then a bounded "funny way to wait" loop (poll system.replication_queue up to 10 times at 2s = 20s) for the MUTATE_PART entry to be assigned. Stop-merges blocks mutation execution, not assignment, so the entry is meant to appear in the queue, be inspected, then execute after SYSTEM START MERGES. Assignment is done asynchronously by the leader's mergeSelectingTask, whose cadence is merge_selecting_sleep_ms with a backoff that grows by merge_selecting_sleep_slowdown_factor up to max_merge_selecting_sleep_ms. CI randomizes merge-tree settings; under contention (e.g. parallel TSAN) the next assignment attempt can land past the 20s window. The loop then proceeds without MUTATE_PART ever assigned, the queue select misses the line, and the n = 10 row is never deleted. That matches both observed outputs exactly.

Plan. This test already has two prior closed flaky issues (#79988, #81948) and two prior test-only fix PRs (#89947, #90032) that reduced but did not eliminate it. I'll reproduce deterministically by inflating the merge-selecting backoff so assignment misses the window, then submit a separate test-only fix PR (likely pinning the merge-selecting cadence low so the MUTATE_PART entry is assigned promptly, pending the repro) that preserves the test's intent of observing the queued MUTATE_PART while merges are stopped. The PR will carry the full root-cause writeup, so a separate tracking issue would be redundant. Say the word if you'd still like one opened.

@groeneai

Copy link
Copy Markdown
Collaborator

Opened the fix for the 02441_alter_delete_and_drop_column flake as a separate PR: #108926. Test-only (extends the async-MUTATE_PART wait from 20s to 60s); reproduced and validated both directions locally via the rmt_merge_selecting_task_pause_when_scheduled failpoint. This PR (#106821) is unrelated to the flake and unaffected.

@UberDever

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov Kindly ping

@alexey-milovidov alexey-milovidov 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.

Passable.

UberDever added 2 commits July 1, 2026 15:53
…o-throw-settings' into uberdever/feature/changeable-to-throw-settings
Address review: the existing integration test in `test_table_db_num_limit`
exercises only the server `ConfigReloader` path. In `clickhouse-local` there
is no `ConfigReloader`, so the `max_*_num_to_throw` limits are enforced solely
because their mirrors are seeded in `Context::setApplicationType`. A regression
there would silently disable enforcement in `clickhouse-local` while the
server-based test keeps passing.

Add a focused stateless test that runs `clickhouse-local` with
`max_table_num_to_throw=1` and checks that the second `CREATE TABLE` throws
`TOO_MANY_TABLES`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Addressed the AI review's required action: added a focused clickhouse-local regression test (04493_clickhouse_local_max_num_to_throw) proving max_table_num_to_throw is enforced via the mirror seeded in Context::setApplicationType, without a running ConfigReloader (as is the case in clickhouse-local).

The only remaining CI failure is Stress test (arm_asan_ubsan, s3) → Logical error: Unexpected return type from A. Expected B. Got C (STID 3262-40aa) in PlannerCorrelatedSubqueries decorrelateQueryPlan. This is an AST-fuzzer-only correlated-subquery decorrelation exception, unrelated to this PR (which only touches the *_num_to_throw entity limits). Over the last 30 days it has fired on 22 distinct PRs and on master itself (pull_request_number = 0), and it is tracked by #107445, #106377, and #107951.

@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.50% +0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.70% +0.10%

Changed lines: Changed C/C++ lines covered: 209/209 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member

The only red check at 532cac8872d is Integration tests (amd_msan, 5/8) → test_drop_replica/test.py::test_drop_replica failing with Database test3 cannot be detached, because some tables are still in use. Retry later.. This is a known race flake in test_drop_replica, unrelated to this PR (which only touches the *_num_to_throw entity limits — test3 is a database created inside test_drop_replica itself). Over the last 30 days the same test failed on master itself (pull_request_number = 0, on 2026-06-18 and 2026-06-26) and on unrelated PRs #105249 and #107442; it is tracked by #93064. Re-triggered the failed shard.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 2, 2026
Merged via the queue into ClickHouse:master with commit ac01c84 Jul 2, 2026
347 of 348 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…/changeable-to-throw-settings

Make `to_throw` settings cheangeable without restart
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-improvement Pull request with some product improvements 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