diff --git a/be/src/vec/exec/scan/scanner_scheduler.cpp b/be/src/vec/exec/scan/scanner_scheduler.cpp index f3e92619b726aba..15c76fc1ccd00ae 100644 --- a/be/src/vec/exec/scan/scanner_scheduler.cpp +++ b/be/src/vec/exec/scan/scanner_scheduler.cpp @@ -392,6 +392,12 @@ SimplifiedScanScheduler::SimplifiedScanScheduler(std::string sched_name, CgroupC INT_GAUGE_METRIC_REGISTER(_metric_entity, scan_scheduler_max_thread_number); } +SimplifiedScanScheduler::~SimplifiedScanScheduler() { + stop(); + LOG(INFO) << "Scanner sche " << _sched_name << " shutdown"; + DorisMetrics::instance()->metric_registry()->deregister_entity(_metric_entity); +} + Status SimplifiedScanScheduler::start(int max_thread_num, int min_thread_num, int queue_size) { RETURN_IF_ERROR(ThreadPoolBuilder(_sched_name) .set_min_threads(min_thread_num) @@ -401,10 +407,12 @@ Status SimplifiedScanScheduler::start(int max_thread_num, int min_thread_num, in .build(&_scan_thread_pool)); _metric_entity->register_hook("update", [this]() { - this->scan_scheduler_running_tasks->set_value(_scan_thread_pool->num_active_threads()); - this->scan_scheduler_queue_size->set_value(_scan_thread_pool->get_queue_size()); - this->scan_scheduler_queue_capacity->set_value(_scan_thread_pool->get_max_queue_size()); - this->scan_scheduler_max_thread_number->set_value(_scan_thread_pool->max_threads()); + if (_scan_thread_pool != nullptr) { + this->scan_scheduler_running_tasks->set_value(_scan_thread_pool->num_active_threads()); + this->scan_scheduler_queue_size->set_value(_scan_thread_pool->get_queue_size()); + this->scan_scheduler_queue_capacity->set_value(_scan_thread_pool->get_max_queue_size()); + this->scan_scheduler_max_thread_number->set_value(_scan_thread_pool->max_threads()); + } }); return Status::OK(); diff --git a/be/src/vec/exec/scan/scanner_scheduler.h b/be/src/vec/exec/scan/scanner_scheduler.h index 30bea375df33210..7e6b951d6c45f5b 100644 --- a/be/src/vec/exec/scan/scanner_scheduler.h +++ b/be/src/vec/exec/scan/scanner_scheduler.h @@ -117,10 +117,7 @@ class SimplifiedScanScheduler { public: SimplifiedScanScheduler(std::string sched_name, CgroupCpuCtl* cgroup_cpu_ctl); - ~SimplifiedScanScheduler() { - stop(); - LOG(INFO) << "Scanner sche " << _sched_name << " shutdown"; - } + ~SimplifiedScanScheduler(); void stop() { _is_stop.store(true);