-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improvement] Optimize send fragment logic to reduce send fragment timeout error #9720
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f2971a
pass
morningman 969000f
code format
morningman 9f4a1e0
add log
morningman 593560d
add log
morningman b6d5d68
fix ut
morningman 2dd009d
1
morningman a98a82e
fix ut
morningman d606a3e
add missing service
morningman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,8 @@ class FragmentExecState { | |
void set_pipe(std::shared_ptr<StreamLoadPipe> pipe) { _pipe = pipe; } | ||
std::shared_ptr<StreamLoadPipe> get_pipe() const { return _pipe; } | ||
|
||
void set_need_wait_execution_trigger() { _need_wait_execution_trigger = true; } | ||
|
||
private: | ||
void coordinator_callback(const Status& status, RuntimeProfile* profile, bool done); | ||
|
||
|
@@ -171,6 +173,9 @@ class FragmentExecState { | |
std::shared_ptr<RuntimeFilterMergeControllerEntity> _merge_controller_handler; | ||
// The pipe for data transfering, such as insert. | ||
std::shared_ptr<StreamLoadPipe> _pipe; | ||
|
||
// If set the true, this plan fragment will be executed only after FE send execution start rpc. | ||
bool _need_wait_execution_trigger = false; | ||
}; | ||
|
||
FragmentExecState::FragmentExecState(const TUniqueId& query_id, | ||
|
@@ -225,6 +230,11 @@ Status FragmentExecState::prepare(const TExecPlanFragmentParams& params) { | |
} | ||
|
||
Status FragmentExecState::execute() { | ||
if (_need_wait_execution_trigger) { | ||
// if _need_wait_execution_trigger is true, which means this instance | ||
// is prepared but need to wait for the signal to do the rest execution. | ||
_fragments_ctx->wait_for_start(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a timeout here, avoid occupy the running thread too much time during exceptions. |
||
} | ||
int64_t duration_ns = 0; | ||
{ | ||
SCOPED_RAW_TIMER(&duration_ns); | ||
|
@@ -527,6 +537,22 @@ Status FragmentMgr::exec_plan_fragment(const TExecPlanFragmentParams& params) { | |
} | ||
} | ||
|
||
Status FragmentMgr::start_query_execution(const PExecPlanFragmentStartRequest* request) { | ||
std::lock_guard<std::mutex> lock(_lock); | ||
TUniqueId query_id; | ||
query_id.__set_hi(request->query_id().hi()); | ||
query_id.__set_lo(request->query_id().lo()); | ||
auto search = _fragments_ctx_map.find(query_id); | ||
if (search == _fragments_ctx_map.end()) { | ||
return Status::InternalError( | ||
strings::Substitute("Failed to get query fragments context. Query may be " | ||
"timeout or be cancelled. host: ", | ||
BackendOptions::get_localhost())); | ||
} | ||
search->second->set_ready_to_execute(); | ||
return Status::OK(); | ||
} | ||
|
||
void FragmentMgr::set_pipe(const TUniqueId& fragment_instance_id, | ||
std::shared_ptr<StreamLoadPipe> pipe) { | ||
{ | ||
|
@@ -562,65 +588,62 @@ Status FragmentMgr::exec_plan_fragment(const TExecPlanFragmentParams& params, Fi | |
} | ||
|
||
std::shared_ptr<FragmentExecState> exec_state; | ||
if (!params.__isset.is_simplified_param) { | ||
// This is an old version params, all @Common components is set in TExecPlanFragmentParams. | ||
exec_state.reset(new FragmentExecState(params.params.query_id, | ||
params.params.fragment_instance_id, | ||
params.backend_num, _exec_env, params.coord)); | ||
std::shared_ptr<QueryFragmentsCtx> fragments_ctx; | ||
if (params.is_simplified_param) { | ||
// Get common components from _fragments_ctx_map | ||
std::lock_guard<std::mutex> lock(_lock); | ||
auto search = _fragments_ctx_map.find(params.params.query_id); | ||
if (search == _fragments_ctx_map.end()) { | ||
return Status::InternalError( | ||
strings::Substitute("Failed to get query fragments context. Query may be " | ||
"timeout or be cancelled. host: ", | ||
BackendOptions::get_localhost())); | ||
} | ||
fragments_ctx = search->second; | ||
} else { | ||
std::shared_ptr<QueryFragmentsCtx> fragments_ctx; | ||
if (params.is_simplified_param) { | ||
// Get common components from _fragments_ctx_map | ||
std::lock_guard<std::mutex> lock(_lock); | ||
auto search = _fragments_ctx_map.find(params.params.query_id); | ||
if (search == _fragments_ctx_map.end()) { | ||
return Status::InternalError( | ||
strings::Substitute("Failed to get query fragments context. Query may be " | ||
"timeout or be cancelled. host: ", | ||
BackendOptions::get_localhost())); | ||
} | ||
fragments_ctx = search->second; | ||
} else { | ||
// This may be a first fragment request of the query. | ||
// Create the query fragments context. | ||
fragments_ctx.reset(new QueryFragmentsCtx(params.fragment_num_on_host, _exec_env)); | ||
fragments_ctx->query_id = params.params.query_id; | ||
RETURN_IF_ERROR(DescriptorTbl::create(&(fragments_ctx->obj_pool), params.desc_tbl, | ||
&(fragments_ctx->desc_tbl))); | ||
fragments_ctx->coord_addr = params.coord; | ||
fragments_ctx->query_globals = params.query_globals; | ||
|
||
if (params.__isset.resource_info) { | ||
fragments_ctx->user = params.resource_info.user; | ||
fragments_ctx->group = params.resource_info.group; | ||
fragments_ctx->set_rsc_info = true; | ||
} | ||
// This may be a first fragment request of the query. | ||
// Create the query fragments context. | ||
fragments_ctx.reset(new QueryFragmentsCtx(params.fragment_num_on_host, _exec_env)); | ||
fragments_ctx->query_id = params.params.query_id; | ||
RETURN_IF_ERROR(DescriptorTbl::create(&(fragments_ctx->obj_pool), params.desc_tbl, | ||
&(fragments_ctx->desc_tbl))); | ||
fragments_ctx->coord_addr = params.coord; | ||
fragments_ctx->query_globals = params.query_globals; | ||
|
||
if (params.__isset.query_options) { | ||
fragments_ctx->timeout_second = params.query_options.query_timeout; | ||
if (params.query_options.__isset.resource_limit) { | ||
fragments_ctx->set_thread_token(params.query_options.resource_limit.cpu_limit); | ||
} | ||
if (params.__isset.resource_info) { | ||
fragments_ctx->user = params.resource_info.user; | ||
fragments_ctx->group = params.resource_info.group; | ||
fragments_ctx->set_rsc_info = true; | ||
} | ||
|
||
if (params.__isset.query_options) { | ||
fragments_ctx->timeout_second = params.query_options.query_timeout; | ||
if (params.query_options.__isset.resource_limit) { | ||
fragments_ctx->set_thread_token(params.query_options.resource_limit.cpu_limit); | ||
} | ||
} | ||
|
||
{ | ||
// Find _fragments_ctx_map again, in case some other request has already | ||
// create the query fragments context. | ||
std::lock_guard<std::mutex> lock(_lock); | ||
auto search = _fragments_ctx_map.find(params.params.query_id); | ||
if (search == _fragments_ctx_map.end()) { | ||
_fragments_ctx_map.insert( | ||
std::make_pair(fragments_ctx->query_id, fragments_ctx)); | ||
} else { | ||
// Already has a query fragmentscontext, use it | ||
fragments_ctx = search->second; | ||
} | ||
{ | ||
// Find _fragments_ctx_map again, in case some other request has already | ||
// create the query fragments context. | ||
std::lock_guard<std::mutex> lock(_lock); | ||
auto search = _fragments_ctx_map.find(params.params.query_id); | ||
if (search == _fragments_ctx_map.end()) { | ||
_fragments_ctx_map.insert(std::make_pair(fragments_ctx->query_id, fragments_ctx)); | ||
} else { | ||
// Already has a query fragmentscontext, use it | ||
fragments_ctx = search->second; | ||
} | ||
} | ||
} | ||
|
||
exec_state.reset(new FragmentExecState(fragments_ctx->query_id, | ||
params.params.fragment_instance_id, | ||
params.backend_num, _exec_env, fragments_ctx)); | ||
exec_state.reset(new FragmentExecState(fragments_ctx->query_id, | ||
params.params.fragment_instance_id, params.backend_num, | ||
_exec_env, fragments_ctx)); | ||
if (params.__isset.need_wait_execution_trigger && params.need_wait_execution_trigger) { | ||
// set need_wait_execution_trigger means this instance will not actually being executed | ||
// until the execPlanFragmentStart RPC trigger to start it. | ||
exec_state->set_need_wait_execution_trigger(); | ||
} | ||
|
||
std::shared_ptr<RuntimeFilterMergeControllerEntity> handler; | ||
|
@@ -672,6 +695,7 @@ void FragmentMgr::cancel_worker() { | |
LOG(INFO) << "FragmentMgr cancel worker start working."; | ||
do { | ||
std::vector<TUniqueId> to_cancel; | ||
std::vector<TUniqueId> to_cancel_queries; | ||
DateTimeValue now = DateTimeValue::local_time(); | ||
{ | ||
std::lock_guard<std::mutex> lock(_lock); | ||
|
@@ -682,6 +706,9 @@ void FragmentMgr::cancel_worker() { | |
} | ||
for (auto it = _fragments_ctx_map.begin(); it != _fragments_ctx_map.end();) { | ||
if (it->second->is_timeout(now)) { | ||
// The execution logic of the instance needs to be notified. | ||
// The execution logic of the instance will eventually cancel the execution plan. | ||
it->second->set_ready_to_execute(); | ||
it = _fragments_ctx_map.erase(it); | ||
} else { | ||
++it; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a timeout here, avoid occupy the running thread too much time during exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need, there is a "timeout checker" on BE side to check and notify this.