Skip to content

Commit

Permalink
[Exec)(cache) add element count in LRU cache (#41199)
Browse files Browse the repository at this point in the history
add element_count() in LRU cache
  • Loading branch information
HappenLee authored Sep 25, 2024
1 parent af9a2f4 commit c687481
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions be/src/olap/lru_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,14 @@ int64_t ShardedLRUCache::get_usage() {
return total_usage;
}

size_t ShardedLRUCache::get_element_count() {
size_t total_element_count = 0;
for (int i = 0; i < _num_shards; i++) {
total_element_count += _shards[i]->get_element_count();
}
return total_element_count;
}

void ShardedLRUCache::update_cache_metrics() const {
size_t capacity = 0;
size_t total_usage = 0;
Expand Down
4 changes: 4 additions & 0 deletions be/src/olap/lru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ class Cache {
virtual PrunedInfo set_capacity(size_t capacity) = 0;
virtual size_t get_capacity() = 0;

virtual size_t get_element_count() = 0;

private:
DISALLOW_COPY_AND_ASSIGN(Cache);
};
Expand Down Expand Up @@ -404,6 +406,7 @@ class ShardedLRUCache : public Cache {
PrunedInfo prune() override;
PrunedInfo prune_if(CachePrunePredicate pred, bool lazy_mode = false) override;
int64_t get_usage() override;
size_t get_element_count() override;
PrunedInfo set_capacity(size_t capacity) override;
size_t get_capacity() override;

Expand Down Expand Up @@ -467,6 +470,7 @@ class DummyLRUCache : public Cache {
int64_t get_usage() override { return 0; };
PrunedInfo set_capacity(size_t capacity) override { return {0, 0}; };
size_t get_capacity() override { return 0; };
size_t get_element_count() override { return 0; };
};

} // namespace doris
2 changes: 1 addition & 1 deletion be/src/pipeline/query_cache/query_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ bool QueryCache::lookup(const CacheKey& key, int64_t version, doris::QueryCacheH
return false;
}

} // namespace doris
} // namespace doris
2 changes: 2 additions & 0 deletions be/src/runtime/memory/lru_cache_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class LRUCachePolicy : public CachePolicy {

int64_t get_usage() { return _cache->get_usage(); }

size_t get_element_count() { return _cache->get_element_count(); }

size_t get_capacity() override { return _cache->get_capacity(); }

uint64_t new_id() { return _cache->new_id(); };
Expand Down

0 comments on commit c687481

Please sign in to comment.