hello-stephen commented on code in PR #68991:
URL: https://github.com/apache/doris/pull/68991#discussion_r4740031439
##########
be/src/io/cache/block_file_cache.cpp:
##########
@@ -2272,29 +2338,231 @@ std::string
BlockFileCache::dump_single_cache_type_unlocked(const UInt128Wrapper
return cache_type_to_string(cell->second.file_block->cache_type());
}
-void BlockFileCache::change_cache_type(const UInt128Wrapper& hash, size_t
offset,
- FileCacheType new_type,
- std::lock_guard<std::mutex>&
cache_lock) {
- if (auto iter = _files.find(hash); iter != _files.end()) {
- auto& file_blocks = iter->second;
- if (auto cell_it = file_blocks.find(offset); cell_it !=
file_blocks.end()) {
- FileBlockCell& cell = cell_it->second;
- // No iterator means remove() already took the block out of its
queue while it was
- // downloading. The block is deleting, so keep it out of every
queue.
- if (!cell.queue_iterator) {
- return;
+bool BlockFileCache::is_protected(const FileBlock& block, int64_t now) {
+ return is_protected(block.tablet_id(),
static_cast<int64_t>(block.expiration_time()), now);
+}
+
+bool BlockFileCache::is_protected(int64_t tablet_id, int64_t legacy_deadline,
int64_t now) {
+ bool legacy = false;
+ const int64_t deadline = _policy_registry->protected_until(tablet_id,
legacy_deadline, &legacy);
+ if (deadline <= now) {
+ return false;
+ }
+ if (legacy) {
+ int64_t next = _next_legacy_deadline.load(std::memory_order_relaxed);
+ while (deadline < next && !_next_legacy_deadline.compare_exchange_weak(
+ next, deadline,
std::memory_order_relaxed)) {
+ }
+ }
+ return true;
+}
+
+FileCacheType BlockFileCache::queue_type_for(int64_t tablet_id, int64_t
legacy_deadline,
+ FileCacheType cache_class,
int64_t now) {
+ DCHECK(cache_class != FileCacheType::TTL);
+ return is_protected(tablet_id, legacy_deadline, now) ? FileCacheType::TTL
: cache_class;
+}
+
+void BlockFileCache::move_cell_to_queue(FileBlockCell& cell, FileCacheType
new_type,
+ std::lock_guard<std::mutex>&
cache_lock) {
+ auto& file_block = *cell.file_block;
+ const FileCacheType old_type = file_block.cache_type();
+ DCHECK(old_type != new_type);
+ // No iterator means remove() already took the block out of its queue
while it was
+ // downloading. The block is deleting, so keep it out of every queue.
+ if (!cell.queue_iterator) {
+ file_block._key.meta.type = new_type;
+ return;
+ }
+ get_queue(old_type).remove(*cell.queue_iterator, cache_lock);
+ _lru_recorder->record_queue_event(old_type, CacheLRULogType::REMOVE,
+ file_block.get_hash_value(),
file_block.offset(),
+ cell.size());
+ cell.queue_iterator = get_queue(new_type).add_front(
Review Comment:
[P2] Keep time-based eviction valid after queue relocation
`add_front()` preserves the cell's recent `atime`. After a recently read TTL
block expires or loses protection, demotion therefore puts a hot entry ahead of
older cold NORMAL entries. `try_reserve_from_other_queue_by_time_interval()`
stops at that first hot entry, so it never examines the cold blocks behind it.
With the cache full and INDEX at its quota, the current-queue quota guard also
bypasses size-based fallback, and self-LRU evicts a hot INDEX block despite
reclaimable cold NORMAL data. The previous implementation appended demoted
blocks, allowing that cold data to be reclaimed. Keep relocation consistent
with access-time ordering, or make the time scanner tolerate reclassified hot
entries, and cover this full-cache scenario.
--
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]