Repository navigation
Conversation
…limit
The AST fuzzer found a std::length_error (server abort in debug and sanitizer
builds) reachable with make_distributed_plan, enable_cascades_optimizer and a
very large distributed_plan_workers_num:
SELECT count() FROM t
SETTINGS enable_cascades_optimizer = 1, make_distributed_plan = 1,
distributed_plan_execute_locally = 1,
distributed_plan_workers_num = 9223372036854775807;
buildContext resolves cluster_node_count from the internal query parameter,
from distributed_plan_workers_num, or from the configured worker cluster, and
checks only for zero. The ParallelRead rule passes the resolved count through as
the read's bucket count, and sliceMarksAcrossBuckets sizes a std::vector to it as
its first statement. The 256 bucket ceiling is already threaded into
setupDistributedReadBuckets and is consulted, but only after the allocation.
buildContext now also rejects a resolved count above
max_distributed_read_buckets, beside the existing zero check. Bounding the
resolved value covers all three sources of the count and every consumer of it,
including the read buckets, the layer budget the FINAL path derives from them,
and the exchange fan-out sized from the count by DistributionEnforcer.
The bound is deliberately not placed inside sliceMarksAcrossBuckets: the FINAL
path legitimately calls it with target_buckets * 16 derived counts and only
afterwards groups the resulting layers into at most 256 tasks, so a check there
would drop non-intersecting ranges while intersecting ones remained.
A count above the ceiling cannot produce a bucketed read: the read would split
into that many buckets and is then refused for exceeding the same ceiling. The
plan is not necessarily single-node, though: a serial read can still feed a
scatter or broadcast sized from the count, and a replicated read pins one bucket
while advertising the full count. Bounding the count bounds that fan-out too,
which is the memory cost the sibling cap on
distributed_plan_default_reader_bucket_count already limits with the same
ceiling, error code and test file.
One deliberate behaviour change: a count above 256 that did not reach the plain
slicer (257, a FINAL read, or a statically configured worker cluster above 256
replicas) is planned today and is now refused with INVALID_SETTING_VALUE. Such a
plan reads serially but can still scatter to that many exchange destinations, so
distributed plans are affected. No result changes silently.
04320_distributed_plan_read_rejects gains seven arms covering both sources of the
count, both read paths, and three positive controls: 256 accepted on the plain
and FINAL paths, and a rule-based query with a huge distributed_plan_workers_num
left untouched, since without Cascades the count never becomes a bucket count.
Deleting the bound makes the file abort, and widening it to reject 256 makes the
positive controls raise instead of answering, since the bound refuses rather than
falling back to a serial read.
Internal second-model review (3 rounds, all findings resolved)This PR went through an independent cold review plus a separate second-model gate on each round, with
One round was spent on a rebase: master moved 150 commits mid-review and renamed the type the guard Validation on the shipped tree: the bound was deleted (test aborts with the original |
Pre-PR validation gate (click to expand)
Suite check: the 65 |
|
Workflow [PR], commit [4fdbf54] Summary: ✅
AI ReviewSummaryThis PR fixes the Findings❌ Blockers
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 4/7 (57.14%) · Uncovered code |
|
cc @davenger @KochetovNicolai, could you review this? The Cascades cluster node count is resolved in |
| "(also required for `distributed_plan_execute_locally` without a configured cluster)."); | ||
| /// The count sizes the read buckets and the exchange fan-out, so the read-bucket ceiling bounds it | ||
| /// too: above it a plan would scatter to more destinations than a bucketed read may have. | ||
| if (context.cluster_node_count > ReadFromMergeTree::max_distributed_read_buckets) |
There was a problem hiding this comment.
This turns the 256 fan-out cap into a global cluster-size cap. buildContext now throws before the optimizer has seen whether the winning plan will ever materialize a >256-way read or exchange, but the memo still has explicit {1 node} fallbacks (LocalReadImplementation, DefaultImplementation) and the root requirement still starts at {1 node}. On a worker cluster with more than 256 replicas, that means even queries whose chosen Cascades plan would stay local now fail up front. Can we move this bound to the places that actually construct >256 fan-out, or otherwise keep the existing single-node fallback for queries that do not need it?
There was a problem hiding this comment.
Agreed, and I reproduced it. This is a real over-refusal and the bound is in the wrong place.
Two A/B measurements on SELECT 1, with no table involved, so no fan-out can be constructed. Base is unpatched 071c010e (Build ID c26e0799), fix is this PR's head (Build ID ae0d046a):
| node count from | 256 | 257 |
|---|---|---|
distributed_plan_workers_num |
both answer 1 |
base answers 1, this PR raises Code: 471 |
a configured stateless_worker_client.cluster with that many <replica> entries, setting unset |
both answer 1 |
base answers 1, this PR raises Code: 471 |
The second row is your scenario exactly: an operator with a 257-node worker cluster sets nothing unusual, and SELECT 1 still fails up front.
I also checked whether anything above 256 is merely a dead configuration, and it is not. On a 300-replica cluster the read declines to bucket and falls back (No parallel read for 'default.t': the read splits into 0 buckets instead of 300), with no length_error, and execution proceeds past planning into TaskToHostMap::fillWorkerAddresses. Sweeping the count on base, 257, 1e5, 1e7, 1e9 and 2e9 all plan without aborting; the std::length_error I set out to fix only appears at the extreme tail (2^62 and 2^63-1, confirmed in the server log by Code: 1001 with sliceMarksAcrossBuckets and setupDistributedReadBuckets frames). So the guard refuses about 4.6e18 values of which only the far tail is dangerous, and 256 is roughly ten orders of magnitude below the real boundary.
One correction to my own PR description while I am here: it claims a count above the ceiling "cannot produce a bucketed read", implying nothing is lost. The fallback trace above shows what actually happens is a serial read that still runs, so the sentence understates the cost of the refusal.
On where the bound belongs, I would rather not pick unilaterally, because the options differ in which plans get produced:
- clamp inside
getCandidateNodeCounts(Cascades/RuleUtils.h:28), the single helper all four multi-node consumers go through (DistributionPassthrough.cpp:71,HashJoinImplementation.cpp:442,TopNImplementation.cpp:66,AggregationImplementations.cpp:227), so a large cluster plans at 256-way parallelism instead of failing; - bound only where fan-out is materialized, leaving the read path as is. It is already self-limiting:
tryMakeBucketedReadVariantreturnsnullptrwhenactual_buckets != target_buckets(RuleUtils.cpp:39-41), which is what produced the fallback above; - keep a refusal but raise it only once a plan that actually needs the oversized fan-out is selected.
@davenger, you own this area: which of those shapes do you want? Clamping in getCandidateNodeCounts looks smallest to me and keeps large clusters working, but it changes planned parallelism on such clusters, so I would rather have your call than guess. I will rework the PR to whichever you prefer.
There was a problem hiding this comment.
Correcting myself on one point above: I wrote that the "cannot produce a bucketed read" sentence is in the PR description. It is not, it is in the commit message. The PR description already says the honest thing ("Such a plan reads serially but can still scatter to that many exchange destinations"), so the disclosure was there and I misattributed it. The substantive part stands: 257 through 2e9 plan fine on base, and the refusal costs a working serial read.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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. Compile time of recompiled translation units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
ff4ddd3
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A very large
distributed_plan_workers_numno longer makes the server abort with astd::length_errorwhen the experimentalmake_distributed_planandenable_cascades_optimizerareenabled. Such a node count is now rejected with
INVALID_SETTING_VALUE.Description
Related: #109770
That PR capped the sibling setting the same way.
Found by
AST fuzzer (arm_asan_ubsan):CI report
(unrelated carrier PR). Reproduces deterministically:
buildContextresolvescluster_node_countfrom the internal query parameter, fromdistributed_plan_workers_num, or from the configured worker cluster, checking only for zero. TheParallelReadrule passes it through as the read's bucket count, andsliceMarksAcrossBucketssizesa vector to it as its first statement, before the 256 ceiling already threaded in is consulted.
buildContextnow also rejects a resolved count abovemax_distributed_read_buckets, beside theexisting zero check. Bounding the resolved value covers all three sources of the count and every
consumer of it: the read buckets, the layer budget
FINALderives from them, and the exchange fan-outsized from the count. Not inside
sliceMarksAcrossBuckets, whichFINALlegitimately calls withtarget_buckets * 16-derived counts before grouping the layers into at most 256 tasks.Behaviour change: a count above 256 that did not reach the plain slicer (
257, aFINALread, or aworker cluster above 256 replicas) is planned today and is now refused. Such a plan reads serially but
can still scatter to that many exchange destinations, which is the memory cost this same ceiling
already bounds for the sibling settings. @ davenger, say so if you would rather bound the setting
itself (a worker lease count) or clamp.
04320_distributed_plan_read_rejects.sqlgains seven arms: both sources of the count, both read paths,and three positive controls (256 accepted on the plain and
FINALpaths, plus a rule-based query witha huge
workers_numuntouched). It fails on unpatched master withserver died, and passed 50/50runs with the fix.
Workflow [PR]
Sync PR [sync-upstream/pr/115398]
Version info
26.8.1.1837(included in26.8and later)