yangzhg commented on code in PR #11959:
URL: https://github.com/apache/doris/pull/11959#discussion_r952228075


##########
be/src/io/cache/file_cache_manager.cpp:
##########
@@ -29,18 +32,110 @@ void FileCacheManager::add_file_cache(const Path& 
cache_path, FileCachePtr file_
 }
 
 void FileCacheManager::remove_file_cache(const Path& cache_path) {
-    std::lock_guard<std::shared_mutex> wrlock(_cache_map_lock);
-    _file_cache_map.erase(cache_path.native());
+    bool cache_path_exist = false;
+    {
+        std::shared_lock<std::shared_mutex> rdlock(_cache_map_lock);
+        if (_file_cache_map.find(cache_path) == _file_cache_map.end()) {
+            bool cache_dir_exist = false;
+            if (global_local_filesystem()->exists(cache_path, 
&cache_dir_exist).ok()) {
+                if (cache_dir_exist) {
+                    Status st = 
global_local_filesystem()->delete_directory(cache_path);
+                    if (!st.ok()) {
+                        LOG(WARNING) << st.to_string();
+                    }
+                }
+            }
+        } else {
+            cache_path_exist = true;
+            _file_cache_map.find(cache_path)->second->clean_all_cache();
+        }
+    }
+    if (cache_path_exist) {
+        std::lock_guard<std::shared_mutex> wrlock(_cache_map_lock);
+        _file_cache_map.erase(cache_path.native());
+    }
 }
 
 void FileCacheManager::clean_timeout_caches() {
     std::shared_lock<std::shared_mutex> rdlock(_cache_map_lock);
     for (std::map<std::string, FileCachePtr>::const_iterator iter = 
_file_cache_map.cbegin();
          iter != _file_cache_map.cend(); ++iter) {
+        if (iter->second == nullptr) {
+            continue;
+        }
         iter->second->clean_timeout_cache();
     }
 }
 
+void FileCacheManager::clean_timeout_file_not_in_mem(const Path& cache_path) {
+    std::shared_lock<std::shared_mutex> rdlock(_cache_map_lock);
+    // Deal with caches not in _file_cache_map
+    if (_file_cache_map.find(cache_path.native()) == _file_cache_map.end()) {
+        std::vector<Path> cache_file_names;
+        if (io::global_local_filesystem()->list(cache_path, 
&cache_file_names).ok()) {
+            std::map<std::string, bool> cache_names;
+            std::list<std::string> done_names;
+            for (Path cache_file_name : cache_file_names) {
+                std::string filename = cache_file_name.native();
+                if (filename.find("_DONE") == std::string::npos) {
+                    cache_names[filename] = true;
+                    continue;
+                }
+                done_names.push_back(filename);
+                std::string done_file_path = (cache_path / filename).native();
+                time_t m_time;
+                if (!FileUtils::mtime(done_file_path, &m_time).ok()) {
+                    continue;
+                }
+                if (time(nullptr) - m_time < 
config::file_cache_alive_time_sec) {

Review Comment:
   mv time(nullptr) out of for block 



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