dataroaring commented on code in PR #37312:
URL: https://github.com/apache/doris/pull/37312#discussion_r1673277281
##########
be/src/io/cache/block_file_cache.cpp:
##########
@@ -796,6 +820,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()) {
+ if (auto iter = _key_to_time.find(hash);
+ _key_to_time.find(hash) != _key_to_time.end()) {
+ auto _time_to_key_iter =
_time_to_key.equal_range(iter->second);
+ while (_time_to_key_iter.first !=
_time_to_key_iter.second) {
+ if (_time_to_key_iter.first->second == hash) {
+ _time_to_key_iter.first =
+
_time_to_key.erase(_time_to_key_iter.first);
+ break;
Review Comment:
too many idents here, we should supress indents via function call.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]