HappenLee commented on code in PR #27798:
URL: https://github.com/apache/doris/pull/27798#discussion_r1412775507


##########
be/src/agent/cgroup_cpu_ctl.cpp:
##########
@@ -157,4 +181,45 @@ Status CgroupV1CpuCtl::add_thread_to_cgroup() {
     return CgroupCpuCtl::write_cg_sys_file(_cgroup_v1_cpu_tg_task_file, tid, 
msg, true);
 #endif
 }
+
+Status CgroupV1CpuCtl::delete_unused_cgroup_path(std::set<uint64_t> 
used_wg_ids) {
+    if (!_init_succ) {
+        return Status::InternalError<false>(
+                "cgroup cpu ctl init failed, delete can not be executed");
+    }
+    // 1 get all wg id
+    std::set<std::string> unused_wg_ids;
+    DIR* query_path_dir = opendir(_cgroup_v1_cpu_query_path.c_str());
+    struct dirent* de;
+    while ((de = readdir(query_path_dir))) {
+        std::string f_name = de->d_name;
+        if (!f_name.empty() && std::all_of(f_name.begin(), f_name.end(), 
::isdigit)) {
+            uint64_t id_in_path = std::stoll(f_name);
+            if (used_wg_ids.find(id_in_path) == used_wg_ids.end()) {
+                unused_wg_ids.insert(f_name);
+            }
+        }
+    }
+    closedir(query_path_dir);
+
+    // 2 delete unused cgroup path
+    int failed_count = 0;
+    std::string query_path = _cgroup_v1_cpu_query_path.back() != '/'
+                                     ? _cgroup_v1_cpu_query_path + "/"
+                                     : _cgroup_v1_cpu_query_path;
+    for (std::string unused_wg_id : unused_wg_ids) {

Review Comment:
   `const auto &` to prevent the copy of string.



-- 
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

Reply via email to