xinyiZzz commented on a change in pull request #8476: URL: https://github.com/apache/incubator-doris/pull/8476#discussion_r828866893
########## File path: be/src/runtime/thread_context.h ########## @@ -50,27 +56,65 @@ class ThreadContext { }; public: - ThreadContext() : _thread_id(std::this_thread::get_id()), _type(TaskType::UNKNOWN) {} + ThreadContext() : _thread_id(std::this_thread::get_id()), _type(TaskType::UNKNOWN) { + _thread_mem_tracker_mgr.reset(new ThreadMemTrackerMgr()); + } void attach(const TaskType& type, const std::string& task_id, - const TUniqueId& fragment_instance_id) { + const TUniqueId& fragment_instance_id, + const std::shared_ptr<MemTracker>& mem_tracker) { DCHECK(_type == TaskType::UNKNOWN && _task_id == ""); _type = type; _task_id = task_id; _fragment_instance_id = fragment_instance_id; + _thread_mem_tracker_mgr->attach_task(task_type_string(_type), task_id, fragment_instance_id, + mem_tracker); } void detach() { _type = TaskType::UNKNOWN; _task_id = ""; _fragment_instance_id = TUniqueId(); + _thread_mem_tracker_mgr->detach_task(); } - const std::string type() const; const std::string& task_id() const { return _task_id; } const std::thread::id& thread_id() const { return _thread_id; } const TUniqueId& fragment_instance_id() const { return _fragment_instance_id; } + inline static const std::string task_type_string(ThreadContext::TaskType type) { + switch (type) { + case ThreadContext::TaskType::QUERY: + return "QUERY"; + case ThreadContext::TaskType::LOAD: + return "LOAD"; + case ThreadContext::TaskType::COMPACTION: + return "COMPACTION"; + default: + return "UNKNOWN"; + } + } + + void consume_mem(int64_t size) { + if (thread_mem_tracker_mgr_init == true) { Review comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org