[improvement](task exec context) add parent class HasTaskExecutionCtx to own the task ctx (#29388)

---------

Co-authored-by: yiguolei <yiguolei@gmail.com>
This commit is contained in:
yiguolei
2024-01-02 15:28:27 +08:00
committed by GitHub
parent 4581618b09
commit 2ed122b787
5 changed files with 34 additions and 15 deletions

View File

@ -21,11 +21,35 @@
namespace doris {
// This class act as a super class of all context like things
// This class act as a super class of all context like things such as
// plan fragment executor or pipelinefragmentcontext or pipelinexfragmentcontext
class TaskExecutionContext : public std::enable_shared_from_this<TaskExecutionContext> {
public:
TaskExecutionContext() = default;
virtual ~TaskExecutionContext() = default;
};
using TaskExecutionContextSPtr = std::shared_ptr<TaskExecutionContext>;
// Task Execution Context maybe plan fragment executor or pipelinefragmentcontext or pipelinexfragmentcontext
// In multi thread scenario, the object is created in main thread (such as FragmentExecThread), but the object
// maybe used in other thread(such as scanner thread, brpc->sender queue). If the main thread stopped and destroy
// the object, then the other thread may core. So the other thread must lock the context to ensure the object exists.
struct HasTaskExecutionCtx {
using Weak = typename TaskExecutionContextSPtr::weak_type;
HasTaskExecutionCtx(TaskExecutionContextSPtr task_exec_ctx) : task_exec_ctx_(task_exec_ctx) {}
// Init task ctx from state, the state has to own a method named get_task_execution_context()
// like runtime state
template <typename T>
HasTaskExecutionCtx(T* state) : task_exec_ctx_(state->get_task_execution_context()) {}
public:
inline TaskExecutionContextSPtr task_exec_ctx() const { return task_exec_ctx_.lock(); }
private:
Weak task_exec_ctx_;
};
} // namespace doris