diff --git a/be/src/runtime/exec_env.cpp b/be/src/runtime/exec_env.cpp index ab24d7ca192689f..57ba02bc5a34368 100644 --- a/be/src/runtime/exec_env.cpp +++ b/be/src/runtime/exec_env.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -38,7 +39,9 @@ namespace doris { -ExecEnv::ExecEnv() = default; +ExecEnv::ExecEnv(DorisMetrics* doris_metrics) { + _doris_metrics = std::unique_ptr(doris_metrics); +} ExecEnv::~ExecEnv() { destroy(); diff --git a/be/src/runtime/exec_env.h b/be/src/runtime/exec_env.h index 6a670ce3fcd2589..58ee726c16e380e 100644 --- a/be/src/runtime/exec_env.h +++ b/be/src/runtime/exec_env.h @@ -124,6 +124,7 @@ inline bool k_doris_exit = false; // once to properly initialise service state. class ExecEnv { public: + ExecEnv(DorisMetrics* metrics); // Empty destructor because the compiler-generated one requires full // declarations for classes in scoped_ptrs. ~ExecEnv(); @@ -141,8 +142,8 @@ class ExecEnv { /// Returns the first created exec env instance. In a normal doris, this is /// the only instance. In test setups with multiple ExecEnv's per process, /// we return the most recently created instance. - static ExecEnv* GetInstance() { - static ExecEnv s_exec_env; + static ExecEnv* GetInstance(doris::DorisMetrics* metrics = nullptr) { + static ExecEnv s_exec_env(metrics); return &s_exec_env; } diff --git a/be/src/service/doris_main.cpp b/be/src/service/doris_main.cpp index 43a45f67f98d66e..b19f78381be2a02 100644 --- a/be/src/service/doris_main.cpp +++ b/be/src/service/doris_main.cpp @@ -425,9 +425,17 @@ int main(int argc, char** argv) { << doris::config::spill_storage_root_path; exit(-1); } + std::set broken_paths; doris::parse_conf_broken_store_paths(doris::config::broken_storage_path, &broken_paths); + // LocalFileWriter object will be created by check_datapath_rw. + // LocalFileWriter need to access to the DorisMetrics. + std::unique_ptr doris_metrics = + std::unique_ptr(doris::DorisMetrics::create()); + // Create a global instance of ExecEnv with doris_metrics. + doris::ExecEnv::GetInstance(doris_metrics.get()); + auto it = paths.begin(); for (; it != paths.end();) { if (broken_paths.count(it->path) > 0) { diff --git a/be/src/util/doris_metrics.h b/be/src/util/doris_metrics.h index 029d443a01f65bc..156452afeffe23a 100644 --- a/be/src/util/doris_metrics.h +++ b/be/src/util/doris_metrics.h @@ -48,6 +48,9 @@ namespace doris { class DorisMetrics { public: + static DorisMetrics* create() { return new DorisMetrics; } + static DorisMetrics* instance() { return ExecEnv::GetInstance()->doris_metrics(); } + IntCounter* fragment_requests_total = nullptr; IntCounter* fragment_request_duration_us = nullptr; IntCounter* query_scan_bytes = nullptr; @@ -245,10 +248,6 @@ class DorisMetrics { IntAtomicCounter* scanner_cnt = nullptr; IntAtomicCounter* scanner_task_cnt = nullptr; - static DorisMetrics* create() { return new DorisMetrics; } - - static DorisMetrics* instance() { return ExecEnv::GetInstance()->doris_metrics(); } - // not thread-safe, call before calling metrics void initialize( bool init_system_metrics = false,