Repository navigation
Propagate the cluster-function read-task callback into SQL SECURITY views - #113371
Conversation
…iews A SELECT through a SQL SECURITY DEFINER or NONE view whose inner query is a cluster table function (s3Cluster, urlCluster, fileCluster) aborted the server in debug and sanitizer builds when the SELECT itself arrived as a secondary query, for example when the view is read through remote() or clusterAllReplicas, or when the AST fuzzer wraps the query in remoteSecure(): Logical error: Next task callback is not set for query <id> StorageInMemoryMetadata::getSQLSecurityOverriddenContext rebuilds the view context from the global context for the DEFINER and NONE branches, so the definer must not inherit the invoker's identity, then re-propagates the query-scoped state item by item. It carried the three MergeTree parallel-replicas callbacks but not next_task_callback, so the cluster table function inside the view could no longer reach the initiator that decides whether to serve the read task, and Context::getClusterFunctionReadTaskCallback threw. The ordinary Context copy constructor does carry next_task_callback, and the INVOKER branch uses that constructor, so the same query through an INVOKER view already worked. That differential shows the omission was accidental rather than a policy, so the callback is now propagated for the other two branches as well. The propagation is placed above the NONE early return so both branches are covered, mirroring commit 7f75908, which fixed the same bug class in this function for the MergeTree callbacks. The unsupported nesting now lands on the existing rejection in RemoteQueryExecutor::processReadTaskRequest and reports BAD_ARGUMENTS "A cluster table function (s3Cluster, urlCluster, fileCluster, ...) cannot be nested inside another distributed query", which is what an INVOKER view already produced, and the server stays alive. Legitimate distribution is unaffected because those paths install a task iterator on the initiator. The LOGICAL_ERROR at the three callback consumers is deliberately kept: once the propagation is correct, a missing callback under distributed processing is a genuine internal invariant violation, and turning it into a user-facing error would mask future propagation gaps.
Internal second-model review (2 issues fixed, 2 declined with evidence)An independent model reviewed this change cold against the repository review checklist, separately
|
Pre-PR validation gate (a-i)
Non-regression: |
|
cc @SmitaRKulkarni @devcrafter, could you review this? A SQL SECURITY DEFINER or NONE view rebuilds its context from the global context and re-propagated every query-scoped callback except next_task_callback, so a cluster table function inside the view lost its channel to the initiator and hit a logical error that aborts debug and sanitizer builds; an INVOKER view already worked because that branch uses the ordinary Context copy constructor. @devcrafter, you own the sibling #111677, which is the similarly worded merge_tree_all_ranges_callback variant and is not what this fixes. |
|
Workflow [PR], commit [81f1a79] Summary: ❌
AI ReviewSummaryThis PR propagates the missing Final Verdict✅ No findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing 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. Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Parquet/GeoFilter.cpp.o |
new | 860.64 KiB | +860.64 KiB |
src/CMakeFiles/dbms.dir/Storages/MergeTree/SharedPartColumns.cpp.o |
new | 294.32 KiB | +294.32 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Parquet/Reader.cpp.o |
558.56 KiB | 634.53 KiB | +75.97 KiB (+13.60%) |
src/CMakeFiles/dbms.dir/Storages/MergeTree/IMergeTreeDataPart.cpp.o |
1.38 MiB | 1.33 MiB | -46.27 KiB (-3.28%) |
src/CMakeFiles/dbms.dir/Storages/MergeTree/ColumnsSubstreams.cpp.o |
132.58 KiB | 154.18 KiB | +21.60 KiB (+16.29%) |
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
7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline.
CI finish ledger - 81f1a79Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260805-033000 |
c068f0e
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRPropagate the cluster-function read-task callback into SQL SECURITY views ClickGap verified: reproduced it with the script below on Reproduction-- Needs a server with a cluster `test_cluster_two_shards_localhost` (two self-pointing shards)
-- and a debug/sanitizer (or RelWithDebInfo) build so the LOGICAL_ERROR is visible.
CREATE OR REPLACE VIEW v SQL SECURITY DEFINER AS
SELECT * FROM fileCluster('test_cluster_two_shards_localhost', 'data.tsv', 'TSV', 'x UInt8');
SELECT count() FROM remote('127.0.0.1:9000', currentDatabase(), 'v')
SETTINGS prefer_localhost_replica = 0;
-- Observed (pre-fix): LOGICAL_ERROR "Next task callback is not set for query <id>: While executing File"
-- which aborts a debug/sanitizer server. Fixed: BAD_ARGUMENTS "... cannot be nested inside
-- another distributed query", server stays alive. Same for SQL SECURITY NONE and s3Cluster/urlCluster.Bisect
Affects
Suggested next stepThe fix has landed on master; Component: ClickGap · Finding: Triage metadata
|
Related: #110972
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERRORNext task callback is not set for querywhen aSQL SECURITY DEFINERorSQL SECURITY NONEview over a cluster table function (s3Cluster,urlCluster,fileCluster) was read as a secondary query, for example throughremoteorclusterAllReplicas. The unsupported nesting is now rejected with a normal query error instead of aborting the server in debug and sanitizer builds.Description
Found by CI: Stress test (amd_tsan) on #110972. 6 hits in 30 days, over 5 unrelated pull requests by different authors plus one master run, so it is a trunk bug, not any one PR's fault.
What breaks: a
SELECTthrough aSQL SECURITY DEFINERorNONEview over a cluster table function aborts a debug or sanitizer server when thatSELECTarrives as a secondary query. The failing CI query wasSELECT count() FROM remoteSecure(..., 'test_view'), wrapped by the AST fuzzer. Read locally the view always worked, so no stateless test caught this.Root cause:
StorageInMemoryMetadata::getSQLSecurityOverriddenContextrebuilds the view context from the global context for those two branches, so the definer does not inherit the invoker's identity, then re-propagates query state item by item. It carried the three MergeTree parallel-replicas callbacks but notnext_task_callback, so the cluster function inside the view could not reach the initiator that decides whether to serve its read task. The ordinaryContextcopy constructor does carry it, andINVOKERuses that constructor, so anINVOKERview already worked: the omission was accidental, not policy.The fix propagates the callback for the other two branches, above the
NONEearly return so both are covered, mirroring7f75908b72374e3which fixed the same bug class here for the MergeTree callbacks. The unsupported nesting then lands on the existing rejection inRemoteQueryExecutor::processReadTaskRequestand reportsBAD_ARGUMENTS, asINVOKERalready did, with the server alive. Legitimate distribution is unaffected, since those paths install a task iterator on the initiator, and theLOGICAL_ERRORat the three consumers stays a genuine invariant.New test
04810_definer_view_over_cluster_functioncovers the three security modes across the three cluster functions and both analyzers, withINVOKERas control.Validation matrix (18 cells, before and after)
Note on a similar message:
Context::getMergeTreeAllRangesCallbackthrowsNext task callback is not set for query with id:, but reads a different member. That is the parallel-replicas variant tracked by #111677, which this PR does not address.Each cell is a
SQL SECURITY <mode>view over the named cluster function, read viaremote(...)withprefer_localhost_replica = 0. The server was restarted before every cell and itsbuildIdasserted against the binary under test, because aLOGICAL_ERRORaborts a debug server and would otherwise silently blind later cells.The
INVOKERrow is the control: it never lost the callback, and its verdict is identical on both arms, so the difference in the other twelve cells is attributable to the change rather than to the environment.Test
04810fails on pristine HEAD with theLOGICAL_ERRORin the server log and passes with the change; 50/50 passes with randomized settings.03850_nested_cluster_table_function_task_iteratorpasses unchanged, which is the evidence that legitimate distribution still reads each task exactly once, as does03667_view_with_s3_cluster_and_sql_security_definer. A 56-test sweep of everything touching a cluster table function orSQL SECURITYgives identical verdicts on both arms.Version info
26.8.1.813(included in26.8and later)