[refactor](scanner) use weak ptr to lock task execution context to avoid core in scanner dctor (#28493)

using weak ptr as a lock between fragment execute thread and scanner thread, to solve the core problem in scanner's dctor to access scannode's profile.
This commit is contained in:
yiguolei
2023-12-18 14:09:32 +08:00
committed by GitHub
parent 4bcde57775
commit 73f7b61019
23 changed files with 241 additions and 153 deletions

View File

@ -22,6 +22,14 @@
namespace doris {
class DelayReleaseToken : public Runnable {
public:
DelayReleaseToken(std::unique_ptr<ThreadPoolToken>&& token) { token_ = std::move(token); }
~DelayReleaseToken() override = default;
void run() override {}
std::unique_ptr<ThreadPoolToken> token_;
};
QueryContext::QueryContext(TUniqueId query_id, int total_fragment_num, ExecEnv* exec_env,
const TQueryOptions& query_options)
: fragment_num(total_fragment_num),
@ -55,6 +63,14 @@ QueryContext::~QueryContext() {
}
LOG_INFO("Query {} deconstructed, {}", print_id(_query_id), mem_tracker_msg);
// Not release the the thread token in query context's dector method, because the query
// conext may be dectored in the thread token it self. It is very dangerous and may core.
// And also thread token need shutdown, it may take some time, may cause the thread that
// release the token hang, the thread maybe a pipeline task scheduler thread.
if (_thread_token) {
static_cast<void>(ExecEnv::GetInstance()->lazy_release_obj_pool()->submit(
std::make_shared<DelayReleaseToken>(std::move(_thread_token))));
}
}
void QueryContext::set_ready_to_execute(bool is_cancelled) {