hello-stephen commented on code in PR #71336:
URL: https://github.com/apache/doris/pull/71336#discussion_r4780750420


##########
be/src/exec/runtime_filter/runtime_filter_mgr.cpp:
##########
@@ -785,10 +793,20 @@ Status 
RuntimeFilterMergeControllerEntity::reset_global_rf(
 
 std::string RuntimeFilterMergeControllerEntity::debug_string() {
     std::string result = "RuntimeFilterMergeControllerEntity Info:\n";
-    SharedLockGuard guard(_filter_map_mutex);
-    for (const auto& [filter_id, ctx] : _filter_map) {
-        result += fmt::format("filter_id: {}, stage: {}, {}\n", filter_id, 
ctx.stage,
-                              ctx.merger->debug_string());
+    std::vector<std::pair<int, GlobalMergeContext*>> contexts;
+    {
+        SharedLockGuard guard(_filter_map_mutex);
+        contexts.reserve(_filter_map.size());
+        for (auto& [filter_id, ctx] : _filter_map) {
+            contexts.emplace_back(filter_id, &ctx);
+        }
+    }
+    // The caller retains this initialized entity. Its node-based map never 
erases
+    // contexts, so their addresses remain valid without holding the map lock.
+    for (auto [filter_id, ctx] : contexts) {
+        auto snapshot = ctx->snapshot_for_debug();

Review Comment:
   [P2] Release the previous Bloom merger under the query’s memory tracker
   
   If reset replaces a populated Bloom merger after this snapshot is taken, the 
HTTP dump can drop the last reference to it. `FragmentMgr::merge_filter()` 
allocates the cloned Bloom directory with the query attached. 
`BlockBloomFilter::close()` releases it through the current thread’s limiter, 
which is Orphan on the HTTP dump path. The live query keeps the charge for 
freed bytes and can hit its limit in later rounds. A checked BE can also trip 
the orphan-memory assertion. Keep the query limiter active through snapshot 
destruction or capture diagnostic values without retaining the filter buffer.



##########
be/test/runtime/fragment_mgr_cross_cluster_cancel_test.cpp:
##########
@@ -287,6 +301,98 @@ TEST_F(FragmentMgrCrossClusterCancelTest, 
RebuildRestoresFragmentExecutingCount)
     EXPECT_EQ(get_fragment_executing_count(), count_before_rebuild);
 }
 
+TEST_F(FragmentMgrCrossClusterCancelTest, DumpPipelineTasksWithGlobalRfReset) {
+    auto* fragment_mgr = _exec_env.fragment_mgr();
+    EXPECT_EQ(fragment_mgr->dump_pipeline_tasks(0),
+              "0 pipeline fragment contexts are still running! 
duration_limit=0\n");
+
+    TUniqueId query_id;
+    query_id.__set_hi(707);
+    query_id.__set_lo(808);
+    constexpr int fragment_id = 1;
+    constexpr int filter_id = 7;
+    TNetworkAddress coord;
+    coord.hostname = "127.0.0.1";
+    coord.port = 9030;
+    auto query_ctx = QueryContext::create(query_id, &_exec_env, 
_make_min_query_options(789), coord,
+                                          true, coord, 
QuerySource::INTERNAL_FRONTEND);
+    SCOPED_ATTACH_TASK(query_ctx->resource_ctx());
+    auto handler = std::make_shared<RuntimeFilterMergeControllerEntity>();
+    auto rf_params =
+            TRuntimeFilterParamsBuilder()
+                    .add_rid_to_runtime_filter(
+                            filter_id, 
TRuntimeFilterDescBuilder(filter_id).set_mode(false).build())
+                    .add_runtime_filter_builder_num(filter_id, 3)
+                    .add_rid_to_target_paramv2(filter_id)
+                    .build();
+    ASSERT_TRUE(handler->init(query_ctx, rf_params).ok());
+    query_ctx->set_merge_controller_handler(handler);
+    TPipelineFragmentParams params;
+    params.__set_fragment_id(fragment_id);
+    params.__set_need_notify_close(false);
+    auto pfc = std::make_shared<PipelineFragmentContext>(query_id, params, 
query_ctx, &_exec_env,
+                                                         
FragmentMgr::FinishCallback());
+    const auto key = std::make_pair(query_id, fragment_id);
+    // This diagnostic-only PFC has no tasks or execution-count increment. 
Erase directly
+    // rather than calling remove_pipeline_context(), which decrements that 
count.
+    fragment_mgr->_pipeline_map.insert(key, pfc);
+    Defer cleanup([&] { fragment_mgr->_pipeline_map.erase(key); });
+
+    const std::string query_heading = "QueryId: " + print_id(query_id);
+    auto initial_dump = fragment_mgr->dump_pipeline_tasks(0);
+    EXPECT_NE(initial_dump.find(query_heading), std::string::npos);
+    EXPECT_NE(initial_dump.find("global_runtime_filter_mgr:"), 
std::string::npos);
+    EXPECT_NE(initial_dump.find("RuntimeFilterMergeControllerEntity Info:"), 
std::string::npos);
+    EXPECT_NE(initial_dump.find("filter_id: 7, stage: 0, Merger:"), 
std::string::npos);
+    EXPECT_NE(initial_dump.find("No.0 (elapse_second="), std::string::npos);
+    EXPECT_NE(initial_dump.find("PipelineFragmentContext Info:"), 
std::string::npos);
+    auto filtered_dump = fragment_mgr->dump_pipeline_tasks(3600);
+    EXPECT_EQ(filtered_dump.find(query_heading), std::string::npos);
+    EXPECT_EQ(filtered_dump.find("PipelineFragmentContext Info:"), 
std::string::npos);
+
+    google::protobuf::RepeatedField<int32_t> filter_ids;
+    filter_ids.Add(filter_id);
+    constexpr int rounds = 32;
+    std::barrier rendezvous(2);
+    std::vector<Status> reset_results(rounds);
+    std::vector<std::string> dumps(rounds);
+    std::thread resetter([&] {
+        SCOPED_ATTACH_TASK(query_ctx->resource_ctx());
+        for (int round = 0; round < rounds; ++round) {
+            rendezvous.arrive_and_wait();
+            reset_results[round] = query_ctx->reset_global_rf(filter_ids);
+            rendezvous.arrive_and_wait();
+        }
+    });
+    std::thread dumper([&] {

Review Comment:
   [P3] Cover fragment removal while RF diagnostics are blocked
   
   This fixture keeps a strong reference to the fragment across both joins and 
erases it afterward. The stage assertions could still pass if the dump held the 
shard lock or retained the fragment during the global RF wait. Add a 
synchronized case that pauses global RF diagnostics, removes the fragment, and 
checks that the `WAIT_FOR_DESTROY` notification fires before diagnostics resume.



-- 
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]

Reply via email to