Skip to content

Commit

Permalink
4
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyiZzz committed Mar 12, 2024
1 parent fa94d7f commit 76725bf
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion be/src/olap/rowset/segment_v2/inverted_index_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class InvertedIndexSearcherCache {

CacheValue() : LRUCacheValueBase(CachePolicy::CacheType::INVERTEDINDEX_SEARCHER_CACHE) {}
explicit CacheValue(IndexSearcherPtr searcher, size_t mem_size, int64_t visit_time)
: index_searcher(std::move(searcher)) {
: LRUCacheValueBase(CachePolicy::CacheType::INVERTEDINDEX_SEARCHER_CACHE),
index_searcher(std::move(searcher)) {
size = mem_size;
last_visit_time = visit_time;
}
Expand Down
3 changes: 1 addition & 2 deletions be/src/olap/txn_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,7 @@ void TxnManager::update_tablet_version_txn(int64_t tablet_id, int64_t version, i
CacheKey cache_key((const char*)&key, sizeof(key));

auto* value = new CacheValue;
value->value = new int64_t;
*value->value = txn_id;
value->value = txn_id;
auto* handle = _tablet_version_cache->insert(cache_key, value, 1, sizeof(txn_id),
CachePriority::NORMAL);
_tablet_version_cache->release(handle);
Expand Down
3 changes: 1 addition & 2 deletions be/src/olap/txn_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ class TxnManager {
class CacheValue : public LRUCacheValueBase {
public:
CacheValue() : LRUCacheValueBase(CachePolicy::CacheType::TABLET_VERSION_CACHE) {}
~CacheValue() override { delete value; }

int64_t* value;
int64_t value;
};

// add a txn to manager
Expand Down
2 changes: 1 addition & 1 deletion be/src/runtime/memory/cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int64_t CacheManager::for_each_cache_prune_stale_wrap(
int64_t freed_size = 0;
std::lock_guard<std::mutex> l(_caches_lock);
for (const auto& pair : _caches) {
auto* cache_policy = pair->second;
auto* cache_policy = pair.second;
if (!cache_policy->enable_prune()) {
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions be/src/runtime/memory/cache_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ class CachePolicy {
_cost_timer = ADD_TIMER(_profile, "CostTime");
}

void init_mem_tracker(const std::string& name) {
_mem_tracker = std::make_shared<MemTrackerLimiter>(MemTrackerLimiter::Type::GLOBAL, name);
}

CacheType _type;

std::shared_ptr<MemTrackerLimiter> _mem_tracker;
Expand Down
15 changes: 5 additions & 10 deletions be/src/runtime/memory/lru_cache_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class LRUCachePolicy : public CachePolicy {
CHECK(ExecEnv::GetInstance()->get_dummy_lru_cache());
_cache = ExecEnv::GetInstance()->get_dummy_lru_cache();
}
_init_mem_tracker();
init_mem_tracker(
fmt::format("{}[{}]", type_string(_type), lru_cache_type_string(_lru_cache_type)));
}

LRUCachePolicy(CacheType type, size_t capacity, LRUCacheType lru_cache_type,
Expand All @@ -63,7 +64,8 @@ class LRUCachePolicy : public CachePolicy {
CHECK(ExecEnv::GetInstance()->get_dummy_lru_cache());
_cache = ExecEnv::GetInstance()->get_dummy_lru_cache();
}
_init_mem_tracker();
init_mem_tracker(
fmt::format("{}[{}]", type_string(_type), lru_cache_type_string(_lru_cache_type)));
}

~LRUCachePolicy() override { _cache.reset(); }
Expand Down Expand Up @@ -98,8 +100,7 @@ class LRUCachePolicy : public CachePolicy {
CachePriority priority = CachePriority::NORMAL) {
size_t bytes_with_handle = _get_bytes_with_handle(key, charge, tracking_bytes);
if (value != nullptr && tracking_bytes > 0) {
CHECK(((LRUCacheValueBase*)value)->mem_tracker()->label() == _mem_tracker->label());
_mem_tracker->cache_consume(bytes_with_handle);
((LRUCacheValueBase*)value)->mem_tracker()->cache_consume(bytes_with_handle);
((LRUCacheValueBase*)value)->set_tracking_bytes(bytes_with_handle);
}
return _cache->insert(key, value, charge, priority);
Expand Down Expand Up @@ -182,12 +183,6 @@ class LRUCachePolicy : public CachePolicy {
}

private:
void _init_mem_tracker() {
_mem_tracker = std::make_shared<MemTrackerLimiter>(
MemTrackerLimiter::Type::GLOBAL,
fmt::format("{}[{}]", type_string(_type), lru_cache_type_string(_lru_cache_type)));
}

// LRUCacheType::SIZE equal to total_size.
size_t _get_bytes_with_handle(const CacheKey& key, size_t charge, size_t bytes) {
size_t handle_size = sizeof(LRUHandle) - 1 + key.size();
Expand Down
1 change: 1 addition & 0 deletions be/src/runtime/memory/lru_cache_value_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace doris {
// Base of the lru cache value.
class LRUCacheValueBase {
public:
LRUCacheValueBase() = delete;
LRUCacheValueBase(CachePolicy::CacheType type) {
_mem_tracker = CacheManager::instance()->get_cache(type)->mem_tracker();
}
Expand Down
4 changes: 4 additions & 0 deletions be/src/service/point_query_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class RowCache : public LRUCachePolicy {
bool valid() { return _cache != nullptr && _handle != nullptr; }

LRUCachePolicy* cache() const { return _cache; }
Slice data() const {
return {(char*)((RowCacheValue*)_cache->value(_handle))->cache_value,
reinterpret_cast<LRUHandle*>(_handle)->charge};
}

private:
LRUCachePolicy* _cache = nullptr;
Expand Down

0 comments on commit 76725bf

Please sign in to comment.