@@ -320,7 +320,7 @@ Status PipelineFragmentContext::prepare(ThreadPool* thread_pool) {
320320
321321 auto * fragment_context = this ;
322322
323- if (!_need_notify_close && _params.query_options .__isset .is_report_success ) {
323+ if (_params.query_options .__isset .is_report_success ) {
324324 fragment_context->set_is_report_success (_params.query_options .is_report_success );
325325 }
326326
@@ -1793,10 +1793,16 @@ void PipelineFragmentContext::_close_fragment_instance() {
17931793 }
17941794 Defer defer_op {[&]() {
17951795 _is_fragment_instance_closed = true ;
1796- _close_cv .notify_all ();
1796+ _notify_cv .notify_all ();
17971797 }};
17981798 _fragment_level_profile->total_time_counter ()->update (_fragment_watcher.elapsed_time ());
1799- static_cast <void >(send_report (true ));
1799+ if (!_need_notify_close) {
1800+ auto st = send_report (true );
1801+ if (!st) {
1802+ LOG (WARNING) << fmt::format (" Failed to send report for query {}, fragment {}: {}" ,
1803+ print_id (_query_id), _fragment_id, st.to_string ());
1804+ }
1805+ }
18001806 // Print profile content in info log is a tempoeray solution for stream load and external_connector.
18011807 // Since stream load does not have someting like coordinator on FE, so
18021808 // backend can not report profile to FE, ant its profile can not be shown
@@ -1971,8 +1977,11 @@ std::vector<PipelineTask*> PipelineFragmentContext::get_revocable_tasks() const
19711977std::string PipelineFragmentContext::debug_string () {
19721978 std::lock_guard<std::mutex> l (_task_mutex);
19731979 fmt::memory_buffer debug_string_buffer;
1974- fmt::format_to (debug_string_buffer, " PipelineFragmentContext Info:\n need_notify_close: {}\n " ,
1975- _need_notify_close);
1980+ fmt::format_to (debug_string_buffer,
1981+ " PipelineFragmentContext Info: _closed_tasks={}, _total_tasks={}, "
1982+ " need_notify_close={}, has_task_execution_ctx_ref_count={}\n " ,
1983+ _closed_tasks, _total_tasks, _need_notify_close,
1984+ _has_task_execution_ctx_ref_count);
19761985 for (size_t j = 0 ; j < _tasks.size (); j++) {
19771986 fmt::format_to (debug_string_buffer, " Tasks in instance {}:\n " , j);
19781987 for (size_t i = 0 ; i < _tasks[j].size (); i++) {
@@ -2057,10 +2066,17 @@ Status PipelineFragmentContext::wait_close(bool close) {
20572066
20582067 {
20592068 std::unique_lock<std::mutex> lock (_task_mutex);
2060- _close_cv.wait (lock, [this ] { return _is_fragment_instance_closed.load (); });
2069+ _notify_cv.wait (lock, [this ] {
2070+ return _is_fragment_instance_closed.load () && !_has_task_execution_ctx_ref_count;
2071+ });
20612072 }
20622073
20632074 if (close) {
2075+ auto st = send_report (true );
2076+ if (!st) {
2077+ LOG (WARNING) << fmt::format (" Failed to send report for query {}, fragment {}: {}" ,
2078+ print_id (_query_id), _fragment_id, st.to_string ());
2079+ }
20642080 _exec_env->fragment_mgr ()->remove_pipeline_context ({_query_id, _fragment_id});
20652081 }
20662082 return Status::OK ();
0 commit comments