Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[Optimize][Cache]Implementation of Separated Page Cache#5008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,35 +21,48 @@ namespace doris { | ||
| StoragePageCache* StoragePageCache::_s_instance = nullptr; | ||
| void StoragePageCache::create_global_cache(size_t capacity) { | ||
| void StoragePageCache::create_global_cache(size_t capacity, int32_t index_cache_percentage) { | ||
| DCHECK(_s_instance == nullptr); | ||
| static StoragePageCache instance(capacity); | ||
| static StoragePageCache instance(capacity, index_cache_percentage); | ||
| _s_instance = &instance; | ||
| } | ||
| StoragePageCache::StoragePageCache(size_t capacity) | ||
| : _cache(new_lru_cache("StoragePageCache", capacity)) {} | ||
| StoragePageCache::StoragePageCache(size_t capacity, int32_t index_cache_percentage) | ||
| : _index_cache_percentage(index_cache_percentage) { | ||
| if (index_cache_percentage == 0) { | ||
| _data_page_cache = std::unique_ptr<Cache>(new_lru_cache("DataPageCache", capacity)); | ||
| } else if (index_cache_percentage == 100) { | ||
| _index_page_cache = std::unique_ptr<Cache>(new_lru_cache("IndexPageCache", capacity)); | ||
| } else if (index_cache_percentage > 0 && index_cache_percentage < 100) { | ||
| _data_page_cache = std::unique_ptr<Cache>(new_lru_cache("DataPageCache", capacity * (100 - index_cache_percentage) / 100)); | ||
| _index_page_cache = std::unique_ptr<Cache>(new_lru_cache("IndexPageCache", capacity * index_cache_percentage / 100)); | ||
| } else { | ||
| CHECK(false) << "invalid index page cache percentage"; | ||
| } | ||
| } | ||
| bool StoragePageCache::lookup(const CacheKey& key, PageCacheHandle* handle) { | ||
| auto lru_handle = _cache->lookup(key.encode()); | ||
| bool StoragePageCache::lookup(const CacheKey& key, PageCacheHandle* handle, segment_v2::PageTypePB page_type) { | ||
| auto cache = _get_page_cache(page_type); | ||
| auto lru_handle = cache->lookup(key.encode()); | ||
| if (lru_handle == nullptr) { | ||
| return false; | ||
| } | ||
| *handle = PageCacheHandle(_cache.get(), lru_handle); | ||
| *handle = PageCacheHandle(cache, 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); | ||
| auto cache = _get_page_cache(page_type); | ||
Skysheepwang marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| auto lru_handle = cache->insert(key.encode(), data.data, data.size, deleter, priority); | ||
| *handle = PageCacheHandle(cache, lru_handle); | ||
| } | ||
| } // namespace doris | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -112,7 +112,7 @@ Status PageIO::read_and_decompress_page(const PageReadOptions& opts, PageHandle* | ||
| auto cache = StoragePageCache::instance(); | ||
| PageCacheHandle cache_handle; | ||
| StoragePageCache::CacheKey cache_key(opts.rblock->path(), opts.page_pointer.offset); | ||
| if (opts.use_page_cache && cache->lookup(cache_key, &cache_handle)) { | ||
| if (opts.use_page_cache && cache->is_cache_available(opts.type) && cache->lookup(cache_key, &cache_handle, opts.type)) { | ||
Skysheepwang marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // we find page in cache, use it | ||
| *handle = PageHandle(std::move(cache_handle)); | ||
| opts.stats->cached_pages_num++; | ||
| @@ -189,9 +189,9 @@ Status PageIO::read_and_decompress_page(const PageReadOptions& opts, PageHandle* | ||
| } | ||
| *body = Slice(page_slice.data, page_slice.size - 4 - footer_size); | ||
| if (opts.use_page_cache) { | ||
| if (opts.use_page_cache && cache->is_cache_available(opts.type)) { | ||
| // insert this page into cache and return the cache handle | ||
| cache->insert(cache_key, page_slice, &cache_handle, opts.kept_in_memory); | ||
| cache->insert(cache_key, page_slice, &cache_handle, opts.type, opts.kept_in_memory); | ||
| *handle = PageHandle(std::move(cache_handle)); | ||
| } else { | ||
| *handle = PageHandle(page_slice); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.