mrhhsg opened a new pull request, #71336: URL: https://github.com/apache/doris/pull/71336
### Background Recursive CTE execution reuses global runtime-filter contexts across rounds. Each reset replaces the merger and advances its context stage. Pipeline task dumps include query-level and global runtime-filter diagnostics. ### What problem does this PR solve? Issue Number: None Related PR: #71289 (synchronizes publication with reset; does not fix diagnostic reads) PR Type: Bugfix Problem Summary: Global filter diagnostics can read mismatched rounds or access a replaced merger without owning it when a dump overlaps a recursive CTE reset. This PR takes an owning stage/merger snapshot under the context mutex and renders it after releasing that lock. Rendering moves outside pipeline-map shard locks, releasing fragment references before global diagnostics to avoid reverse lock dependencies and delayed destruction. Most additions are unit tests; SQL results and diagnostic field formats remain unchanged. ### Details - **Change map:** Production: +98/-48 in five files; tests: +177/-0 in two files; no generated files or docs. Production parts: owning context snapshots and failure-atomic reset (+35/-8), shard/task/filter lifetime separation (+54/-26), and lock-boundary comments (+9/-14). - **Frequency:** Not observed; found by static code inspection. The trigger is a global diagnostic dump overlapping a recursive CTE filter reset; no occurrence rate is established. - **Root cause:** `RuntimeFilterMergeControllerEntity::debug_string()` reads stage/merger under the map mutex, whereas reset modifies them under the context mutex. It lacks both synchronization and an owning reference; the merger's internal mutex cannot protect the context's shared_ptr replacement or object lifetime. - **Why existing tests missed it:** `RuntimeFilterMgrTest` covers initialization/registration and `FragmentMgrCrossClusterCancelTest` covers classification/cleanup, not diagnostic/reset overlap or ownership. The closest SQL suites, `recursive_cte/rf_merge_context_reuse` and `recursive_cte/rec_cte_parallel_targets`, check recursive results, not diagnostic snapshots. New unit tests cover the missing invariants; existing SQL outputs are unchanged. - **Fix:** Copy stage and a strong merger reference under the context mutex, then render outside map/context locks. Initialize replacements before publication, preserving the old pair on failure. Collect weak fragment references by shard; read each fragment outside shard locks and release it before global diagnostics. - **Other paths and branches:** All-task and duration-filtered dumps share this fix. Query-id dumps use weak snapshots without global merger output; local filter diagnostics already snapshot references. Only master was checked; release-branch impact and the introducing PR are unknown. #71289's publication/reset synchronization is unchanged and did not introduce this diagnostic pattern. ### Testing All runs below were local on the patched code: - `BUILD_TYPE_UT=ASAN DORIS_TOOLCHAIN=clang ./run-be-ut.sh --run --filter='RuntimeFilterMgrTest.*:FragmentMgrCrossClusterCancelTest.*' -j 32`: 11/11 passed, including snapshot ownership, failed-reset preservation and recovery, and 32 bounded rounds of concurrent reset and actual task dumping. - `./run-regression-test.sh --conf <isolated-conf> --run -d recursive_cte -s rf_merge_context_reuse`: one suite passed, with zero failures, fatal scripts or skips; existing ordered output matched. - `./run-regression-test.sh --conf <isolated-conf> --run -d recursive_cte -s rec_cte_parallel_targets`: one suite passed, with zero failures, fatal scripts or skips. No pre-fix failure is claimed: the defect was confirmed statically, and only the patched code was exercised. ASAN is not a data-race detector. The bounded concurrency test does not force every interleaving or exercise real task destruction/cancellation; TSAN and multi-BE/mixed-version tests were not run. ### Notes for Reviewers Start with `GlobalMergeContext::snapshot_for_debug()` and `FragmentMgr::dump_pipeline_tasks(int64_t)`. Snapshots may show an earlier complete round, not a query-wide instant. Context addresses require the caller-owned entity and its non-erasing node-based map. Fragment references end before RF diagnostics to preserve `WAIT_FOR_DESTROY` progress. Fragment-context edits only update comments. ### Release note Fix inconsistent global runtime-filter diagnostic state when recursive CTE filters are reset concurrently. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Partially verified: local ASAN unit tests and SQL regressions passed; TSAN and multi-BE/mixed-version tests were not run. ### AI Disclosure - Tool: Codex - Generated: Code, unit tests and this description - Human review: No human review is recorded. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
