From de251b0cba0e2b4278b5dbcc2a3c71412bf533b7 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 15 Oct 2024 11:40:28 +0800 Subject: [PATCH] [Improvement](minor) Reduce locking scope --- be/src/runtime/fragment_mgr.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/be/src/runtime/fragment_mgr.cpp b/be/src/runtime/fragment_mgr.cpp index acf622b4196d2f..b4ecf2c9d70f2a 100644 --- a/be/src/runtime/fragment_mgr.cpp +++ b/be/src/runtime/fragment_mgr.cpp @@ -698,18 +698,22 @@ Status FragmentMgr::exec_plan_fragment(const TPipelineFragmentParams& params, } Status FragmentMgr::start_query_execution(const PExecPlanFragmentStartRequest* request) { - std::lock_guard lock(_lock); - TUniqueId query_id; - query_id.__set_hi(request->query_id().hi()); - query_id.__set_lo(request->query_id().lo()); - auto search = _query_ctx_map.find(query_id); - if (search == _query_ctx_map.end()) { - return Status::InternalError( - "Failed to get query fragments context. Query may be " - "timeout or be cancelled. host: {}", - BackendOptions::get_localhost()); + std::shared_ptr q_ctx = nullptr; + { + std::lock_guard lock(_lock); + TUniqueId query_id; + query_id.__set_hi(request->query_id().hi()); + query_id.__set_lo(request->query_id().lo()); + auto search = _query_ctx_map.find(query_id); + if (search == _query_ctx_map.end()) { + return Status::InternalError( + "Failed to get query fragments context. Query may be " + "timeout or be cancelled. host: {}", + BackendOptions::get_localhost()); + } + q_ctx = search->second; } - search->second->set_ready_to_execute(false); + q_ctx->set_ready_to_execute(false); return Status::OK(); }