[bugfix](deadlock) fix dead lock in cancel fragment (#33181)

Co-authored-by: yiguolei <yiguolei@gmail.com>
This commit is contained in:
yiguolei
2024-04-03 13:40:07 +08:00
committed by yiguolei
parent 4d18fc1e4c
commit 7675383c40
8 changed files with 57 additions and 54 deletions

View File

@ -157,12 +157,14 @@ void QueryContext::set_execution_dependency_ready() {
_execution_dependency->set_ready();
}
bool QueryContext::cancel(bool v, std::string msg, Status new_status, int fragment_id) {
if (_is_cancelled) {
return false;
void QueryContext::cancel(std::string msg, Status new_status, int fragment_id) {
// Just for CAS need a left value
bool false_cancel = false;
if (!_is_cancelled.compare_exchange_strong(false_cancel, true)) {
return;
}
DCHECK(!false_cancel && _is_cancelled);
set_exec_status(new_status);
_is_cancelled.store(v);
set_ready_to_execute(true);
std::vector<std::weak_ptr<pipeline::PipelineFragmentContext>> ctx_to_cancel;
@ -175,12 +177,14 @@ bool QueryContext::cancel(bool v, std::string msg, Status new_status, int fragme
ctx_to_cancel.push_back(f_context);
}
}
// Must not add lock here. There maybe dead lock because it will call fragment
// ctx cancel and fragment ctx will call query ctx cancel.
for (auto& f_context : ctx_to_cancel) {
if (auto pipeline_ctx = f_context.lock()) {
pipeline_ctx->cancel(PPlanFragmentCancelReason::INTERNAL_ERROR, msg);
}
}
return true;
return;
}
void QueryContext::cancel_all_pipeline_context(const PPlanFragmentCancelReason& reason,