Skip to content

Commit fc1b28f

Browse files
lxy-9602Copilot
andauthored
cache invaliade should call callback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4ab62d7 commit fc1b28f

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/paimon/common/io/cache/lru_cache.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,32 @@ void LruCache::Invalidate(const std::shared_ptr<CacheKey>& key) {
7070

7171
auto it = lru_map_.find(key);
7272
if (it != lru_map_.end()) {
73-
current_weight_ -= GetWeight(it->second->second);
73+
auto invalidated_key = it->second->first;
74+
auto invalidated_value = it->second->second;
75+
current_weight_ -= GetWeight(invalidated_value);
7476
lru_list_.erase(it->second);
7577
lru_map_.erase(it);
78+
79+
if (invalidated_value) {
80+
invalidated_value->OnEvict(invalidated_key);
81+
}
7682
}
7783
}
7884

7985
void LruCache::InvalidateAll() {
8086
std::lock_guard<std::mutex> lock(mutex_);
8187

82-
lru_list_.clear();
83-
lru_map_.clear();
88+
while (!lru_list_.empty()) {
89+
auto invalidated_key = lru_list_.back().first;
90+
auto invalidated_value = lru_list_.back().second;
91+
current_weight_ -= GetWeight(invalidated_value);
92+
lru_map_.erase(invalidated_key);
93+
lru_list_.pop_back();
94+
95+
if (invalidated_value) {
96+
invalidated_value->OnEvict(invalidated_key);
97+
}
98+
}
8499
current_weight_ = 0;
85100
}
86101

0 commit comments

Comments
 (0)