AshinGau commented on code in PR #16767:
URL: https://github.com/apache/doris/pull/16767#discussion_r1106726945


##########
be/src/io/cache/block/block_lru_file_cache.cpp:
##########
@@ -634,63 +637,113 @@ void LRUFileCache::remove(const Key& key, bool 
is_persistent, size_t offset,
 }
 
 void LRUFileCache::load_cache_info_into_memory(std::lock_guard<std::mutex>& 
cache_lock) {
+    /// version 1.0: cache_base_path / key / offset
+    /// version 2.0: cache_base_path / key_prefix / key / offset
+    if (read_file_cache_version() != FILE_CACHE_VERSION) {
+        // move directories format as version 2.0
+        fs::directory_iterator key_it {_cache_base_path};
+        for (; key_it != fs::directory_iterator(); ++key_it) {
+            if (key_it->is_directory()) {
+                std::string cache_key = key_it->path().filename().native();
+                if (cache_key.size() > KEY_PREFIX_LENGTH) {
+                    std::string key_prefix =
+                            fs::path(_cache_base_path) / cache_key.substr(0, 
KEY_PREFIX_LENGTH);
+                    if (!fs::exists(key_prefix)) {
+                        std::error_code ec;
+                        fs::create_directories(key_prefix, ec);
+                        if (ec) {
+                            LOG(WARNING) << "Failed to create new version 
cached directory: "
+                                         << ec.message();
+                            continue;
+                        }
+                    }
+                    std::error_code ec;
+                    std::filesystem::rename(key_it->path(), key_prefix / 
cache_key, ec);
+                    if (ec) {
+                        LOG(WARNING)
+                                << "Failed to move old version cached 
directory: " << ec.message();

Review Comment:
   Dirty data has been removed in the following process 
`key_prefix_it->path().filename().native().size() != KEY_PREFIX_LENGTH`



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