This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 5d1930699cd branch-4.1: [fix](runtime-filter) Publish merged filter
under the merge-context lock #71289 (#71329)
5d1930699cd is described below
commit 5d1930699cd22451bce3024edc22703acd8dfb5c
Author: Jerry Hu <[email protected]>
AuthorDate: Sat Dec 5 22:18:48 2026 +0800
branch-4.1: [fix](runtime-filter) Publish merged filter under the
merge-context lock #71289 (#71329)
### What problem does this PR solve?
Issue Number: None
Related PR: #71289
Cherry-picked from #71289 to `branch-4.1`.
`RuntimeFilterMergeControllerEntity::merge()` released
`GlobalMergeContext::mtx` before publishing the merged runtime filter. A
concurrent recursive CTE round reset can replace the merger and clear
the publication state under the same lock. This can invalidate the
borrowed Bloom filter buffer between serialization and copying, or mix
readiness and publication state from different rounds.
### Changes
- Keep the readiness check and `_send_rf_to_target()` inside the
existing merge-context critical section, protecting serialization, the
attachment copy, publication state, and asynchronous RPC submission
against round reset.
- Preserve the existing `branch-4.1` stale-stage and null-merger checks,
error handling, and direct/tree publication paths. RPC completion is not
awaited under this lock.
- Add the complete recursive CTE regression fixture and expected output,
which are absent from `branch-4.1`. The coverage checks cross-Exchange
runtime-filter publication and explicitly exercises Bloom filters.
### Release note
Prevent runtime-filter publication from racing with recursive CTE round
resets.
### Testing
Local validation of the final code tree:
- `BUILD_TYPE=ASAN FE_MAVEN_THREADS=8 ./build.sh --be --fe -j 48`:
passed, including Maven Checkstyle (zero violations).
- `./run-be-ut.sh --run --filter='RuntimeFilterMgrTest.*' -j 48`: 5/5
passed.
- Recursive CTE regression (`-d recursive_cte -s rf_merge_context_reuse
-parallel 1 -times 3`): 3/3 runs passed.
- Existing runtime-filter regressions (`-d
nereids_p0/runtime_filter,query_p0/runtimefilterV2 -parallel 1`): 6/6
suites passed; no failures or skips.
- `clang-format --dry-run --Werror
be/src/exec/runtime_filter/runtime_filter_mgr.cpp` (clang-format 16):
passed.
- `git diff --check`: passed for the complete backport diff.
- Post-shutdown BE log scan found no ASAN/UBSAN/LSAN error signatures.
Both regression selections used `./run-regression-test.sh --run` with an
isolated local configuration and one ASAN-enabled BE. Multi-BE stress,
deterministic race reproduction, and performance testing were not run.
### Check List (For Author)
- Test:
- [x] Regression test
- [x] Unit Test
- Behavior changed:
- [x] Yes. Runtime-filter publication is synchronized with recursive CTE
round reset; SQL semantics and the wire format are unchanged.
- Does this need documentation?
- [x] No.
---
be/src/exec/runtime_filter/runtime_filter_mgr.cpp | 23 ++++---
.../data/recursive_cte/rf_merge_context_reuse.out | 12 ++++
.../recursive_cte/rf_merge_context_reuse.groovy | 71 ++++++++++++++++++++++
3 files changed, 98 insertions(+), 8 deletions(-)
diff --git a/be/src/exec/runtime_filter/runtime_filter_mgr.cpp
b/be/src/exec/runtime_filter/runtime_filter_mgr.cpp
index f69efa855a9..9d75968526d 100644
--- a/be/src/exec/runtime_filter/runtime_filter_mgr.cpp
+++ b/be/src/exec/runtime_filter/runtime_filter_mgr.cpp
@@ -605,15 +605,22 @@ Status
RuntimeFilterMergeControllerEntity::merge(std::shared_ptr<QueryContext> q
RETURN_IF_ERROR(cnt_val.merger->merge_from(tmp_filter.get(),
&is_ready));
cnt_val.arrive_id.insert(UniqueId(request->fragment_instance_id()));
- }
- if (is_ready) {
- return _send_rf_to_target(cnt_val,
- query_ctx->ignore_runtime_filter_error()
- ? std::weak_ptr<QueryContext> {}
- : query_ctx,
- merge_time, request->query_id(),
query_ctx->execution_timeout(),
- query_ctx->query_options());
+ if (is_ready) {
+ // Publish while `cnt_val.mtx` is still held. reset_global_rf()
replaces and destroys
+ // `merger` under the same lock, while serialize() hands out a raw
pointer into the
+ // merger's filter buffer and the publish state (`done`, `stage`,
+ // `publish_callbacks`) belongs to the current stage. Keeping the
readiness check and
+ // the whole publish in one critical section makes them atomic
with respect to a
+ // recursive CTE round reset; otherwise the merger can be
destroyed between
+ // serialize() and the memcpy of its buffer.
+ return _send_rf_to_target(cnt_val,
+ query_ctx->ignore_runtime_filter_error()
+ ? std::weak_ptr<QueryContext> {}
+ : query_ctx,
+ merge_time, request->query_id(),
+ query_ctx->execution_timeout(),
query_ctx->query_options());
+ }
}
return Status::OK();
}
diff --git a/regression-test/data/recursive_cte/rf_merge_context_reuse.out
b/regression-test/data/recursive_cte/rf_merge_context_reuse.out
new file mode 100644
index 00000000000..708a1c68855
--- /dev/null
+++ b/regression-test/data/recursive_cte/rf_merge_context_reuse.out
@@ -0,0 +1,12 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !recursive --
+1
+2
+3
+4
+
+-- !recursive_bloom --
+1
+2
+3
+4
diff --git a/regression-test/suites/recursive_cte/rf_merge_context_reuse.groovy
b/regression-test/suites/recursive_cte/rf_merge_context_reuse.groovy
new file mode 100644
index 00000000000..654c8b5eec9
--- /dev/null
+++ b/regression-test/suites/recursive_cte/rf_merge_context_reuse.groovy
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+suite('rf_merge_context_reuse') {
+ sql 'drop table if exists rf_merge_reuse_edges'
+ sql '''create table rf_merge_reuse_edges (src int, dst int) duplicate
key(src)
+ distributed by hash(src) buckets 4 properties ("replication_num" =
"1")'''
+ sql 'insert into rf_merge_reuse_edges values (1, 2), (2, 3), (3, 4)'
+ // Keep the probe scan in its own fragment. With bucket shuffle enabled
the regulator may put
+ // it into the join fragment (BUCKET_SHUFFLE) for small
parallel_pipeline_task_num values,
+ // which turns the RF into a local filter: no global merge coordinator, no
publish, and no
+ // round reset on that path. P0 fuzzes parallel_pipeline_task_num, so pin
the plan instead of
+ // letting the coverage depend on the connection.
+ sql 'set enable_bucket_shuffle_join = false'
+ // P0 fuzzes enable_runtime_filter_prune as well. The pruner keeps this RF
today (the build
+ // side has no usable statistics), but pin the setting so the plan
assertions below cannot
+ // depend on the pruner's future decisions.
+ sql 'set enable_runtime_filter_prune = false'
+
+ String plan = sql('''explain with recursive numbers(n) as (
+ select cast(1 as int)
+ union all
+ select cast(e.dst as int) from
rf_merge_reuse_edges e
+ inner join [shuffle] numbers r on e.src = r.n
where r.n < 4
+ ) select n from numbers order by n''').toString()
+ // The recursive join must publish RFs across an Exchange on every round;
+ // a constants-only recursive query never exercises the merge-context
reset.
+ assertTrue(plan.contains('INNER JOIN(PARTITIONED)'), plan)
+ assertTrue(plan.contains('runtime filters: RF'), plan)
+ assertTrue(plan.contains('-> src'), plan)
+ assertTrue(plan.contains('VEXCHANGE'), plan)
+
+ order_qt_recursive '''with recursive numbers(n) as (
+ select cast(1 as int)
+ union all
+ select cast(e.dst as int) from
rf_merge_reuse_edges e
+ inner join [shuffle] numbers r on e.src = r.n
where r.n < 4
+ ) select n from numbers order by n'''
+
+ // A merged Bloom filter is serialized as a raw pointer into the merger's
buffer and then
+ // copied by the coordinator, while a small IN set is copied through
protobuf. Force Bloom
+ // (runtime_filter_type = 2) so the recursive rounds also exercise that
copy path, which a
+ // round reset must not invalidate.
+ sql 'set runtime_filter_type = 2'
+ String bloomPlan = sql('''explain with recursive numbers(n) as (
+ select cast(1 as int)
+ union all
+ select cast(e.dst as int) from
rf_merge_reuse_edges e
+ inner join [shuffle] numbers r on e.src = r.n
where r.n < 4
+ ) select n from numbers order by n''').toString()
+ assertTrue(bloomPlan.contains('runtime filters: RF') &&
bloomPlan.contains('[bloom]'), bloomPlan)
+ order_qt_recursive_bloom '''with recursive numbers(n) as (
+ select cast(1 as int)
+ union all
+ select cast(e.dst as int) from
rf_merge_reuse_edges e
+ inner join [shuffle] numbers r on e.src = r.n
where r.n < 4
+ ) select n from numbers order by n'''
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]