github-actions[bot] commented on code in PR #32346:
URL: https://github.com/apache/doris/pull/32346#discussion_r1528001157


##########
be/src/runtime/query_context.h:
##########
@@ -107,6 +112,11 @@ class QueryContext {
     void set_ready_to_execute(bool is_cancelled);
 
     [[nodiscard]] bool is_cancelled() const { return _is_cancelled.load(); }
+
+    using ForEachFunc = std::function<void(const int, 
PipelineFragmentContextWrapper&)>;
+    void for_each_pipeline_context(ForEachFunc for_each_func);
+    using MaphFunc = std::function<void(PipelineFragmentContextWrapper&)>;
+    Status map_pipeline_context(MaphFunc map_func, const int fragment_id);

Review Comment:
   warning: parameter 'fragment_id' is const-qualified in the function 
declaration; const-qualification of parameters only has an effect in function 
definitions [readability-avoid-const-params-in-decls]
   
   ```suggestion
       Status map_pipeline_context(MaphFunc map_func, int fragment_id);
   ```
   



##########
be/src/runtime/query_context.cpp:
##########
@@ -161,18 +165,44 @@ bool QueryContext::cancel(bool v, std::string msg, Status 
new_status, int fragme
     _is_cancelled.store(v);
 
     set_ready_to_execute(true);
-    {
-        std::lock_guard<std::mutex> plock(pipeline_lock);
-        for (auto& ctx : fragment_id_to_pipeline_ctx) {
-            if (fragment_id == ctx.first) {
-                continue;
-            }
-            ctx.second->cancel(PPlanFragmentCancelReason::INTERNAL_ERROR, msg);
+    for_each_pipeline_context([&](const int f_id, 
PipelineFragmentContextWrapper& ctx) -> void {
+        if (fragment_id == f_id) {
+            return;
         }
-    }
+        if (!ctx.valid) {
+            return;
+        }
+        if (auto pipeline_ctx = ctx.pip_ctx.lock()) {
+            pipeline_ctx->cancel(PPlanFragmentCancelReason::INTERNAL_ERROR, 
msg);
+        }
+    });
     return true;
 }
 
+void QueryContext::for_each_pipeline_context(ForEachFunc for_each_func) {
+    std::lock_guard<std::mutex> lock(_pipeline_map_write_lock);
+    for (auto& [f_id, f_context] : _fragment_id_to_pipeline_ctx) {
+        for_each_func(f_id, f_context);
+    }
+}
+
+Status QueryContext::map_pipeline_context(MaphFunc map_func, const int 
fragment_id) {

Review Comment:
   warning: method 'map_pipeline_context' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/runtime/query_context.h:118:
   ```diff
   -     Status map_pipeline_context(MaphFunc map_func, const int fragment_id);
   +     static Status map_pipeline_context(MaphFunc map_func, const int 
fragment_id);
   ```
   



##########
be/src/runtime/fragment_mgr.cpp:
##########
@@ -773,6 +775,7 @@ std::string FragmentMgr::dump_pipeline_tasks() {
 }
 
 Status FragmentMgr::exec_plan_fragment(const TPipelineFragmentParams& params,

Review Comment:
   warning: function 'exec_plan_fragment' has cognitive complexity of 91 
(threshold 50) [readability-function-cognitive-complexity]
   ```cpp
   Status FragmentMgr::exec_plan_fragment(const TPipelineFragmentParams& params,
                       ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/runtime/fragment_mgr.cpp:786:** +1
   ```cpp
       const bool enable_pipeline_x = 
params.query_options.__isset.enable_pipeline_x_engine &&
                                                                                
            ^
   ```
   **be/src/runtime/fragment_mgr.cpp:788:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       if (enable_pipeline_x) {
       ^
   ```
   **be/src/runtime/fragment_mgr.cpp:800:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
               if (!prepare_st.ok()) {
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:808:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           for (size_t i = 0; i < params.local_params.size(); i++) {
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:810:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               RETURN_IF_ERROR(_runtimefilter_controller.add_entity(
               ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/runtime/fragment_mgr.cpp:810:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
               RETURN_IF_ERROR(_runtimefilter_controller.add_entity(
               ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:813:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (!i && handler) {
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:813:** +1
   ```cpp
               if (!i && handler) {
                      ^
   ```
   **be/src/runtime/fragment_mgr.cpp:820:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
                   if (iter != _pipeline_map.end()) {
                   ^
   ```
   **be/src/runtime/fragment_mgr.cpp:827:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (!params.__isset.need_wait_execution_trigger ||
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:827:** +1
   ```cpp
               if (!params.__isset.need_wait_execution_trigger ||
                                                               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:842:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(query_ctx->map_pipeline_context(
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/runtime/fragment_mgr.cpp:842:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           RETURN_IF_ERROR(query_ctx->map_pipeline_context(
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:849:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(context->submit());
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/runtime/fragment_mgr.cpp:849:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           RETURN_IF_ERROR(context->submit());
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:851:** +1, nesting level increased to 1
   ```cpp
       } else {
         ^
   ```
   **be/src/runtime/fragment_mgr.cpp:852:** nesting level increased to 2
   ```cpp
           auto pre_and_submit = [&](int i) {
                                 ^
   ```
   **be/src/runtime/fragment_mgr.cpp:859:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
                   if (iter != _pipeline_map.end()) {
                   ^
   ```
   **be/src/runtime/fragment_mgr.cpp:867:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (!params.__isset.need_wait_execution_trigger ||
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:867:** +1
   ```cpp
               if (!params.__isset.need_wait_execution_trigger ||
                                                               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:882:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
                   if (!prepare_st.ok()) {
                   ^
   ```
   **be/src/runtime/fragment_mgr.cpp:892:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               RETURN_IF_ERROR(_runtimefilter_controller.add_entity(
               ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/runtime/fragment_mgr.cpp:892:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
               RETURN_IF_ERROR(_runtimefilter_controller.add_entity(
               ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:895:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (i == 0 && handler) {
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:895:** +1
   ```cpp
               if (i == 0 && handler) {
                          ^
   ```
   **be/src/runtime/fragment_mgr.cpp:910:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (local_params.__isset.runtime_filter_params) {
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:911:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (local_params.__isset.runtime_filter_params) {
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:916:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (local_params.__isset.topn_filter_source_node_ids) {
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:918:** +1, nesting level increased to 2
   ```cpp
           } else {
             ^
   ```
   **be/src/runtime/fragment_mgr.cpp:922:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (target_size > 1) {
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:928:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               for (size_t i = 0; i < target_size; i++) {
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:929:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   RETURN_IF_ERROR(_thread_pool->submit_func([&, i]() {
                   ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/runtime/fragment_mgr.cpp:929:** +5, including nesting penalty of 4, 
nesting level increased to 5
   ```cpp
                   RETURN_IF_ERROR(_thread_pool->submit_func([&, i]() {
                   ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/runtime/fragment_mgr.cpp:940:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (prepare_done != target_size) {
               ^
   ```
   **be/src/runtime/fragment_mgr.cpp:943:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   for (size_t i = 0; i < target_size; i++) {
                   ^
   ```
   **be/src/runtime/fragment_mgr.cpp:944:** +5, including nesting penalty of 4, 
nesting level increased to 5
   ```cpp
                       if (!prepare_status[i].ok()) {
                       ^
   ```
   **be/src/runtime/fragment_mgr.cpp:950:** +1, nesting level increased to 2
   ```cpp
           } else {
             ^
   ```
   
   </details>
   



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to