acelyc111 commented on a change in pull request #5008: URL: https://github.com/apache/incubator-doris/pull/5008#discussion_r538054989
########## File path: be/src/olap/page_cache.cpp ########## @@ -21,35 +21,81 @@ namespace doris { StoragePageCache* StoragePageCache::_s_instance = nullptr; -void StoragePageCache::create_global_cache(size_t capacity) { +void StoragePageCache::create_global_cache(size_t capacity, double index_cache_ratio) { DCHECK(_s_instance == nullptr); - static StoragePageCache instance(capacity); + static StoragePageCache instance(capacity, index_cache_ratio); _s_instance = &instance; } -StoragePageCache::StoragePageCache(size_t capacity) - : _cache(new_lru_cache("StoragePageCache", capacity)) {} +StoragePageCache::StoragePageCache(size_t capacity, double index_cache_ratio) + : _index_cache_ratio(index_cache_ratio) { + if (index_cache_ratio == 0) { + _data_page_cache = std::unique_ptr<Cache>(new_lru_cache("DataPageCache", capacity)); + } + else if (index_cache_ratio == 1) { + _index_page_cache = std::unique_ptr<Cache>(new_lru_cache("IndexPageCache", capacity)); + } + else if (index_cache_ratio > 0 && index_cache_ratio < 1) { + _data_page_cache = std::unique_ptr<Cache>(new_lru_cache("DataPageCache", static_cast<size_t>(capacity * (1 - index_cache_ratio)))); + _index_page_cache = std::unique_ptr<Cache>(new_lru_cache("IndexPageCache", static_cast<size_t>(capacity * index_cache_ratio))); + } +} -bool StoragePageCache::lookup(const CacheKey& key, PageCacheHandle* handle) { - auto lru_handle = _cache->lookup(key.encode()); - if (lru_handle == nullptr) { +bool StoragePageCache::lookup(const CacheKey& key, PageCacheHandle* handle, segment_v2::PageTypePB page_type) { + Cache::Handle* lru_handle = nullptr; + switch (page_type) { + case segment_v2::DATA_PAGE: + lru_handle = _data_page_cache->lookup(key.encode()); + if (lru_handle == nullptr) { + return false; + } + *handle = PageCacheHandle(_data_page_cache.get(), lru_handle); + break; + case segment_v2::INDEX_PAGE: + lru_handle = _index_page_cache->lookup(key.encode()); + if (lru_handle == nullptr) { + return false; + } + *handle = PageCacheHandle(_index_page_cache.get(), lru_handle); + break; + default: return false; } - *handle = PageCacheHandle(_cache.get(), lru_handle); return true; } void StoragePageCache::insert(const CacheKey& key, const Slice& data, PageCacheHandle* handle, - bool in_memory) { + segment_v2::PageTypePB page_type, bool in_memory) { auto deleter = [](const doris::CacheKey& key, void* value) { delete[](uint8_t*) value; }; CachePriority priority = CachePriority::NORMAL; if (in_memory) { priority = CachePriority::DURABLE; } - auto lru_handle = _cache->insert(key.encode(), data.data, data.size, deleter, priority); - *handle = PageCacheHandle(_cache.get(), lru_handle); + Cache::Handle* lru_handle = nullptr; + switch (page_type) { + case segment_v2::DATA_PAGE: + lru_handle = _data_page_cache->insert(key.encode(), data.data, data.size, deleter, priority); + *handle = PageCacheHandle(_data_page_cache.get(), lru_handle); + break; + case segment_v2::INDEX_PAGE: + lru_handle = _index_page_cache->insert(key.encode(), data.data, data.size, deleter, priority); + *handle = PageCacheHandle(_index_page_cache.get(), lru_handle); + break; + default: + break; + } +} + +bool StoragePageCache::is_cache_available(segment_v2::PageTypePB page_type) { + if (page_type == segment_v2::DATA_PAGE && _index_cache_ratio == 1) { + return false; + } + else if (page_type == segment_v2::INDEX_PAGE && _index_cache_ratio == 0) { + return false; + } Review comment: If you do the refactor as mentioned above, you can simply judge whether the return `Cache* ` is nullptr or not ---------------------------------------------------------------- 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. 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