gavinchou commented on code in PR #37312:
URL: https://github.com/apache/doris/pull/37312#discussion_r1665722197


##########
be/src/io/cache/block_file_cache.cpp:
##########
@@ -796,6 +817,58 @@ bool BlockFileCache::try_reserve_for_ttl(size_t size, 
std::lock_guard<std::mutex
     return true;
 }
 
+bool BlockFileCache::try_reserve_for_ttl(size_t size, 
std::lock_guard<std::mutex>& cache_lock) {
+    if (try_reserve_for_ttl_without_lru(size, cache_lock)) {
+        return true;
+    } else if (config::enable_ttl_cache_evict_using_lru) {
+        auto& queue = get_queue(FileCacheType::TTL);
+        size_t removed_size = 0;
+        size_t cur_cache_size = _cur_cache_size;
+
+        std::vector<FileBlockCell*> to_evict;
+        for (const auto& [entry_key, entry_offset, entry_size] : queue) {
+            if (!is_overflow(removed_size, size, cur_cache_size)) {
+                break;
+            }
+            auto* cell = get_cell(entry_key, entry_offset, cache_lock);
+
+            DCHECK(cell) << "Cache became inconsistent. UInt128Wrapper: " << 
entry_key.to_string()
+                         << ", offset: " << entry_offset;
+
+            size_t cell_size = cell->size();
+            DCHECK(entry_size == cell_size);
+
+            if (cell->releasable()) {
+                auto& file_block = cell->file_block;
+
+                std::lock_guard block_lock(file_block->_mutex);
+                DCHECK(file_block->_download_state == 
FileBlock::State::DOWNLOADED);
+                to_evict.push_back(cell);
+
+                removed_size += cell_size;
+            }
+        }
+
+        auto remove_file_block_if = [&](FileBlockCell* cell) {
+            FileBlockSPtr file_block = cell->file_block;
+            if (file_block) {
+                std::lock_guard block_lock(file_block->_mutex);
+                remove(file_block, cache_lock, block_lock);   // 维护 
time_to_hash &  hash_to_map
+            }
+        };
+
+        std::for_each(to_evict.begin(), to_evict.end(), remove_file_block_if);
+
+        if (is_overflow(removed_size, size, cur_cache_size)) {

Review Comment:
   just `return is_overflow(removed_size, size, cur_cache_size)`



##########
be/src/io/cache/block_file_cache.cpp:
##########
@@ -796,6 +817,58 @@ bool BlockFileCache::try_reserve_for_ttl(size_t size, 
std::lock_guard<std::mutex
     return true;
 }
 
+bool BlockFileCache::try_reserve_for_ttl(size_t size, 
std::lock_guard<std::mutex>& cache_lock) {
+    if (try_reserve_for_ttl_without_lru(size, cache_lock)) {
+        return true;
+    } else if (config::enable_ttl_cache_evict_using_lru) {
+        auto& queue = get_queue(FileCacheType::TTL);
+        size_t removed_size = 0;
+        size_t cur_cache_size = _cur_cache_size;
+
+        std::vector<FileBlockCell*> to_evict;
+        for (const auto& [entry_key, entry_offset, entry_size] : queue) {
+            if (!is_overflow(removed_size, size, cur_cache_size)) {
+                break;
+            }
+            auto* cell = get_cell(entry_key, entry_offset, cache_lock);
+
+            DCHECK(cell) << "Cache became inconsistent. UInt128Wrapper: " << 
entry_key.to_string()
+                         << ", offset: " << entry_offset;
+
+            size_t cell_size = cell->size();
+            DCHECK(entry_size == cell_size);
+
+            if (cell->releasable()) {
+                auto& file_block = cell->file_block;
+
+                std::lock_guard block_lock(file_block->_mutex);
+                DCHECK(file_block->_download_state == 
FileBlock::State::DOWNLOADED);
+                to_evict.push_back(cell);
+
+                removed_size += cell_size;
+            }
+        }
+
+        auto remove_file_block_if = [&](FileBlockCell* cell) {
+            FileBlockSPtr file_block = cell->file_block;
+            if (file_block) {
+                std::lock_guard block_lock(file_block->_mutex);
+                remove(file_block, cache_lock, block_lock);   // 维护 
time_to_hash &  hash_to_map
+            }
+        };
+
+        std::for_each(to_evict.begin(), to_evict.end(), remove_file_block_if);
+
+        if (is_overflow(removed_size, size, cur_cache_size)) {

Review Comment:
   just `return !is_overflow(removed_size, size, cur_cache_size)`



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