Skip to content

Multiple static stateless worker clusters, selectable per query - #124938

Merged
serxa merged 13 commits into
masterfrom
multiple-static-worker-clusters
Oct 17, 2026
Merged

serxa merged 13 commits into
masterfrom
multiple-static-worker-clusters

Conversation

@serxa

@serxa serxa commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

A server can now configure several stateless worker clusters and pick one per query.

  • The flat stateless_worker_client block remains the default cluster, so existing configs keep working unchanged. Named clusters go under stateless_worker_client.clusters.<name>, and each names exactly one worker source: a cluster (a single-shard remote_servers entry) or a host. The default can be given a name with default_cluster_name, or omitted for a symmetric config where every query names its cluster.
  • The new query setting distributed_plan_worker_cluster selects the cluster for a query's distributed plan (empty = the default). An unknown cluster, one without a worker source, or an empty selection when there is no default is rejected rather than silently run locally.
  • IStatelessWorkersProvider abstracts a worker source. StatelessWorkersProviderFactory builds providers from registered provider kinds; this build registers one, static. StatelessWorkersProviderRegistry owns one provider per cluster and builds it on first use.
  • The query context resolves its cluster's provider once, so plan sizing (getCascadesPlanningNodeCount) and the per-query StatelessWorkerAllocation use the same provider and worker set.
  • On config reload, a cluster whose configuration changed is retired and rebuilt on its next use; queries still holding the old provider drain on it. Reload never throws: a cluster whose new configuration cannot be applied is retired, and the error surfaces to the next query that selects it.

Tests: gtests for the static provider (host/cluster forms, single-shard check, snapshot across reload, remote_servers changes), the registry (named cluster, reload retirement, broken config on reload), the per-query provider resolution, and plan sizing for default/named/no-default/disabled/ambiguous configurations.

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):

Not for changelog.


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

Version info

  • Merged into: 26.11.1.120-master (included in 26.11 and later)

A server can configure several stateless worker clusters: the flat
`stateless_worker_client` block stays the default cluster, and named clusters
live under `stateless_worker_client.clusters.<name>`. A query picks one with the
new `distributed_plan_worker_cluster` setting.

`IStatelessWorkersProvider` abstracts a worker source. Providers are built by
`StatelessWorkersProviderFactory` from registered provider kinds; this build
registers `static`, a fixed `cluster` (single-shard `remote_servers` entry) or
`host`. `StatelessWorkersProviderRegistry` owns one provider per cluster, builds
it on first use, and on config reload retires a cluster whose configuration
changed (queries still holding it drain on it) without ever throwing.

The query context resolves its cluster's provider once, so plan sizing and the
allocation (`StatelessWorkerAllocation`) see one provider and one worker set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [92f7b09]

Summary: ✅


AI Review

Summary

The PR adds named stateless worker clusters, query-level cluster selection, and cached providers shared between planning and allocation. Two previously reported reload concerns remain in the current code; both were explicitly dismissed by the author and are retained below without reopening their threads. No new inline findings.

Missing context / blind spots
  • ⚠️ The Cloud discovery provider is outside this checkout. Its registration, configuration signatures, token refresh, and lease lifecycle need validation against the matching Cloud implementation.
  • ⚠️ No local build directory or ClickHouse binary is available, so this review used source tracing and existing CI reports; it did not execute the added gtests.
Findings

