Merge pull request #64803 from ClickHouse/fix-memory-leak-in-slru

Fix memory leak in slru cache policy
This commit is contained in:
Kseniia Sumarokova 2024-06-05 09:58:12 +00:00 committed by GitHub
commit f50fbfa411
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -325,7 +325,7 @@ void SLRUFileCachePriority::downgrade(IteratorPtr iterator, const CachePriorityG
candidate_it->getEntry()->toString());
}
const size_t entry_size = candidate_it->entry->size;
const size_t entry_size = candidate_it->getEntry()->size;
if (!probationary_queue.canFit(entry_size, 1, lock))
{
throw Exception(ErrorCodes::LOGICAL_ERROR,
@ -483,7 +483,10 @@ SLRUFileCachePriority::SLRUIterator::SLRUIterator(
SLRUFileCachePriority::EntryPtr SLRUFileCachePriority::SLRUIterator::getEntry() const
{
return entry;
auto entry_ptr = entry.lock();
if (!entry_ptr)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Entry pointer expired");
return entry_ptr;
}
size_t SLRUFileCachePriority::SLRUIterator::increasePriority(const CachePriorityGuard::Lock & lock)

View File

@ -125,7 +125,10 @@ private:
SLRUFileCachePriority * cache_priority;
LRUFileCachePriority::LRUIterator lru_iterator;
const EntryPtr entry;
/// Entry itself is stored by lru_iterator.entry.
/// We have it as a separate field to use entry without requiring any lock
/// (which will be required if we wanted to get entry from lru_iterator.getEntry()).
const std::weak_ptr<Entry> entry;
/// Atomic,
/// but needed only in order to do FileSegment::getInfo() without any lock,
/// which is done for system tables and logging.