Lchangliang commented on code in PR #37312: URL: https://github.com/apache/doris/pull/37312#discussion_r1669615656
########## be/src/io/cache/block_file_cache.cpp: ########## @@ -796,6 +818,70 @@ 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)) { Review Comment: ``` if (!try_reserve_for_ttl_without_lru(size, cache_lock) && config::enable_ttl_cache_evict_using_lru) { } ``` ########## be/src/io/cache/block_file_cache.cpp: ########## @@ -796,6 +818,70 @@ 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); + auto hash = cell->file_block->get_hash_value(); + remove(file_block, cache_lock, block_lock); + if (_files.find(hash) == _files.end()) { Review Comment: it dont need to do this ########## be/src/io/cache/block_file_cache.cpp: ########## @@ -1463,6 +1553,7 @@ void BlockFileCache::run_background_operation() { _index_queue.get_capacity(cache_lock) - _normal_queue.get_capacity(cache_lock) - _disposable_queue.get_capacity(cache_lock)); + _cur_ttl_cache_lru_queue_size_metrics->set_value(_ttl_queue.get_capacity(cache_lock)); Review Comment: add `_cur_ttl_queue_element_count_metrics` -- 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