⚠️ Majors

  • src/Server/StatelessWorker/StatelessWorkersProviderRegistry.cpp:97 A lookup can select the wrong worker pool during reload. getConfigRef returns the live layered configuration, so canonicalization, signing, and construction can straddle the server configuration replacement. For example, changing the default name from blue to red while adding a named blue cluster can make a lookup for blue return the new default pool. The query then pins that unrelated provider. Retain an immutable configuration for the entire lookup, or detect a generation change and reject/retry the lookup.
    [dismissed by author -- https://github.com/Multiple static stateless worker clusters, selectable per query #124938#discussion_r4276027374] The author accepts inconsistent resolution during reload; this remains material because execution can pin an unrelated pool for the lifetime of the query.

  • src/QueryPipeline/DistributedPlanExecutor.cpp:1388 Repeated planning bypasses the query's pinned provider after disabling the client. A subsequent planning pass, including a deferred IN source plan, throws for a named selection or returns zero for the implicit default, which Cascades rejects. Allocation still accepts the same held provider. Consult an already-resolved provider before applying the disabled-client behavior to first-time resolution.
    [dismissed by author -- https://github.com/Multiple static stateless worker clusters, selectable per query #124938#discussion_r4276027380] The author accepts failing in-flight multi-plan queries; this still contradicts the PR description's unqualified promise that queries holding retired providers drain on them.

Tests
  • ⚠️ Add a deterministic lookup test that replaces the live configuration between cluster canonicalization and provider construction; sequential setConfig tests do not cover this race.
  • ⚠️ Extend disabling-reload coverage to repeat getCascadesPlanningNodeCount on the held query for default and named selections, alongside the existing allocation assertion.
Final Verdict

Status: ⚠️ Request changes. Make provider lookup consistent across reload and preserve pinned-provider planning, or explicitly narrow the advertised reload contract and document/test the accepted limitations. Existing dismissed threads were left untouched; no new review batch was submitted.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 9, 2026
@serxa
serxa marked this pull request as ready for review October 9, 2026 15:55
A provider kind is registered under the configuration key that selects it
(`cluster` and `host` for the static kind), so the factory finds a cluster's
kind from the keys it sets and the per-kind source counting is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Oct 9, 2026
…e client is disabled

The worker fill no longer re-checks `stateless_worker_client.enabled`: a query that
resolved its provider keeps allocating from it after a reload disables the client,
while resolving a new provider is refused by the registry (`SUPPORT_IS_DISABLED`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The server publishes a new configuration before it reloads the registry, so a
lookup compares the cached provider's signature with the live configuration and
rebuilds it on a mismatch; a query started after the change never resolves to the
stale provider.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ected and signed with

A lookup reads the server configuration once and uses it for the cluster selection,
the signature and the build, including the static provider's worker resolution, so
a reload published in between cannot mix two configurations. Building also refuses a
cluster that does not configure exactly one worker source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 92f7b09714b325391f22f0920a1a1e0af7f90a11 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception; stopped retrying after the 1250 s read budget).

See the job log for details.

@serxa

serxa commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

@groeneai, please investigate the AST fuzzer failure and provide a fix in a separate PR. If the fix is already in progress, link it here.

Job: https://github.com/ClickHouse/ClickHouse/actions/runs/38013471256/job/114117867192
STID: 4752-3ae2 — Logical error: Left and right columns have same names: [A], [B] in JoinExpressionActions / JoinStepLogical::deserialize

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. The throw is in the three-argument JoinExpressionActions constructor that JoinStepLogical::deserialize calls: it rejects __join_result_dummy being present in both input headers. My open #108787 changes exactly that check. I am verifying that it covers this distributed plan executor path and will confirm here, or follow up with a separate PR if it does not.

@groeneai

Copy link
Copy Markdown
Collaborator

Follow-up: #108787 does not fix this one. Its name-based fallback assigns the first DAG input to the left side, which is wrong for a join swapped by Cascades join commutativity, the shape in this failure. The fix is #125071: the Join step now serializes the side of every input of its actions DAG. Its regression test fails on master in 20 of 20 randomized runs and passes on the branch in 50 of 50.

serxa and others added 2 commits October 10, 2026 12:08
`StatelessWorkersProviderRegistry::getBuiltProviders` returns the providers built so
far, by cluster, without building any. Drops the unused
`Context::tryGetStatelessWorkersProvider`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
serxa and others added 5 commits October 16, 2026 13:20
…refix on reload

A provider lookup computes the configuration signature before taking the registry
mutex, so concurrent queries do not serialize on it. A reload passes each provider
its cluster's configuration prefix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- `getBuiltProviders` reports the default cluster under its `default_cluster_name`,
  so the system table no longer handles the registry's empty key;
- the discovery provider's worker reachability check is a method rather than an
  injected function; tests replace it through the lease hooks;
- rename `computeConfigSignature` to `computeConfigSignatureForCluster`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ker-clusters

# Conflicts:
#	src/QueryPipeline/DistributedPlanExecutor.cpp
@serxa
serxa added this pull request to the merge queue Oct 17, 2026
Merged via the queue into master with commit 76cb67e Oct 17, 2026
179 checks passed
@serxa
serxa deleted the multiple-static-worker-clusters branch October 17, 2026 13:43
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 17, 2026
raimannma pushed a commit to raimannma/ClickHouse that referenced this pull request Nov 1, 2026
On a server without a `stateless_worker_client` block (the stock config,
and the NightlySQLancer server) `make_distributed_plan = 1` failed with
NO_ELEMENTS_IN_CONFIG "No default stateless worker cluster is configured;
set `distributed_plan_worker_cluster` to one of: ." (an empty list).

`StatelessWorkersProviderRegistry::getProvider` canonicalized the cluster
selection first, and the `enabled` check lived in `buildProvider`, after
it. ClickHouse#124938 removed the check from `fillWorkerAddresses` because "resolving
a new provider is refused by the registry (SUPPORT_IS_DISABLED)", but that
held only when a disabled client still named a worker source.

Check `enabled` at the start of `getProvider` and drop the duplicate in
`buildProvider` (its only caller, same configuration object). A disabled
client never resolved a provider before either: a cached entry's signature
never matches the empty signature of a disabled client, so only the error
changes. A query that already resolved its provider still drains on it,
since `Context::getStatelessWorkersProvider` never re-enters the registry.

The SQLancer DistributedPlanEquivalence oracle expects SUPPORT_IS_DISABLED
but not the new message, so every database was a finding and the
2026-10-19 nightly stopped at the 2000-finding cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... and removed comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... 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.

4 participants